The standard Arduino "analogWrite()" function outputs a 1kHz PWM signal so you're not going to see any flicker.
I said it's incorrect because that WILL cause me to see flicker. I know this cuz I've tested it
Then:
a) You tested it wrong, or
b) You have superhuman eyes and should go and see a specialist to be studied for posterity.
, and the fact that LED PWM is often done at massively higher PWM frequencies
No it isn't: https://encrypted.google.com/search?q=led+pwm+frequency
The frequency response of human eyes is well studied: https://en.wikipedia.org/wiki/Flicker_fusion_threshold
Sorry, you're wrong. I did not "test it wrong". I had the LED hooked up, and a scope as well, measuring the frequency and duty cycle. The fact is, at 490Hz I can readily detect flicker at low duty cycles, as many people can. (Just Google "led pwm flicker" - you'll find plenty of people who agree.)
The flicker fusion threshold applies to an unmoving light source. The problem is, we don't stare at light bulbs in normal use. They're around us, and we look at things, which we do by moving our heads, and our eyes within them (saccades). The second you move your eyes quickly, a frequency that was fine without motion suddenly breaks into a series of flashes precisely because we have a certain amount of persistence of vision. You know those displays that go on car tires and display messages and stuff? That's precisely the effect in action. If you took one of those wheel displays and looked at it when not moving, you'd see a bunch of unblinking, unflickering LEDs. But move them quickly and it breaks into discrete dots of light. THAT is the flicker people like me perceive in slow PWM lighting. It's annoying as fuck, it's not imaginary, and it's entirely reproducible.
http://www.tftcentral.co.uk/articles/pulse_width_modulation.htm has an image that illustrates the problem, precisely as I experience it.
And this discussion on stackexchange goes into it more, and suggests that to successfully eliminate it, PWM frequencies of as high as 15KHz are necessary:
http://physics.stackexchange.com/a/19056I looked at the LED driver chips again, and must confess that I misread one datasheet and confused its buck converter switching frequency with its PWM frequency. The PWM frequency is "only" 20KHz.
The Arduino platform is the combination of the AtMega chips and the libraries and IDE. You are correct that the Mega328 can be manually driven to bit-bang much higher PWM speeds (I knew that before starting this thread), but I am not a programmer and going deeper than the Arduino libraries probably goes beyond what I can code and debug.
As I said before, it's one line of code (and I'll be happy to tell you what that line is, all I need to know is what pin you're using for PWM).
I'd still love to find out what it would take to Arduino-control a true analog output that could in turn do true analog control of the LEDs, if somebody is willing to indulge me.
All you need is a big inductor and a current sensor connected to your Arduino.
Make a feedback loop, ie. turn MOSFET on if there's too little current, turn if off if there's too much.
if ( analogRead(CURRENT_SENSOR) < preset_value ) {
digitalWrite(MOSFET,1);
}
else {
digitalWrite(MOSFET,0);
}
That's it.
If that loop is running very fast then the effect is constant-current at the defined value.
I am not a programmer and going deeper than the Arduino libraries probably goes beyond what I can code and debug.
I thought you said you were an engineer who wanted a challenge...
I want to learn electronics engineering, not software engineering. (Indeed, one of the reasons for me getting back into electronics is to be doing something more physical, because I have RSI problems that require me to limit computer use.) I'm willing to do the minimum in software that is necessary to complete a project, but it's expressly what I don't want to be doing! :p
I've said twice already that I know how to tweak Arduino's PWM, and that I know what other consequences that has. What I definitely don't want to do is the other approach, which is to circumvent the Arduino PWM (analogWrite) altogether and bit bang it by writing directly to registers or something, for the aforementioned reason that I lack the skills to debug that. (And I don't want to acquire that skill either, lest I spend even more time at the computer and ruin my hand even more...)
I think I understand what you're saying with the feedback loop. Let me refresh my knowledge on inductors (something I've never used in any project so far, so something I'm very green on) and get back to you.