Go Down

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

#### dtokez

##### Mar 13, 2013, 10:17 am
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?

Thanks!

#1

#### majenko

#2
##### Mar 14, 2013, 12:31 pm
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.

#### dtokez

#3
##### Mar 14, 2013, 01:36 pm
brilliant, thanks!

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

What is the formula to get 60Hz from 130?

Thanks again

#### vaj4088

#4
##### Mar 14, 2013, 08:07 pm
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.

#### dtokez

#5
##### Mar 15, 2013, 12:06 am
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