slaamdunk@gmail.com
Junior Member level 1
- Joined
- Aug 27, 2013
- Messages
- 19
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 130
HI,
As part of my project I am needed to start timer1 , count till a certain timer T and then once I am done with T, I need to start counting till 3T.
I implemented this by using Timer1 ( because I could start and stop it) let it overflow for time T and once I have reached T, I stopped and started the same timer in the Interrupt Service Routine. But it doesn't seem to be working. Any idea on how to go about with this problem.
Thank you
This is the sample ISR that I have written
As part of my project I am needed to start timer1 , count till a certain timer T and then once I am done with T, I need to start counting till 3T.
I implemented this by using Timer1 ( because I could start and stop it) let it overflow for time T and once I have reached T, I stopped and started the same timer in the Interrupt Service Routine. But it doesn't seem to be working. Any idea on how to go about with this problem.
Thank you
This is the sample ISR that I have written
Code:
void interrupt isr(){
if(PIR1bits.TMR1IF == 1 && bit_0 ==1 ){ // bit_0 is a variable to denote the first time period T
PIR1bits.TMR1IF = 0;
counter_timer1++;
if(counter_timer1 == 1)
{
if(RB0==1)
{
PORTA = digit[2];
bit_0=0;
bit_1 = 1;
}
counter_timer1 = 0;
//IOCBNbits.IOCBN0 = 1;
T1CONbits.TMR1ON = 0; // disabe timer
TMR1H = 239; // preset for timer1 MSB register to start counting the next timer slot of 3T
TMR1L = 32; // preset for timer1 LSB register
T1CONbits.TMR1ON = 1; // bit 0 enables timer
}
}
// this is where it stops working
if(PIR1bits.TMR1IF == 1 && bit_1 ==1){ // checking condition to see if it has overflown 3T
PIR1bits.TMR1IF = 0;
PORTA=digit[5];
counter_timer2++;
if(counter_timer2 ==1 && RB0 ==0){
counter_timer2 = 0;
IOCBNbits.IOCBN0 = 1;
T1CONbits.TMR1ON = 0; // enables timer
}
}
}