I've got the timer1 interrupt working. It's a 16 bit timer. I'm using a 20MHz oscillator.
I'd like to have a variable micros that keeps track of how long the program has been running. I'd like 10uS resolution.
Using this calculator: **broken link removed**
I found that I can get a 10uS timer period by setting the pre-scalar to 1:1 and timer offset to 0xffcd.
Questions:
- Am I doing this correctly, by setting the TMR1H and TMR1L values in the ISR or there a better way to do this?
- Do I need to account for the (time) length of the ISR to get an accurate count for my micros variable? If so, what should I set my timer period to (ie, 9.8uS or something)?
I'd like to have a variable micros that keeps track of how long the program has been running. I'd like 10uS resolution.
Using this calculator: **broken link removed**
I found that I can get a 10uS timer period by setting the pre-scalar to 1:1 and timer offset to 0xffcd.
Code:
unsigned long micros = 0;
void interrupt isr(void){
if((TMR1IE)&&(TMR1IF)){
TMR1H = 0xff; //TIMER OFFSET FOR 10uS Period
TMR1L = 0xcd; //TIMER OFFSET FOR 10uS Period
micros+=10;
TMR1IF=0; // clear event flag
}
}
Questions:
- Am I doing this correctly, by setting the TMR1H and TMR1L values in the ISR or there a better way to do this?
- Do I need to account for the (time) length of the ISR to get an accurate count for my micros variable? If so, what should I set my timer period to (ie, 9.8uS or something)?