Hi, my goal is to use a Mega 2560 to dim 2 group of led lights, using leading edge way.
There are different approaches to realize that, but looking around I can't find efficent examples, libraries managing timers are probably a bit slow and most of them are designed for millisecons purposes while I need microseconds to get accurate low dim outputs, driving pins with digital.write on an interrupt routine takes cycles too.. not really efficent.
I've read that timers can drive hardware particular pins, this is for PWM purposes, and I would use the same concept, but simply I don't want that the timer reloads after reaching zero, I want to start the counter next time only when the zero is crossing again.
In this case I can use only an interrupt to get the zero crossing, the timer will deactivate the hardware pin automatically, without need to use interrupt from timer.
Shortly, I think I can load a value in the timer, using it as a counter instead, and have a reflection on the corrispondent hardware output, is that possible? One timer for one dimmer.
Beeing more concrete describing the idea, theorically, thinking that the corrispondent hardware connected pin is low while the counter is 0, and high with any value <>0 is loaded on the counter, I trigger an interrupt from another pin when the zero is crossed, and in the interrupt routine I'll load the desidered dim value on the counter, reflecting an immediate HIGH on hardware pin output, quitting back to loop to do something else, then the counter beging to decrease by the clock to zero, reflecting then a LOW on hardware pin outputm the next zero will repeat the process. Exteamely clean and efficent, the CPU can do anything else without worries, no glitches.
LOW or HIGH output is not important, I can manage the hardware according to this.
To reach the result I have to set timer register values manually, as I read I have timer 3, 4 and 5 free for this purpose, can please somebody help me with thise values? Thank you a lot!