L298 DC Motor Control: Software

Program Download:

Main C File
L298_Control.c

The Software
           The software for this project is very straight forward. A PWM (Pulse With Modulation) signal is generated at 1 KHz and input into the motor driver using the PORTB on the PIC.

The Main Algorithm

------------« Begin Code »------------

for(i=0;i<500;i++){
     Delay100TCYx(speed_pos);
     PORTBbits.RB1 = 1;
     PORTBbits.RB2 = 0;

     Delay100TCYx(speed_neg);
     PORTBbits.RB1 = 0;
     PORTBbits.RB2 = 1;
}

------------« End Code »------------


           With this simple algorithm we can generate a standard PWM signal. To keep the 1 KHz frequency it is important that speed_neg + speed_pos = 50. The variations of those two integers will determine the duty cycle of the PWM signal which inturn determines the speed & direction that the motor moves.

The Rest Of The Code
           The code following the for loop is just there to make sure the motor cycles back and forth from fast to slow, backward to forward. No real control loop exists other than telling the motor what to do.

           Download the code and look through it. The comments should clear up any other questions you might have about what is going on. It is only a 70 line program so no need to fear it. If you have more questions about what is going on, just go on over to the Forums and ask!



;