2
\$\begingroup\$

I am using a PIC 16F884 to run 2 motors and 2 servos. The motors are using the onboard PWM module, and I am bit banging PWM for the servos on Timer 2.

With only one servo being controlled, it works perfectly, but when I add a second servo control, the timing becomes off because of the number of commands that are being issued during the interrupt period (at least this is what I've seen when I've hooked it up to an oscilloscope).

My question is: Can I issue a command to a servo, wait until its reached to proper position, then turn off the pulse and expect it to maintain position? If this is the case, then I should be able to control both servos with 1 timer.

I saw a similar question here: Will a servo hold its position without a signal? with no definitive answer.

\$\endgroup\$
  • 2
    \$\begingroup\$ I control several servos with one timer -- turn on all your servo pins, then set the timer to the off time for the 'lowest' servo position, in the interrupt routine, turn off that servo and set the timer for the difference between that and the next 'lowest' servo. \$\endgroup\$ – Tom Davies May 8 '13 at 6:12
2
\$\begingroup\$

A specific type of servo motor, a latching servo, is required for holding position after the control signal is removed.


Depending on the specific servo in use (see caveats below), an alternative "poor man's latching servo" can be implemented thus:

  • Control the power supply line for the servo with a high side switch, either a P-MOSFET or for high power servos, an SSR.
    • Low side switching is not suggested, as disconnecting the ground path may cause unpredictable behavior due to the control signal losing ground reference.
  • After allowing the servo time to achieve desired position, disable the servo power before removing the control signal.
  • For changing position, start the control signal, then enable power to the servo.

Caveats:

  • The servo needs to be of a high reduction ratio / high torque type, so that small forces applied to the arm while it is unpowered, do not cause the arm to rotate.
  • Not all servos can tolerate a control signal arriving while supply power is absent. While some will suffer damage to the internal electronics (not too likely), I have at least one servo that tries powering its motor from the control signal, ergo microcontroller pin damage.

Side Note:

Servo control signals are not actually PWM but a variant, pulse duration modulation: Servo position is not defined by the PWM duty cycle (i.e., ON vs OFF time) but only by the duration of the pulse. As long as it is anywhere in a range of (typically) 40 Hz to 200 Hz, the exact value of the frame rate is irrelevant. The servo expects to see a pulse every so many ms, this can vary within a wide range that differs from servo to servo.

This is relevant because the OP's requirement can be meet by generating consecutive pulses of desired durations for each driven servo, with a lot of flexibility in the time taken between a pulse for Servo A, and a pulse for Servo B, for example. The servos would thus be fed their control pulses in round Robin fashion.

As pointed out by Dave Tweed in comments, using the acronym PDM can be confusing, as that is also applied to Pulse Density Modulation, yet another special case variant of PWM.

\$\endgroup\$
  • \$\begingroup\$ What's the difference between PWM and PDM? \$\endgroup\$ – Dave Tweed May 8 '13 at 11:10
  • 1
    \$\begingroup\$ @DaveTweed In PWM, the duty cycle is varied for a specified frequency. For servos, the pulse duration alone is relevant (typically 1 to 2 mSec min to max), cycle time could be any value within supported range for a particular servo, and can even be varied between consecutive pulses. Thus frequency is not a characteristic parameter (within operating range). \$\endgroup\$ – Anindo Ghosh May 8 '13 at 12:25
  • 2
    \$\begingroup\$ Since when does PWM have a "specified frequency"? While creating a varying duty cycle might be a common application of PWM, that is not its defining characteristic. I think you're splitting a hair that doesn't exist. In any case, you might want to pick a different acronym. Most online souces define PDM as "pulse density modulation" in which the spacing of fixed-width pulses is what varies. \$\endgroup\$ – Dave Tweed May 8 '13 at 12:38
  • \$\begingroup\$ Not splitting hairs, actually solving problems. :-) \$\endgroup\$ – Anindo Ghosh May 8 '13 at 13:20
  • 1
    \$\begingroup\$ @ScottLance At the simplest: If you want full left, send that 1ms pulse. Next, send pulses or do whatever else you must in your code, and then come back and send another 1ms pulse... And so on. That 20 ms gap between pulses is not a hard requirement, any gap between 5 and 25ms will do fine, so don't bother with timing that 20ms at all. \$\endgroup\$ – Anindo Ghosh May 8 '13 at 14:54

protected by W5VO May 8 '13 at 14:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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