Slowest possible PWM frequency for digital pins 3, 5, 6, 11 on Arduino Uno

Hello. I'm attempting to control several servos using digital pins 3, 5, 6, & 11 on an Arduino Uno. However, the servos require a PWM frequency of 50hz, and the lowest PWM frequency I seem to be able to generate using those pins is ~60hz due to timer0 and timer2 only having 8bit registers. Is there any way to generate a 50hz PWM signal on these pins, or is ~60hz the lowest they can go?

Welcome to the forum

Why not use the Servo library ?

2 Likes

I'm doing the programming in Rust, so unfortunately can't use that library. Can the servo library achieve 50hz? If so, maybe I can do some reverse engineering there.

Are there any other important facts that you forgot to mention ?

The Servo library is used to control servos
Servos use PWM at 50Hz

Can you guess what frequency the Servo library uses ?

2 Likes

Thanks. I'll have to dig into the servo library then and see how they do it under the hood.

They use the 16 bit timer, #1 iirc.

1 Like

Can you make pins 3, 5, 6 & 11 use timer1? My understanding was that they used timer0 (pins 5 & 6) and timer2 (pins 3 & 11).

You need to look at the servo.h code. They are bitbanging any output pin you choose in the ISR; servo.h has no pin restrictions

2 Likes

Ok thanks. Yup, time to roll up my sleeves and see how the servo library does it.

1 Like

Not exactly. Servos use about a 0.5 to 2.5ms pulse within a 50ms window, so using PWM that could extend a pulse from 0 to 50ms is a poor solution; giving you too much "range" and not enough "precision."
A preferred solution is to operate your servos sequentially, setting a timer interrupt for the desired pulse width, interrupting and stepping to the next servo, and then waiting the rest of the 50ms when you've pulsed them all. (I believe that this is what the servo library does, in its current incarnation.)

1 Like


Figure-1:

Fig-1 shows which timer delivers PWM signal on which DPin during the execution of analogWrite(DPin, arg8); instruction.

Servo.h Library can deliver 50 Hz PWM signal on any valid DPin.

If registers are manipulated to generate PWM signals of varying frequencies, then the timers deliver PWM signals on the respective DPins of Fig-1.

1 Like

@westfw 20 ms, not 50. Repeated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.