L298 Stepper Motor Control: Software

Program Download:

Main C File
L298_Stepper.c

The Software
           The software for stepper motor control is not the best in the world but instead a working demonstration. All this software does is drive the motor forward by continuously stepping.

------------« Begin Code »------------
while(1) //Step Forever
{
        //Step 1 AB
Delay100TCYx(45);
//Set A Inputs Positive
//Set B Inputs Positive
Delay100TCYx(5);
//Set A Inputs Negative
//Set B Inputs Negative
        //Step 2 A*B
Delay100TCYx(45);
//Set A Inputs Positive
//Set B Inputs Negative
Delay100TCYx(5);
//Set A Inputs Positive
//Set B Inputs Negative
        //Step 3 A*B*
Delay100TCYx(45);
//Set A Inputs Negative
//Set B Inputs Negative
Delay100TCYx(5);
//Set A Inputs Positive
//Set B Inputs Positive
        //Step 4 AB*
Delay100TCYx(45);
//Set A Inputs Positive
//Set B Inputs Negative
Delay100TCYx(5);
//Set A Inputs Negative
//Set B Inputs Positive
        //Step 5 AB
Delay100TCYx(45);
//Set A Inputs Positive
//Set B Inputs Positive
Delay100TCYx(5);
//Set A Inputs Negative
//Set B Inputs Negative
}
------------« End Code »------------

The Main Algorithm
           The above code shows you the main algorithm used for completing one step. Since it is in a while(1) loop it will step forever which is why the motor only moves forward. The complete stepping cycle for a 2-coil stepper motor goes like this:
AB -> AB* -> A*B* -> A*B -> AB

           A and B stand for the two coils in the stepper motor and the * or no star represents the direction of current flow. The code above doesn't actually show the ports being set. This is because the code gets pretty long. Download the actual C file to see how it works and what is really going on.



;