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