Differential Drive Programming


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Apr 2006
    Posts
    29

    Default Differential Drive Programming

    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!
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    shaiqbashir, It may be a bit complex so here is the jistofit, I pulled every thing out but the important stuff. The variables SPD and DIR are 14 bit inputs from say a joy stick corresponding to Y and X. With two H bridge circuits you can make a tank type device and operate it with 1 joystick. Pressing it forward to move forward and pulling it in reverse to travel in reverse. Naturally moving it left or right will the device turn left or right. The null position for the variables is 511 for no output from the H bridge.
    This code was originally written for a 16F876 but updated for 18F252.
    I'm sorry I can't give you more but that's business........ HTH....

    Dave Purola,
    N8NTA
    Attached Files Attached Files

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

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

  4. #4
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thanks a lot for all ur help!

    @skimask:

    Thanks for that idea ! Well! surely i have written up my own code as well, that dint work so i have asked on this forum to provide me some help. I do admit my mistake that i dint provide my own code here: Well! This is what i have tried to do:

    I have used PIC16F84A here. I havegot two motors. So two h-bridges surely.Now in each H-bridge, there are 4 inputs to be controlled logically:

    1) Left P-channel MOS
    2) Left N-channel MOS
    3) Right P-channel MOS
    4) Right N-channel MOS

    now u see, if i take one H-bridge into my consideration. I can ON the pin containing Left P-channel MOS using HIGH command. then i can OFF the pins containing Right P-channel and Left N-CHannel MOSFETs using LOW command. When i apply PWM command on the port containg Right N-channel MOS, the H-bridge works and the motor rotates in one direction. So i say that my H-bridge is controlled by PWM command now.

    Now comes the tricky part:

    Now i have to drive the second H-bridge simultaenously as well. In PIC16F84A, there is only one PWM present. So what i decided to do is simply this that i connect run the second H-bridge totally by HIGH and LOW commands. I dint give any PWM command in the second H-bridge at all. Like I ON the Left P-channel and Right N-channel using HIGH command. I OFF the Right P-channel and LEft N-channel using LOW command. The motor runs in one direction as well.

    What i had in my mind at that time, that i would first see that which of my motor is a faster one, Then i would use PWM command with the faster motor and will control the slower motor with HIGHs and LOWs only. So that i can reduce the speed of the faster motor through PWM command in order to make the speed of both motors equal so that my robot can go straight.

    This is what my logic was, but dont know what it doesnt work. That is the reason whay i have asked u guys! Do u guys see any major flaw in this logic?

    What are ur ideas to control this sort of mechanim?

    Mr. Skimask! once again thanks for providing this code, but i do require some more explaination in order to understand this code. Like plz tell me how can i vary duty cycles in this?

    I would be thankful to you if u plz provide some detailed explaination of this beautiful code.

    Thanks in advance!
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shaiqbashir View Post
    Thanks a lot for all ur help!

    @skimask:

    Thanks for that idea ! Well! surely i have written up my own code as well, that dint work so i have asked on this forum to provide me some help. I do admit my mistake that i dint provide my own code here: Well! This is what i have tried to do:

    I have used PIC16F84A here. I havegot two motors. So two h-bridges surely.Now in each H-bridge, there are 4 inputs to be controlled logically:

    1) Left P-channel MOS
    2) Left N-channel MOS
    3) Right P-channel MOS
    4) Right N-channel MOS

    now u see, if i take one H-bridge into my consideration. I can ON the pin containing Left P-channel MOS using HIGH command. then i can OFF the pins containing Right P-channel and Left N-CHannel MOSFETs using LOW command. When i apply PWM command on the port containg Right N-channel MOS, the H-bridge works and the motor rotates in one direction. So i say that my H-bridge is controlled by PWM command now.

    Now comes the tricky part:

    Now i have to drive the second H-bridge simultaenously as well. In PIC16F84A, there is only one PWM present. So what i decided to do is simply this that i connect run the second H-bridge totally by HIGH and LOW commands. I dint give any PWM command in the second H-bridge at all. Like I ON the Left P-channel and Right N-channel using HIGH command. I OFF the Right P-channel and LEft N-channel using LOW command. The motor runs in one direction as well.

    What i had in my mind at that time, that i would first see that which of my motor is a faster one, Then i would use PWM command with the faster motor and will control the slower motor with HIGHs and LOWs only. So that i can reduce the speed of the faster motor through PWM command in order to make the speed of both motors equal so that my robot can go straight.

    This is what my logic was, but dont know what it doesnt work. That is the reason whay i have asked u guys! Do u guys see any major flaw in this logic?

    What are ur ideas to control this sort of mechanim?

    Mr. Skimask! once again thanks for providing this code, but i do require some more explaination in order to understand this code. Like plz tell me how can i vary duty cycles in this?

    I would be thankful to you if u plz provide some detailed explaination of this beautiful code.

    Thanks in advance!


    Read my post.......again.......slowly.......including the comments.......
    Almost everything you need is right there in my post; left and right drive pwm values and a loop to make the pwm, a method for channel specific complementary drive (for drive 2 sets of 2 MOSFETs connected to 2 different channels). There's nothing tricky about what you're trying to do. It's been done, a lot, a whole lot, since the beginning of time, if not before...

    And if you think you're going to find 2 perfectly matched motors that you can drive with an equal PWM signal/current, and get exactly the same RPM from both, under varying load conditions (floor surface, battery voltage, inclination, etc), well, I'm here to tell you, the world isn't that perfect.

    You'd better design some sort of optical input or something to detect wheel speed and modify your PWM to compensate, and even then, an optical input is going to be a reactive system (i.e. the wheels start turning at different speeds, you speed one or the other up to compensate, too late, the 'bot has already turned somewhat).

    What are YOUR ideas?

  6. #6
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    A bundle of thanks to u Mr. Skimask!

    Now i have understood your coding. Thank u very very much!

    As far as i have understood is this that let us suppose that the Left motor is having a speed that is double than the right motor, so we have given it more duty cycles i.e. 50 While the right one is giving a duty cycle i.e.25.

    Isnt that?

    That is really a very good idea to control the differential Mechanism.

    But one point that you made in your last post and that is that OpticaL Encoders sometimes donot prove to be enough faster in reacting than required. What if my robot speed is around 50RPM (i.e. quite slow) and i used a 10bit degree Optical Encoder, ?? I dont think it will be very slow in reacting? what do u say?
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  7. #7
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default I do not fit here

    Hi All,

    I really do not fit in this thread cause I have no experience in robotics but perhaps can share some view.

    Creating a complementary output just by inverting the PWM out pin and feeding one part.

    1. If you are driving a H-bridge then applying a 50% duty doesn't move motor.

    2. Anything less than 50% or greater than 50% would result in motion in either directions. Speed prportional to duty cycle.

    3. Shutting down both half causes braking.

    Darrel has done a Multiple Soft PWM stuff. Find it here http://www.pbpgroup.com/modules/wfse...p?articleid=12 . It can be easily adopted to get complimentary outputs. Also possible to include dead times.

    Only the PWM freq cannot be high (if you have other tasks to do in between, you run out of cycles). However for a two channel version it should work with some audible noise from the motor. Don't blame me if you burn one.
    Regards

    Sougata

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shaiqbashir View Post

    But one point that you made in your last post and that is that OpticaL Encoders sometimes donot prove to be enough faster in reacting than required. What if my robot speed is around 50RPM (i.e. quite slow) and i used a 10bit degree Optical Encoder, ?? I dont think it will be very slow in reacting? what do u say?
    Why would an optical encoder be slow? Does light travel slower through an optical encoder? Did I miss something in physics class?
    If you've got a slotted wheel, 1 inch in diamater with 10 slots in it and it rotates once per second, you'll get 10 pulses per second, or once pulse for every .31415926535897932384626433832795 inches travelled. If you get 90 pulses from the left wheel and 100 pulses from the right wheel, either you slow down the right, or speed up the left. Or you start driving both at the same time with the same pulse width, the left wheel gets 10 counts before the right wheel, so you slow down the left wheel a bit and speed up the right wheel until the counts are equal again, keep rechecking and rechecking...

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata View Post
    Hi All,

    I really do not fit in this thread cause I have no experience in robotics but perhaps can share some view.

    Creating a complementary output just by inverting the PWM out pin and feeding one part.

    1. If you are driving a H-bridge then applying a 50% duty doesn't move motor.

    2. Anything less than 50% or greater than 50% would result in motion in either directions. Speed prportional to duty cycle.

    3. Shutting down both half causes braking.

    Darrel has done a Multiple Soft PWM stuff. Find it here http://www.pbpgroup.com/modules/wfse...p?articleid=12 . It can be easily adopted to get complimentary outputs. Also possible to include dead times.

    Only the PWM freq cannot be high (if you have other tasks to do in between, you run out of cycles). However for a two channel version it should work with some audible noise from the motor. Don't blame me if you burn one.
    Exactly...software pwm, run as many channels as you have cpu time to handle, at any rate.

    Complementary PWM - exactly! Easy to do with software PWM, one bit mirrors the other...

    Very easily done. Not hard to grasp...

  10. #10
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    That was just superb!

    I got it now how to deal with Software PWMs. Thanks a lot all of u!

    Now can anybody tell me that how would i determine that what frequency do i need to supply in order to run my motor correctly. I mean what is the effect of frequency on motor?

    e.g:

    if i apply a pWM of freq 100Hz to a motor

    and then apply a PWM of freq 1000Hz to the same motor.

    What will be the difference between the two?
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shaiqbashir View Post
    That was just superb!

    I got it now how to deal with Software PWMs. Thanks a lot all of u!

    Now can anybody tell me that how would i determine that what frequency do i need to supply in order to run my motor correctly. I mean what is the effect of frequency on motor?

    e.g:

    if i apply a pWM of freq 100Hz to a motor

    and then apply a PWM of freq 1000Hz to the same motor.

    What will be the difference between the two?



    900 Hz.....

  12. #12
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    haha Skimask!

    that was superb Intelligence.

    WEll! Im asking about the effect actually.

    I want to know what is the effect of frequency over the running of a DC motor.

    Does increase/decrease in frequency affects the Running of the motor?
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I'm certainely not a motor expert, but i think some motor may work, somes not... or simply don't like it... or not.

    mmm.... any datasheet or info on your motor?

    Too low... maybe the motor could shake.. to high... maybe you will hear it.

    Who's the motor expert here?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink Hardware defining ...

    Hi, Shahiqbashir

    I realized some years ago such a thing for my large model boats ...

    But I used TWO PWM outputs to get rid of the PWM soft drive ( other more useful stuff to do during this time ) ... so, it was aboard a 16F876.
    With all the "whistles and bells" ... it took 3783 memory words.

    That's to tell you a 16F84 will be really, really small for such a purpose ( PbP programmed overall !!! )

    These days, the 18F1230/1330 offer you such features aboard a 18 pins package. ...

    Worth some reflexion ???

    Alain

    PS: other possible solution : 1 16F84 cares of the input signals ... and drives 2 16F84s which drive the motors ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink PWM Freq.

    Hi, Steve

    For such model motors it's commonly admitted ~ 3-4000 Hz for ferrite magnets ( to let them some life ...) , and what you want for rare earth magnets.

    Note at higher frequencies, it will be difficult to drive the Mosfets directly from the PIC, due to their High input capacitance ...TC 442x drivers are then to be used.

    soooo, in all cases, you'll have a sweet music for free...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Data Programming Error at 0000
    By cpatnoi in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd May 2009, 04:37
  2. Problems programming
    By Lionheart in forum General
    Replies: 4
    Last Post: - 7th December 2008, 17:51
  3. MPASM Path & File Name Length Limtation
    By Brian J Walsh in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th June 2008, 16:48
  4. Telescope drive motors that don't...
    By Dodgy Geezer in forum General
    Replies: 68
    Last Post: - 12th April 2008, 03:05
  5. Seeking Help With Programming PIC16F688
    By gzayzay in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th March 2006, 04:32

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts