Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Pic18f452 tmr0 & interrupt problems

Status
Not open for further replies.

bobx

Junior Member level 3
Joined
Jan 11, 2010
Messages
29
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Location
TEHRAN
Activity points
1,531
Hello,everybody.I write a program to measure the input signal frequency by using an TMR0 interrupt and A function to display it on a LCD.But my TMR0 interrupt function does not send counter varaiable[cntr] to my
displaying funtion or maybe not worked well,because I have only ; FRQ.= 00000 HZ on my LCD,[I test my funtion of FRQ. displaying by writting cntr=45678,then it displayed it on my LCD.So ,my Tmr0 interrupt function is not worked prioperly.].
At the following are myTMR0 interrupt function in two way but does not worked none of them.
Would you please help me to correct it?

My TMR0 interrupt functions;


PIC18F452,XTAL;20MHZ
1.way 1;

/*
FREQUENCY MEASURMENT Interrupt.
this program writes the frequency of
the input signal on the RB1/INT1 pin.

*/

//PORTB,RB1,IN : Counter Input.

//RB1 Interrupt.
void frqint(unsigned long int cntr){

extern unsigned long int cntr;//Number of RB1 transition.
extern unsigned int ovrflw;//Number of timer0 overflows.
extern unsigned char frq;

INTCON.INT1IE=1;//Enables INT1 external interrupt.
T0CON = 0b11011000;//No prescaler.[RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0.].
cntr =0;//Clear counters;the number of RB1 transition.
ovrflw =0;//Clear the number of timer0 overflows.
INTCON3 =0b00001000;//INT1IE,INT1IF enabled.

while(ovrflw < 65223){//Wait 1 second.
T0CON.TMR0ON=1;//Enables Timer0;ON.

if(INTCON.INT1IF){
cntr++ ;//Inc.transition counter.
INTCON.INT1IF=0;//clear interrupt flag to enable next call.
}

else if(INTCON.TMR0IF){ //TIMER 0 overflow.
ovrflw++ ;//Inc.overflow counter.
INTCON.TMR0IF=0;//clear interrupt flag to enable next call on overflow.
}
}



INTCON.INT1IE=0;//Disables INT1 external interrupt.
INTCON.TMR0IF=0;//clear interrupt flag to enable next call on overflow.
T0CON.TMR0ON=0;//Disables Timer0;OFF.



}//~


2.way2;
/*
FREQUENCY MEASURMENT Interrupt.
this program writes the frequency of
the input signal on the RB1/INT1 pin.

*/

//PORTB,RB1,IN : Counter Input.

//RB1 Interrupt.

void frqint(unsigned long int cntr){

extern unsigned long int cntr;


INTCON=10100000;//Enables the TMR0 overflow interrupt TMR0IE,and global interrupt GIE.
INTCON2.RBPU=1;//Enable PORTB pullups.
TMR0H=0X7;//For 1 sec.TMR0 interrupt;65223.
TMR0L=0XFE;
T0CON=10000011;//16-bit mode,1:16 prescaler,Timer0 clock input comes from
//prescaler output,Increment on low-t0-high transition
//T0CKI pin, internal instruction cycle clock[CLKO],Timer0 ON.

T0CON.TMR0ON=1;//Turn the TMR0 ON.

do{
if(RB1_bit) cntr++ ;//Inc.transition counter.

}while(!TMR0IF);



T0CON.TMR0ON= 0;//Stops TMR0;turn TMR0 OFF.
INTCON.TMR0IF= 0;//Clears TMR0 overflow interrupt flag bit for the next call.
INTCON.TMR0IE= 0;//Disables TMR0 overflow interrupt Enable bit.




}//~


Thanks,:?::!:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top