-
Notifications
You must be signed in to change notification settings - Fork 0
CPU Consumption
The ATMega microprocessors are 8-bit systems usually clocked at 16MHz so there aren't all that many free CPU cycles to begin with. Since this library uses TIMER1 and software interrupts to perform software PWM as well as using an interrupt on TIMER0 for active fading & brightening of the LED it will have an adverse impact on the main sketch.
Most of the time this is not an issue, since frequently programs are waiting using calls to "delay()" or are cycling in loops and polling. In those cases the overhead for this library will not be noticed. But time-critical sketches are at risk of not working correctly while there are one or more LEDs that are actively doing PWM. The library attempts to minimize impact by switching off the interrupt handler for TIMER0 (used in fading) and TIMER1 (used for software PWM) when they are not required. Pins a "0" or "255" ("OFF" and "ON") do not require PWM and pins that are hardware-PWM capable will use hardware PWM unless turned off explicitly.
The software PWM is done at 60Hz, sufficiently fast to avoid visible flickering at low power settings. Hardware PWM is done by the ATMega processor at the rates specified in the data sheet for the corresponding timer that the pin is attached to.
The chart below shows how an active program would be slowed down with active PWM on LEDs. The slowdown chart percentages are in percent slowdown, so a 100% slowdown means that the program runs double as long.
1 LED% | 2 LEDs% | 3 LEDs% | 4 LEDs% | 5 LEDs% | 6 LEDs% | 7 LEDs% | 8 LEDs% | 9 LEDs% | 10 LEDs% |
---|---|---|---|---|---|---|---|---|---|
0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |