Programming the for PWM for 60hz and getting a 7.5% duty cycle.

I am currently working on making my Uno control two Electronic speed controllers with two out puts. And I would like to have 60 hz 7.5% duty Cycle to put out on out put 11, 10. I would just like to make it were if a pushbotton is pushed this is what will come out. If it is not pressed then the output will be either nothing or below 6.5% on the duty cycle.

Try the servo library Rate is a little low, but you could get clues from the source on how to change that

Firstly pins 10 and 11 run from two different timers - pin 11 uses timer2 which is 8 bit and can only go down to 61.03Hz minimum at 16MHz system clock - is that satisfactory?

You might do best to use two pins on the same timer, so pins 9 and 10 (timer1), or pins 11 and 3 (timer2). You'll have to reset the timer's prescaler value to clock slower than the default, then choose an appropriate mode - for timer1 mode 8 (phase and frequency correct, period set by ICR1) would allow two PWM pins to work.

I think with timer2 there is no way to set a frequency-correct mode and have both PWM pins work, but since you are limited to 61.03Hz, frequency correct is already a lost cause. If 61.03Hz is OK, then you probably just need to change the prescaler bits and use analogWrite() on pins 11 and 3:


void setup ()
  pinMode (11, OUTPUT) ;
  pinMode (3, OUTPUT) ;
  TCCR2A = 0xA3 ;
  TCCR2B = 0x07 ;
  analogWrite (11, 19) ;
  analogWrite (3, 19) ;

and see if the right sort of signal comes out

Thank you for the input. I will get to trying some things and see what happens.

If that shouldn’t work:

pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
TCCR1A = (1<<WGM11) | (1<<COM1A1) | (1<<COM1B1);
TCCR1B = (1<<WGM12) | (1<<WGM13) | (1<<CS11);
ICR1 = 33333;      // (16MHz/8)/60Hz=33333
OCR1A = 2500;    // 33333*0,075 = 2500

This should produce 60Hz, 7,5% duty cycle at pin 9 and 10, but this code isn’t tested.
I’m using the mode 15 from the datasheet (page 136):


Hi, I have a library that will control four servos at upto 125Hz, what are you using it in and do you know what your doing ?

If so I can send you the library.

Duane B