cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the timer to keep our LED on 80% to 10% (linear down) of the time

TBen.1
Associate

How to use the timer to keep our LED on 80% to 10% (linear down) of the time by setting a period of 500X, turning it on when the counter is 0 to 400X (0-15 minutes) and turning it off when it is 400X to 500X(5 minutes)?

The time and period is a draft idea.

4 REPLIES 4
Piranha
Chief II

By reading the reference manual on timer output PWM mode.

berendi
Principal

I have some difficulty interpreting your question, so please tell me first if my understanging is correct.

  1. There should be a PWM signal with at least 60 Hz frequency to prevent visible flicker.
  2. The signal should start with 80% duty cycle, and gradually reach 10% duty cycle in 15 minutes. In how many steps?
  3. The perceived intensity of the light should change linearly (not the duty cycle, which is a big difference).
  4. After 15 minutes the light should be off for 5 minutes, then repeat from the beginning.
RMcCa
Senior II

Your eyes have a logarithmic response, so you'll need to use an exponential to make the change look linear. Could be a simple lookup table or maybe use the arm math linear interpolation function.​

Using a 2 kB table (1024 short values) is good for 16384 steps with some bit shifting. Works well even on the STM32F0.