Pages: [1]   Go Down
Author Topic: Higher resolution PWM  (Read 1232 times)
0 Members and 1 Guest are viewing this topic.
BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, any suggestion for an higher resolution (12bit or 16 bit) PWM solution for Arduino?
I've heard of shields from Sparkfun, Adafruit etc but I don't know if they fit my needs.

I need to send PWM signals to a Meanwell LDD led driver, and using the 8 bit native Pwm of the Arduino results in horrible and visible steps instead of a smooth LED dimming.

Thanks  smiley
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 721
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Timer 1 is 16bit.  You can get better PWM out of that one. 
Logged

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I forgot to mention I have to pwm 6 LDD drivers, so pins 9 & 10 are not enough.
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 721
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Then you'll need extra hardware to get more than 8bit resolution on that many pins. 
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 44
Posts: 2459
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need more than 255 levels then you'll need to write a software PWM. The simplest way to do that would be to grab the softPWM library and change the "value" size from an 8 bit int to a 16 bit int.
Logged

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Delta_G: yes, any IC/shield you have experience of?

@Chagrin: thanks, this could be an option but as I control a temperature sensor, an LCD, read values from 6 pots I fear I would have incorrect timings
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Listen to the wind singing in the grass my love, as you lay yourself down to rest. Listen to the cry of the river in autumn cold, my dear.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may want to check out Bit Angle Modulation. It's way more gentle to the microprocessor than PWM and the values/brightness scale better.
Logged

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Vinter: thanks, very interesting! But unfortunately my power led drivers (in fact, most power led drivers) only understand PWM  smiley-confuse
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11649
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can also get more resolution with DDA techniques, averaged over many cycles.
Logged

[ I won't respond to messages, use the forum please ]

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, can you please explain me what are DDA techinques?
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 44
Posts: 2459
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try http://www.adafruit.com/products/815 for 12 bit (4096 steps) PWM resolution.

I believe MarkT is referring to "digital differential analyzer". See http://simplicate.weebly.com/1/post/2013/05/using-bresenham-line-algorithm-for-better-pwm.html for a good explanation of the concept; the general idea is that you get less flicker if you spread the on/off pulses over the entire cycle rather a single on/off pulse per cycle that PWM defines.
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're prepared to devote some CPU time to the job you can do very high resolution PWM in software (on many pins...)
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Fungus: can you show me how?
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// 16-bit PWM
unsigned int brightness = XXXX;

unsigned int counter=0;
while (true) {
  if (counter==0) {
    changeBrightness();
    if (brightness!=0) {
      turnLEDon();
    }
  }
  ++counter;
  if (counter == brightness) {
    turnLEDoff();
  }
}


Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

BLQ, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you
Logged

Pages: [1]   Go Up
Jump to: