2
\$\begingroup\$

Is there a huge difference between using a PWM and switching a port through a program (like using switch) for operating Servos? For smooth movement is PWM necessary or switching using a program will work fine? What about the durability - can switching ports break down as they are not designed for operating like that? I wanted to get a PWM but I keep reading that a Digital Output port can be treated as "PWM" by turning it on and off in certain time intervals? And now I am confused and don't know if its worth investing in a PWM Driver.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ By "switching a port" I assume you mean driving a pin high and low as a digital output? If so, you don't have to worry about the durability of the port pin. Assuming the pin isn't hooked up to a load that exceeds its specified current limit, you won't wear out the output driver. \$\endgroup\$
    – Dan Laks
    Aug 20 '14 at 17:01
  • 1
    \$\begingroup\$ You do not specify a platform or type of servos. Are they regular RC servos with PWM input? If this is an MCU, just use the internal timers in PWM mode. With a bit of DMA fiddling you can even use 8 servos per timer channel (with 50Hz refresh). \$\endgroup\$
    – venny
    Aug 20 '14 at 17:17
5
\$\begingroup\$

Using a hardware timer channel will save the processor having to constantly pay attention to the servo output port (which comes at the expense of ability to pay attention to other software tasks).

It will also likely reduce the jitter or time-to-time variation which can result if the processor takes a variable number of clock cycles to drop whatever it was doing and make a context switch to the code which changes the output. The more complex the other tasks required of the processor, the more likely jitter is to be a challenge.

That said, most servos expect a pulse only 50 times or so per second, which could be just 100 events a second to service. A compact system without other pressing responsibilities may be able to do that reasonably. In contrast, something more like a PC with a multitasking operating system may struggle to execute events with regular timing. A "real time operating system" attempts to provide the best of both worlds - rock steady low-latency events, plus the ability to schedule a variety of more abstract tasks.

I'm not ultimately sure how a servo would respond to a few percent jitter. It's unlikely that the system can mechanically move much within the 20ms period between pulses, but such variation could prevent the servo loop from ever settling, and instead keep it actuating the motor "hunting" for a position match. Yet lots of cheap servos of the sort people buy for hobby microcontroller products may end up doing that all by themselves anyway.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.