]> git.donarmstrong.com Git - qmk_firmware.git/commit
Fix #3566 use an hardware timer for software PWM stability (#3615)
authorBrice Figureau <brice@daysofwonder.com>
Mon, 22 Apr 2019 15:34:13 +0000 (11:34 -0400)
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>
Mon, 22 Apr 2019 15:34:13 +0000 (08:34 -0700)
commitb61baf4281bde34bfe28aaa1109bd5d5c6471116
treefa60f457b48bbb4d635b32f5b48b03a7dd0dccf7
parentc28a4321123131b6ff1e6c6b302fba764255623b
Fix #3566 use an hardware timer for software PWM stability (#3615)

With my XD60, I noticed that when typing the backlight was flickering.

The XD60 doesn't have the backlight wired to a hardware PWM pin.
I assumed it was a timing issue in the matrix scan that made the PWM
lit the LED a bit too longer. I verified it because the more keys that
were pressed, the more lighting I observed.

This patch makes the software PWM be called during CPU interruptions.
It works almost like the hardware PWM, except instead of using
the CPU waveform generation, the CPU will fire interruption
when the LEDs need be turned on or off.

Using the same timer system as for hardware PWM, when the counter
will reach OCRxx (the current backlight level), an Output Compare
match interrupt will be fired and we'll turn the LEDs off.
When the counter reaches its maximum value, an overflow interrupt
will be triggered in which we turn the LEDs on.
This way we replicate the hardware backlight PWM duty cycle.

This gives a better time stability of the PWM computation than pure
software PWM, leading to a flicker free backlight.

Since this is reusing the hardware PWM code, software PWM also supports
backlight breathing.

Note that if timer1 is used for audio, backlight will use timer3, and if
timer3 is used for audio backlight will use timer1.
If both timers are used for audio, then this feature is disabled and we
revert to the matrix scan based PWM computation.

Signed-off-by: Brice Figureau <brice@daysofwonder.com>
docs/feature_backlight.md
quantum/quantum.c
quantum/quantum.h