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 pic18F4550 interrupt problem

Status
Not open for further replies.

sifrid

Newbie level 4
Joined
Oct 19, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
hello every one, i've been trying to solve a problem i have with the overflow flag TMR1IF, it doesn't seems to get set when timer 1 reaches 255 or 65535 depending on the operation mode, i paste my code below:

#include <htc.h>

#define _XTAL_FREQ 4000000

__CONFIG(1,MCLRDIS & WDTDIS & INTIO & STVREN_OFF);

void init (void)
{

OSCCONbits.IDLEN=1; // device enters idle mode on sleep inst
OSCCONbits.IRCF2=1; // 4MHZ
OSCCONbits.IRCF1=1;
OSCCONbits.IRCF0=0;
OSCCONbits.OSTS=1; // oscilator Start-up
OSCCONbits.IOFS=1; // frequency stable bits
OSCCONbits.SCS1=1; // internal oscillator
OSCCONbits.SCS0=0;

RCONbits.IPEN=0; //if 0 disables priority leves if 1 enables them
//INTCON=0b11000000; //enables GIE and PEIE
INTCON=0b1000000; // enables GIE
PIE1bits.TMR1IE=1; // Timer1 interrup flag enable
PIR1bits.TMR1IF=0; // clear overflow flag

T1CONbits.RD16=1; //it is suppose to count up to 65535
T1CONbits.T1RUN=0; //device clock is derive from a source different to timer1 osc
T1CONbits.T1CKPS1=1; // 1:4
T1CONbits.T1CKPS0=0;
T1CONbits.T1OSCEN=0; // Timer1 oscillator is shut off
T1CONbits.TMR1CS=0; // Internal clock selected
T1CONbits.TMR1ON=0; // stops Timer1

ADCON1=0b00001111; //All pins as digital

}

void main (void)
{
init();
T1CONbits.TMR1ON=1; //starts timer 1

while(1)
{
if(PIR1bits.TMR1IF==1)
{
PORTDbits.RD2^=1;
PIR1bits.TMR1IF=0;
}
}

}

i use MPLAB IDE v 8.76 and HI-Tech v9.80 PICC 18 in lite mode, so when i use MPLAB SIM tool and run the code step by step checking the watch window, TMR1 register counts up to 255 but as you may see above, i wrote T1CONbits.RD16=1 so it is suppose to count till 65536 and if i write T1CONbits.RD16=0 it counts up to 65535 not 255, anyway that's not my main concern, as i started checking the watch window i realized TMR1IF never gets set on overflow so i never get to toggle the led placed on RD2, but idk what could be the problem i've already enabled TMR1IE and GIE......
Another trouble i've found is that when i enable PEIE (INTCON=0b11000000;) i always get the message CORE-E0001: Stack over flow error occurred from instruction at 0x007fe6 in the output window, so by now i don't know if i'm writing something wrong in the code, or if there is a HI-tech bug i'm not aware of, so i'll appreciate any help you can give me. thank you in advance.
 

ok, i missed that i just wrote TRISDbits.TRISD2=0; in the init function but i still have the troubles i mentioned.
 

A good advice is to NEVER do use
PortX as output
but instead use LatX

so try :
LATDbits.LATD2^=1
 

aProgrammer thanks a lot, i do really appreciate someone is trying to help, i just followed your advice and tried to run the programm again but it never steps into

if(PIR1bits.TMR1IF==1)
{
LATDbits.LATD2^=1;
PIR1bits.TMR1IF=0;
}
 

RCONbits.IPEN=0; //if 0 disables priority leves if 1 enables them
//INTCON=0b11000000; //enables GIE and PEIE .........this line is commented out, and the datasheet says

" if IPEN is set to zero,as above, then PEIE needs to be set to 1 in the INTCON register, for any of the Peripheral interrupts to work. This includes TMR1IE bit,
which is in the PEI1 register.

I know its really late, but let me know if this makes the program work. thanx
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top