Quote Originally Posted by shaiqbashir View Post
Hi guys!

Well! im a novice in robotics. IM making a robot which will be having two wheels in the differential drive formation. That is each wheel will be connected with one motor. So there will be two motors in total.

Now Im using PIC16F84A. I want to use the PWM command in order to control both the motors. Now the thing is that what is the way to programe this sort of scenario. I mean, just see, we have got two DC motors, each should be controlled independently. SO we will be needing two PWM commands to be operated simultaneously. Since both motors are somewhat different in practical, so different duty cycles would be required. So how would i program that???

I have seen that when i write PWM command, it first executes it completely and then comes to next command. SO how can i control the other motor with PWM simultaneously??

PLease provide some example code to control two motors simultaenously using PWM commands. Or if it is not possible then how can we control two wheel differential drive?

Thanks in advance!

Take carez!

Good Bye!


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'....