Pages: [1]   Go Down
Author Topic: timer interrupt questions  (Read 475 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've started working with the timer interrupt and using code I found on this forum, have managed to get one working properly.  However I need to integrate this interrupt into other code and I have a couple of questions.

1.  Can someone give me a reference that explains in detail how the timer interrupt works?  In particular what all of the different flags and registers do?  I'm using things like TIMSK2 and CCS21 for example but don't have any sort of reference for them and so don't know what they do are what they mean.

2.  How many timer interrupts are available and how does one use more than one of them?

3.  Do I have to disable anything in the arduino code in order to avoid conflicts?  I am not using pwm at all.

4.  Can I use timer interrupts and external interrupts at the same time?

Any information on this would be great!!  Thanks in advance.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1.  Can someone give me a reference that explains in detail how the timer interrupt works?  In particular what all of the different flags and registers do?  I'm using things like TIMSK2 and CCS21 for example but don't have any sort of reference for them and so don't know what they do are what they mean.

2.  How many timer interrupts are available and how does one use more than one of them?

3.  Do I have to disable anything in the arduino code in order to avoid conflicts?  I am not using pwm at all.

4.  Can I use timer interrupts and external interrupts at the same time?

1) For that sort of data, you'll probably need to refer to the Atmel datasheet for the ATmega168 chip used on the arduino boards.  Then you'll have to delve a bit into the avr-gcc manual to see how they're coded in C.

2) There are three interrupts per timer: Overflow, Compare match A, and Compare match B.  There are three timers.  Note that timer1 is 16 bits, while timer0 and timer1 are 8 bits.

3)  The arduino core using the timer0 overflow to do the basic functions like millis() and delay();  Timer1 and Timer2 are only used for PWM, as far as I know (neglecting potential 3rd party libraries.)  So in theory you have 8 interrupts you can use (if you can live with the timer0 setup) and full control of two of the timers.
Logged

Pages: [1]   Go Up
Jump to: