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
Hello friends,
I am using PIC18F452 and MikroC as compiler.
I am trying to use a timer inside a hardware Interrupt. i.e. : implementing the functionality like when a hardware interrupt is triggered, it should give 5 cycles of square wave square wave.
Here I have disabled the interrupt for TMR1 and only checking for hardware interrupt
This program is entering the ISR and also LED is blinking, but it is blinking indefinitely. Program is not coming out of the ISR.
I didn't found the way.
Is it because it may be storing the interrupt signals because practically I can't provide a perfect single pulse for interrupt.
Is there something with my hardware switch. Do I need to connect a capacitor along the way with switch for interrupt.
Or there is something wrong with the code.
I am using PIC18F452 and MikroC as compiler.
I am trying to use a timer inside a hardware Interrupt. i.e. : implementing the functionality like when a hardware interrupt is triggered, it should give 5 cycles of square wave square wave.
Here I have disabled the interrupt for TMR1 and only checking for hardware interrupt
Code:
int cnt=0,i=0,j=0;
void interrupt() //hardware interrupt ISR
{ //for high priority interrupt
INTCON.GIE=0;
TMR1ON_bit= 1; // start the timer1
for(i=0;i<10;i++) //this loop provides 5 cycles
{
LATC.B5= ~ LATC.B5; // toggle the output // Blink LED
for(j=0;j<5;j++) // Loop to provide 500ms delay;
{
while(TMR1IF_bit==0);
TMR1IF_bit=0;
}
}
TMR1ON_bit=0;
INTCON.GIE=1;
}
void main() {
ADCON0=0;
ADCON1=0x0F; // no analog inputs
PORTC.B7=0; //PortC.B7= input
TRISC.B7=1;
PORTC.B6=0; //PortC.B6= output
TRISC.B6=0;
PORTC.B5=0; //PortC.B5= output for continuous wave
TRISC.B5=0;
PORTB=0; //PortB= input for interrupt
TRISB=255;
INTCON.PEIE=1; //Enable global interrupt
INTCON.GIE=1;
// Settings For INT1
INT1IE_bit=1; // enable interrupt1
INT1IP_bit=1; //Enable priority high
INT1IF_bit=0; // clear flag bit
INTEDG1_bit=1; // interrupt on rising edge
// settings for Timer1
INTCON =0xC0; // since PEIE and GIE are already enabled.
TMR1H= 0x0B; // set timer values for 100ms
TMR1L= 0xDC;
TMR1IF_bit=0; // clear flag bit
TMR1IE_bit=0; // disable timer1 interrupt
TMR1IP_bit=0; //priority as low
T1CON= 0x30; // 16bit mode with pre-scalar of 1:8
// timer 1 not started
do
{
LATC.B6 = PORTC.B7;
} while(1) ;
}
This program is entering the ISR and also LED is blinking, but it is blinking indefinitely. Program is not coming out of the ISR.
I didn't found the way.
Is it because it may be storing the interrupt signals because practically I can't provide a perfect single pulse for interrupt.
Is there something with my hardware switch. Do I need to connect a capacitor along the way with switch for interrupt.
Or there is something wrong with the code.