PWM in smaller increments to dimm ledstrip

Hi,

Is it possible to drive a ledstrip in smaller increments?

Instead of analogwrite 1 I would like to analogwrite a 0.1 value (as example here) cause the analogwrite 1 is already to much for my purpose.

Any suggestion where to look for, considering any software solutions or hardware methods ....?

The resolution of PWM is governed by the number of bits in the timer. For example in a Due there is higher resolution available. http://arduino.cc/en/Reference/AnalogWriteResolution

There is also Timer 1 that can be put into a 16 bit mode, see:- http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Can always use Blink Without Delay too.

thank you. Search more for a 16bit resolution and found things to begin with:

https://code.google.com/p/multiwii/wiki/PWM_Generation

https://puzzlebox.io/orbit/development/browser/orbit/arduino/libraries/PWM?rev=1f70352e97d5605c67134360b49e7dc8b94bcf5a&order=name

http://www.ofrecordings.com/2014/03/16/how-to-set-up-16-bit-pwm-with-an-arduino-uno-atmega328/

I probably need to set timer1 to the apropriat pins and test out if setting it to 1 fills my needs :wink:

Think the last is the easiest to begin with.

I probably need to set timer1 to the apropriat pins

No the pins it toggles are fixed you can’t change them.

Hi, why do you need more than 256 levels of PWM?
What is your purpose?

Tom… :slight_smile:

TomGeorge: Hi, why do you need more than 256 levels of PWM?

I absolutely get it. At the low end of the range, the eye can easilly distinguish between 0, 1, 2... At the mid and high end, the steps are too small for the eye distinguish. Its because the eye is logarithmic but analogWrite is linear. The difference between 0/off and 1 is most noticeable. Any application where you want a soft/subtle start, its crude.

Paul

Right Paul !! That my question.

I want the light intensity from 0 to 1 to be smaller .....

Found this: LINK

I probably don't understand pwm correctly ...yet...so here is another (n00b?) question:

I can change the pwm frequency meaning the 8-bit counter will count faster and thus the light intensity at 50% will be smaller than with a lower frequency ? Or how does the frequency in combination with a 8 or 16bit counter affect the light intensity ?

My main goal is to get a smaller light intensity from 0 to 1 so the begin steps with brightening are smaller than I have now with default settings. (Like Paul explained above)

@Grumpy_Mike: I understand (now) that specific pins are dedicated to specific Timer/Counter registers

*EDIT: found this LINK I probably cannot change alot with frequency because of the flickering ): Setting it as high as possible gives me nice light without flickering.

I can change the pwm frequency

Yes.

meaning the 8-bit counter will count faster and thus the light intensity at 50% will be smaller than with a lower frequency

No that is not what happens when you change the frequency. See this for an explanation of how PWM works:- http://www.thebox.myzen.co.uk/Tutorial/PWM.html

Or how does the frequency in combination with a 8 or 16bit counter affect the light intensity

The frequency is unimportant what is important is the duty cycle from full on to full off. With 8 bits there are only 256 increments between these two states. With 16 bits there is just over 65,000 increments between the two states, so each increment is 256 times smaller than an 8 bit counter.

Than the 16-bit counter is the way to go. (Unfortunately only for 2 pins but I read already that it's possible to use a bitshiftregister to get some more going ;)

Thanks for the help guys! If there are more tips please leave them here ;)

but I read already that it's possible to use a bitshiftregister to get some more going

If that is what it said then it is wrong or you have got hold of the wrong end of the stick. While you can get PWM from a shift register it is only 8 bit PWM and having two pins going at 16 bit PWM is not going to be possible to extend.

Doing software 16 bit PWM is going to be messy to say the least, and I doubt if you can get it going fast enough to prevent flicker. Because 16 bits refreshed over 32 times a second is a multiplex rate of just over 2MHz and you are not going to be able to do that with a 16 MHz processor.

If you want more PWM outputs then you will have to use an external chip.

Oke! Thanks for waking me up again…

In other words, if I want to use more than 2 pins (with pwm 16bits counter), I need an external chip.
Don’t want to do it software for the reason you write above.

Any suggestions which external chip is easy to be controlled by arduino (pro mini) and gives the performance as talked about? (16bit counter, >2 pins, )

btw, If I set the 16bit counter to a TOP that equals to a 10bit, does it give the same result as using the TLC5940 chip at 10bits? (LINK)
I expect that using a 10bit counter will meet my demands, but need to test it out…if possible with the arduino 16bit pwm pin to simulate a 10bit counter…

This is just a thought.

You could probably enhance the PWM resolution in code by playing with the duty cycle. It would create some jitter, but with loop speeds above 100Hz and the PWM frequency being 490+ Hz, there would be no perceived flicker.

For example - getting 11-bit PWM on any PWM capable pin:

Define 8 different bytes with bit patterns that represent 1/8 steps fine control of intensity. In your main loop, use a variable (counter) that updates with millis() % 8; Then update the PWM including the "fine control" setting.

The fine control would need to work in such a way that as the pattern shifts, it toggles the duty from "value" to "value - 1".

you think it runs oke having more then 2 soft pwm pins running independently (dimming/brightening)?

For example : http://electronicsfordogs.com/articles/software-pulse-width-modulation-pwm-arduino

That last suggestion by dlloyd is a puzzle for me, but could wel be a simple sollution but smoother/better than above link?

If there is a (cheap) external chip with >2 pwm pins >8bit counter , that would solve it the other way around ;)

Thanks for helping out here...

You can simulate a 10 bit PWM with a 16 bit system by only using increments of 64.

Hi,

http://www.adafruit.com/product/1455

Might help, 16bit PWM 12CHANNELS

Tom....... :)

That last suggestion by dlloyd is a puzzle for me, but could wel be a simple sollution but smoother/better than above link?

This should work on any PWM pin, could easily be modified so multiple pins can use different brightness settings.

Simulate 11-bit PWM on any Arduino 8-bit PWM pin (proof of concept - untested):

unsigned short val = 0; // 0-2047 (brighness range)

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  analogWrite(13, duty());
}

unsigned short duty () {
  byte fine[] = {B0, B1, B00010001, B01001010, B01010110, B01101011, B01110111, B11111111};
  unsigned short dty;
  byte mx = millis() % 8;
  (val > 2047) ? val = 2047 : val;
  dty = val >> 3;
  dty += (fine[val & 7] >> mx) & 1;
  (dty > 255) ? dty = 255 : dty;
  return dty;
}

Thnks for helping out here! Found also this as external chip: TLC5940

Conclusion (for me):

Software pwm to have your own resolutions (post #12 this thread or link )

try external chip like TLC5940 (link )

Or just be happy to have 2 pwm that can be set to a 16bit resolution ( link ).

Instead of mucking around with a regular Arduino I'd get a Teensy3 or Teensy3.1. Fully Arduino compatible. Much smaller. Much cheaper. Running on an Arm Cortex M4 it's much more powerful.

It's got plenty of PWM pins with configurable PWM resolution from 8-16 bits and configurable PWM frequency. Teensy PWM

Teensy home page

Headroom, 20$ for a teensy 3.1 is cheap? (vs attmega328 1$ and a challenge ;)

@Dlloyd, Thx, missed your post. Will try it out but don't understand how using analogwrite can accept a smaller value than 1 and thus dimming less than 1 by playing with the dutycycle. (Probably out of my league :)