Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timer1 inside an interrupt

Status
Not open for further replies.

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
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
}
}
}
 

I cant understand your question which controller you are using 16f or 18f what you mean by 'T' is it an another timer or time event, are you doing firing angle controll project ...
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top