Pages: [1]   Go Down
Author Topic: SoftPWM question  (Read 440 times)
0 Members and 1 Guest are viewing this topic.
South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 585
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 585
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

anyone know much about this library?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
// 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.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 585
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

brilliant, thanks!

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

What is the formula to get 60Hz from 130?

Thanks again
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 585
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: