0

Is it possible to set all 6 PWM frequencies to a value between 2 and 5 kHz?

I've read that the base frequency for pins pins 5 and 6 is 62500 Hz. And the divisors for the pins 5 and 6 are only this ones: 1, 8, 64, 256, and 1024.

The closest I can get is 7.812,5 Hz with the 8 divisor. Are there any other possibilities to achieve this?

3
  • To be honest, I don't know. I haven't choosed yet. My first attempt was to do it with the Raspberry, but the suggestion was to use Arduino. So I found this example: playground.arduino.cc/Code/PwmFrequency
    – Wa Kai
    Commented May 26, 2019 at 21:08
  • So I know it's goin to be an Arduino, but not exactly which model, because I didn't knew which are capable of my requirements in my question. If this sooo unclear to you, then go on and vote.
    – Wa Kai
    Commented May 26, 2019 at 21:39
  • ok, since you are talking about arduino for sure, I am removing the vote to close
    – jsotola
    Commented May 27, 2019 at 1:42

1 Answer 1

2

Judging from your mentioning 62.5 kHz as the base frequency for pins 5 and 6, I assume you are talking about an Arduino Uno or something similar.

If you set the timer 0 to phase correct PWM mode (which is how the Arduino core configures the other timers), then its base frequency is about 31.373 kHz (F_CPU/510). With the prescaler set to 8, you get a PWM frequency of about 3.922 kHz on pins 5 and 6.

Note that you can set all three timers in this mode and have 6 PWM channels at this frequency. But note also that by reconfiguring Timer 0 you loose all the standard Arduino timing functions.

3
  • Thank you for your answer. Are there any other models which are better suited for this? But nevertheless, this is quite helpfull. Thank You!
    – Wa Kai
    Commented May 26, 2019 at 21:09
  • @WaKai: A Mega has way more timers. On the other hand, if you don't need the Arduino timing functions, the Uno could do the job fine, and the Mega would be overkill. Commented May 26, 2019 at 21:14
  • Ah, I see. Clock speed: 16 MHz divided by 510 in phase correct mode for the ~32 kHz base frequency. Neat :-) As far I can think ahead, I won't need any more timers. So the UNO should be perfect.
    – Wa Kai
    Commented May 26, 2019 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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