shubham kumar
Member level 3
- Joined
- Sep 11, 2014
- Messages
- 59
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Location
- bangalore
- Activity points
- 511
Hi I am using PIC18F452 and MikroC.
What I am trying to do is, start a timer (TIMER0) with low priority interrupt. And in the ISR of that I am starting another timer (TIMER1) (which has been given higher interrupt priority). and when I am coming out of TIMER0 ISR, I am turning off the TIMER1.
So Timer1 will be running only when program is in ISR of TIMER0
But is not giving expected output
My aim is to find the time a program spent in ISR if some one writes a large code in ISR. So, here I am doing that by using timer1.
[[here I am not using TMRH TMRL etc .. once I will confirm that this is correct then I will think of measuring time]].
What I am trying to do is, start a timer (TIMER0) with low priority interrupt. And in the ISR of that I am starting another timer (TIMER1) (which has been given higher interrupt priority). and when I am coming out of TIMER0 ISR, I am turning off the TIMER1.
So Timer1 will be running only when program is in ISR of TIMER0
But is not giving expected output
My aim is to find the time a program spent in ISR if some one writes a large code in ISR. So, here I am doing that by using timer1.
[[here I am not using TMRH TMRL etc .. once I will confirm that this is correct then I will think of measuring time]].
Code:
unsigned char txt[8],txt1[8];
int timer0_cnt=0, timer1_cnt=0,cnt=0,t,lambda;
void interrupt() // high priority interrupt TImer1
{
if(TMR1IF_bit)
{
TMR1IF_bit=0; // clear flag
timer1_cnt++; // increment cnt1
}
TMR1H=0;
TMR1L=0;
}
void interrupt_low() // Low priority interrupt TIMER0
{
if(TMR0IF_bit)
{
TMR0IF_bit=0; // clear flag
TMR1ON_bit=1; // start timer 1
lambda=1;
// just do something
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda=0;
timer0_cnt++; // increment cnt0
TMR1ON_bit=0; // Stop TIMER1
}
}
void main()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
ADCON0=0;
ADCON1=0x0F; // no analog inputs
INTCON = 0xC0;
INTCON.GIEL=1;
INTCON.GIEH=1;
// Timer0 settings
TMR0H = 0; TMR0L = 0; // Timer0 initial value
T08BIT_bit=0; // timer in 16 bit mode
TMR0IF_bit=0; // clear flag
TMR0IE_bit=1; // enable interrupt
TMR0IP_bit=0; // set at low priority
// Timer1 settings
TMR1H=0; TMR1L=0;
TMR1IF_bit = 0; // clear TMR1IF
TMR1IE_bit = 1; // enable Timer1 interrupt
TMR1IP_bit=1; // set priority high
T1CON = 0x00; // Timer1 settings
TMR0ON_bit=1; // Timer0 started
do
{
if(timer1_cnt>10)
{
IntToStr(timer1_cnt,txt);
Lcd_Out(1,1,txt);
Lcd_Out(1,9,"Tmr1_10");
timer0_cnt=0;
// Delay_ms(500); // used just to see the output for some significant time
}
if(timer0_cnt>5)
{
IntToStr(timer0_cnt,txt1);
Lcd_Out(2,1,txt1);
Lcd_Out(2,9,"Tmr0_5");
timer1_cnt=0;
// Delay_ms(500); // used just to see the output for some significant time
}
// just do something
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda= lambda+1; lambda= lambda+1; lambda= lambda+1; lambda= lambda+1;
lambda=0;
}while(1);
}