Go Down

Topic: SoftPWM question (Read 681 times) previous topic - next topic


HI all, I'm planning to use the SoftPWM lib on a 328p (12 channels) I have 3 channels set up and working at the moment and I do notice some flickering at low intensity levels

I have a couple of questions

  • WIll the flickering get worse when I use more channels

  • Is there a simple way to increase the frequency or is it running as fast as it can already?



anyone know much about this library?


Yes, you can increase the frequency.  Check the top of SoftPWM.cpp

Code: [Select]

// 130 == 60 Hz (on 16 MHz part)
#define SOFTPWM_OCR 130

But be warned, it will eat into your available CPU time.

Theoretically, it can cope with many channels (up to something like 16 according to the site) without problems, but the more channels you have the less CPU time you have for other things.  SoftPWM is hardware timer driven, so the flickering you are seeing may be caused by other interrupts taking priority, or interrupts being disabled at times, causing the SoftPWM to stall briefly.


brilliant, thanks!

So I guess the higher the number the faster the frequency?

What is the formula to get 60Hz from 130?

Thanks again


A couple of minutes playing with Excel suggests that the formula is

(Output Frequency) = (Clock Frequency)/(2048 * SOFTPWM_OCR)

where (Clock Frequency) = 16 MHz

and SOFTPWM_OCR = 130

You won't get exactly 60 Hz, but 130 is closer than 129 or 131.


Thanks very much, so working through the formula it appears the smaller the ocr the higher the freq. I will have a play around

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131