This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reuse timers

I have to measure some many time periods so I need to reuse timers.

Can someone help me?

Thanks.

Parents
  • since you do not specify precision/resolution here is one way.

    Run T2 as a free running timer and in the interrupt increment the variable Ralph. Depending on how long your program must run between resets Ralph can be char, short or long. When the state of an even input changes to on use RCAP2 to read the timer, briefly disable T2 interrupt and read Ralph. When the event end, do the same.
    The difference between the two will be the time.

    no guarantee, this is an unqualified estimate: this would give you a max error of about 200 clocks.
    I can see no better precison using one timer with that many inputs. If you need better precision you will need to gang timers/5 uCs with PCA.

    Erik

Reply
  • since you do not specify precision/resolution here is one way.

    Run T2 as a free running timer and in the interrupt increment the variable Ralph. Depending on how long your program must run between resets Ralph can be char, short or long. When the state of an even input changes to on use RCAP2 to read the timer, briefly disable T2 interrupt and read Ralph. When the event end, do the same.
    The difference between the two will be the time.

    no guarantee, this is an unqualified estimate: this would give you a max error of about 200 clocks.
    I can see no better precison using one timer with that many inputs. If you need better precision you will need to gang timers/5 uCs with PCA.

    Erik

Children
No data