LED fading with PWM + Interrupt Timer

Status
Not open for further replies.
Hi,

If your 300ms and 800ms is "from edge to edge" then I'd do this with a single 100ms timer for multiple outputs.
100ms is the GCD of 300 and 800.
Use two counters inside the ISR which are incremented every ISR run.
If your "IF" is after the "increment" instruction:
The one counts 0, 1, 2, 3 (if = 3 then toggle the output and set counter to zero)
The other similarely counts 0..8

Klaus
 

    V

    Points: 2
    Helpful Answer Positive Rating
Basically, yes. But you can use a software prescaler to make longer delays out of short ones. For example:
1. set up timer1 to generate an interrupt every 10mS. (1/100 of a second)
2. in the ISR count down a variable from 99 to zero then reset it to 99 and toggle a bit somewhere.

That bit (or byte if you prefer) will now change from 1 to 0 or from 0 to 1 once every second. (100 x 1/100 seconds)
If you set the variable to 49 instead of 99 it would toggle every half second.

The clever bit is is you use more than one variable to count down, the 'master' timing is from the ISR being called but you can count many variables within it to create different timing periods.

Brian.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…