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.

[SOLVED] Interrupt from the match of PR2 and TMR2

Status
Not open for further replies.

Franck84

Newbie level 4
Joined
Feb 5, 2012
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
Hi,
my name is Franck. I have got a problem with my code. Basically the program is not going to the interrupt routine when PR2 and TMR2 match. That will be great if someone can help me on that. I have no idea what can be wrong. On the mplab watch window I can observe the flag on TMR2IF when PR2 equals TMR2 following by the reset of TMR2. But impossible to see the increment of "count"
Thanks
Here is my code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <p18f4610.h> 
#include<stdio.h> 
#include<delays.h> 
#include<timers.h> 
#pragma config WDT=OFF , OSC=HS , PWRT = ON, LVP=OFF 
#pragma interrupt isr 
int count=0; 
void isr(void) 
{ 
if(PIR1bits.TMR2IF==1) 
{ 
 
count=count++; 
PORTAbits.RA0=1; 
} 
PIR1bits.TMR2IF=0; 
} 
 
void main (void) 
{ 
 
//T2CON=0x7F; 
T2CONbits.T2OUTPS0=0; 
T2CONbits.T2OUTPS1=0; 
T2CONbits.T2OUTPS2=0; 
T2CONbits.T2OUTPS3=0; 
T2CONbits.TMR2ON=1; // turn on the timer2 
T2CONbits.T2CKPS0=1; 
T2CONbits.T2CKPS0=1; 
PR2= 100; 
PIE1bits.TMR2IE=1; //Enable TIMER2 Interrupt 
INTCONbits.PEIE=1; //Enable Peripheral Interrupt 
INTCONbits.GIE=1; //Enable INTs globally 
}


PS: I am using MPLAB v8.60, C18 compiler
 
Last edited by a moderator:

Use this code:
Code:
#include <p18f4610.h> 
#include<stdio.h> 
#include<delays.h> 
#include<timers.h> 
#pragma config WDT=OFF , OSC=HS , PWRT = ON, LVP=OFF 
int count=0; 
void interrupt_at_high_vector(void);
void high_isr(void);

#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
  _asm GOTO high_isr _endasm
}
#pragma code /* return to the default code section */
#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.TMR2IF==1) 
{ 
 
count=count++; 
PORTAbits.RA0=1; 
} 
PIR1bits.TMR2IF=0; 
}
 
void main (void) 
{ 
 
//T2CON=0x7F; 
TRISA = 0;
CMCON = 7;
ADCON1 = 7;
T2CONbits.T2OUTPS0=0; 
T2CONbits.T2OUTPS1=0; 
T2CONbits.T2OUTPS2=0; 
T2CONbits.T2OUTPS3=0; 
T2CONbits.TMR2ON=1; // turn on the timer2 
T2CONbits.T2CKPS0=1; 
T2CONbits.T2CKPS0=1; 
PR2= 100; 
PIE1bits.TMR2IE=1; //Enable TIMER2 Interrupt 
INTCONbits.PEIE=1; //Enable Peripheral Interrupt 
INTCONbits.GIE=1; //Enable INTs globally 
while(1);
}

Hope this helps.
Tahmid.
 

Thanks Tahmid. I just found out . That is exactly the way to do it. Thanks again
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top