+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 22 of 22
  1. #21
    Super Moderator
    Points: 60,546, Level: 60
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    12,360
    Helped
    2864 / 2864
    Points
    60,546
    Level
    60

    Re: LED fading with PWM + Interrupt Timer

    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
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

    •   Alt4th March 2018, 08:56

      advertising

        
       

  2. #22
    Super Moderator
    Points: 71,527, Level: 65
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,705
    Helped
    3872 / 3872
    Points
    71,527
    Level
    65

    Re: LED fading with PWM + Interrupt Timer

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

--[[ ]]--