In the previous section, we show how we can drive the bipolar stepper motor and the unipolar stepper motor with the L293D chip. The Handy Board also has two on-board L293D chips which can drive up to 4 DC motors. As mentioned before, stepper motors are simply two(or more) coils that are driven in sequences. So, in theory, we can drive stepper motors using the motor drivers on the Handy Board directly.
Bipolar stepper motor

The pulse sequence of driving the bipolar stepper motor shown in the previous section can be interpreted as driving two different motors forwards and backwards. So, we can use the IC library functions for controlling the DC motors to drive the stepper motors, if we generate the correct pulse sequence. In the IC library, the function fd( ) is used to drive the DC motor in the forward direction and the function bk( ) is used to drive the DC motor in the backward direction. So, the fd ( ) fucntion will set one end of the corresponding motor high and the other end low. The bk ( ) function will just set the polarity of the motor in an opposite way. For example, the code fd(0) will set the the positive end of motor 0 to high (+5V) and the negative end of motor 0 to low (0V). So, we can generate the same pulse sequence as the one shown in the previous section, using a sequence of fd( ) and bk( ) functions. Suppose we plug coil 1 of the stepper motor into the motor 0 input of the Handy Board and coil 2 of the stepper motor into the motor 1 input of the Handy Board. The following C code fragment will generate the correct sequence of driving the stepper motor:

void main()
{ float x=0.001;
while(1){
fd(0);
fd(1);
sleep(x);
bk(0);
fd(1);
sleep(x);
bk(0);
bk(1);
sleep(x);
fd(0);
bk(1);
sleep(x);
}
}



Again, the variable x controls how long the processor should wait between each step and it determines the speed of the stepper motor. In the above example, the motor is set to rotate forever but you can use a for loop instead to set how much the motor should turn.
Unipolar Stepper Motor

Driving a unipolar stepper motor using the Handy Board directly is the same as driving the bipolar stepper motor with the Handy Board. You can use the same code fragment to drive the unipolar stepper motor. The only difference is you have to connect the extra common wire to the +5V supply.

0 comments:

Post a Comment