0

I wanted to understand how people are connecting a servo motor to pins without PWM, so I went searching and I read that the Servo library uses the timer1 of pin 9 and pin 10 to be able to use other pins.

I would like to ask some questions about this.

  1. Could I connect a servo motor on pin 12 by emulation of the library, and another servo on pin 9, another on pin 10 and another on pin 11 at the same time?

  2. Or using the Servo library the PWM in pin 9 and 10 stops working?

  3. I could then through library emulation connect one servo on pin 7, another on 8, another on 12 and another on 13 ?
  4. 4 emulations at the same time?
  • How are you planning to emulate this? Afaik the servo lib uses hardware pwm but one can still use the timer interrupts to toggle any pin. This way, the resulting pwm is still triggered by hardware and therefore is still much more accurate than a pure soft pwm. The pwm on the oc pins can still be used then... – Sim Son Feb 18 at 13:22
  • The library only uses the timer1 interrupt part, not the timer1-pwm part. – Gerben Feb 18 at 16:42
1

Have you read the Servo library page?

The library support upto 12 servos outputs. You can use any pin you want.

The library disables analogWrite() (PWM) functionality on pins 9 and 10.

1

For those looking for more information on PWM in arduino, a must see page is this one: http://www.righto.com/2009/07/secrets-of-arduino-pwm.html. Once you read it you may undestand, what is software and hardware PWM and which are the limitations.

To do the software PWM the servo library takes over one of the three arduino's timers. So pin 9,10 are not available to analoWrite() anymore, resting Timer0 (pins 5,6) and Timer2 (pins 11,3).

Note that internally arduino must use Timer0 to its timing functions (such as delay(), milis(), etc).

So to answer your question:

1) Yes, you can since the library is managing your timers it may allocate fine (as software emulation though).

2) Yes and No. It works for the library itself but may be not at disposal for other libraries or for your code. Example: if you want use it along with RH_ASK (radio frequency library) you have an conflict of timer usage and may be needed to change the config of one of them to move to another Timer.

3) Yes.

4) Yes (you can get all 20 pins working as PWM if you want. SoftPWM library does that).

Best regards,

gl

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.