leftpwm var byte
left var portb.0
rightpwm var byte
right var portb.1
counter var byte
main:
leftpwm = 50 'set the left drive pulse width with whatever
rightpwm = 25 'set the right drive pulse width with whatever
counter = 0 'reset the counter
left = 0 : right = 0 'turn off the motors to start with
if leftpwm > 0 then left = 1 'if left drive needs to be driven, start it
if rightpwm > 0 then right = 1 'if right drive needs to be driven, start it
loop:
counter = counter + 1 'increase the counter
if counter > leftpwm then left = 0 'in this case, the left drive will get 50 counts of on time, then be turned off
if counter > rightpwm then right = 0 'in this case, the right drive will get 25 counts of on time, then be turned off
if counter = 255 then goto main 'if the counter is about to roll over, reset everything and start over
goto loop 'otherwise...
Simple and effective...set up your pwm values right under main:
I've looked at all of your other posts. You have always asked for this, asked for that, please provide this, give me this, give me that.
If you don't understand how this simple code works, you need to start with the basics (i.e. blinking LEDs).
If you do understand it, then go with it. The PIC16F84A doesn't have 2 PWM's inside, so you'll have to do it thru software. I've got really good code that I use to drive RGB LEDs, timer based interrupt, 19.5khz, 66 PWM channels on a PIC18F8722...and it works great.
You'd get a lot better responses from people in general if you provided some sample code of your own that didn't work, and made it look like you tried, than just to say 'Gimme gimme gimme'....





Bookmarks