1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PWM mode vs dirty

Discussion in 'Robotics & Mechatronics' started by Makaram, Oct 14, 2012.

  1. Makaram

    Makaram Member

    Joined:
    Mar 24, 2011
    Messages:
    153
    Likes:
    0
    Location:
    Dunedin, NZ
    Hey guys,
    writing c code for pwm controlling 4 servo's and as far as I can tell, the dirty method seems infinitely easier than using the proper pwm method (which I have yet to get my head around).

    What is the point in using pwm mode rather than simply doing the work in code?

    Thanks
     
  2. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    What's "dirty mode" ?
     
  3. Makaram

    Makaram Member

    Joined:
    Mar 24, 2011
    Messages:
    153
    Likes:
    0
    Location:
    Dunedin, NZ
    Doing in code
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada

    Hardware PWM is not very practical for servo motors. Software is the traditional method.
     
  6. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    Hardware PWM lets the processor spend it's time doing other things. Software PWM eats up processor power and is more sensitive to the processor load since it is a time dependent task running alongside other tasks. If the PWM hardware module allows you to have time pulses long enough for operation with RC servos then it is best to do that.
     
    Last edited: Oct 14, 2012
  7. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    There's the rub, most microcrontrollers don't run the PWM slow enough for effective servo control. Also most have only one or two actual PWM controllers.

    It's easy enough in software, using interrupts is the way to go.
     
  8. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,897
    Likes:
    502
    Location:
    Cleveland, OH, USA
    The usual refresh rate for model servos is 50Hz. Analog servos will operate OK to about 100 to 120 Hz, which gets you to the lower limit of PIC hardware PWM, but the resolution might not be what you need. I had read somewhere that digital servos can go even higher. I can'f find that source, but if you search on "digital servo refresh rate" you will find lots of comments that they will tolerate 300Hz. Here is one thread: http://www.multiwii.com/forum/viewtopic.php?f=8&t=1644

    Of course, one can also find out how to make cars run on water on the Internet too. So, I can't vouch for the reliability of that number. It should be easy enough to test with a digital servo. They are quite cheap now, and the ones with 8 ┬ÁS deadband (standard) should be more than adequate for that purpose.

    John

    Edit: I forgot to say that I agree with Bill about using software. The above was written from the standpoint of someone who wanted to use hardware or in a situation, such as a latch, where hardware might be simpler.
     
    Last edited: Oct 15, 2012
  9. Makaram

    Makaram Member

    Joined:
    Mar 24, 2011
    Messages:
    153
    Likes:
    0
    Location:
    Dunedin, NZ
    Thanks for your reply's. My initial though was also that hardware pwm didn't seem very practical as it would require constant changing of multiple registers and calculations. I think i'll go ahead with the software approach as I've already got some experience with this anyway.

    Thanks again
     
  10. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,


    It's called "bit banging" implying that you bang the bit either 0 or 1 and that does all the work.

    But with software PWM then the software is loaded down unless of course you're not doing anything else anyway.

    One of the moon missions almost didnt make it back because of software overloading...not enough time to perform all the required tasks. If you have the time however then there's no problem. So it's really a matter of if you have the time in clock cycles or not. If you really didnt have the time you'd before forced to use the on board hardware.
     
  11. kinarfi

    kinarfi Well-Known Member

    Joined:
    Jul 7, 2009
    Messages:
    1,503
    Likes:
    30
    Location:
    P. G., Utah, United States of America
    I hope this isn't a hyjack, although it may be, does any one know of a radio control type PWM chip for decoding the 1 - 2ms pulse? other than the NJM2611 by JRC,(analog) or the Renesas M64611FP (digital) which Renesas says is not available any more. I'd like to find a source for digital decoder if possible.
    Thanks
    Kinarfi
     
  12. tomizett

    tomizett Active Member

    Joined:
    Aug 11, 2013
    Messages:
    419
    Likes:
    45
    Location:
    UK
    Also of course, a hardware circuit would probably be a better solution if you want a regulator-type system with current or voltage feedback.
     

Share This Page