HI all:
I'm working with the old good CCS compiler and a PIC 18F88 ( not yet in the flesh)
i have configured the oscillator to 4Mhz and i try to use the timer 2 to create an interrupt every 10 ms
so the dummy code is as follows
setup_timer_2(T2_DIV_BY_4,250,10);
that means 1EE6 /4 = 250EE3 , or an increment every 4us, this goes 250 times, then i have an overflow every 1 ms and an interrupt every 10 overflows so i have an interrupt every 10 ms
the code i get to do this is like this
int I,M;
#int_TIMER2
void TIMER2_isr(void)
{
setup_timer_2(T2_DIV_BY_4,250,10);
I++;
if (I==100)
{
M++; //this should happen every second
}
}
void main()
{
setup_timer_2(T2_DIV_BY_4,250,10);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
for(;

{
if (M==60)
{
// the good stuff will be here every minute
M=0;
}
}
}
BUT.... when i try to simulate this code into the MPlab ide i get very different values
and in the mage3 you will see the place of the breakpoint
I'm really lost in this one because if i read the data sheet and a lil of logic this should happen every second!
Any ideas? thanks in advance for your input
Cheers
PS the images corresponds to the first and second pass over the breakpoint and the 3rd one is the place of the breakpoint itself.
Posted on: March 30, 2008, 07:06:35 AM - Automerged
Ops Sorry i forget to re initialize the variables and i change the names for something else and then they work as they should, seems that I is a reserved word ?? I starts at 100 no mater what i do.
Cheers
Now i get a breakpoint every 1.004085 seconds... real close but i will find out where is the missing cycles ahead
Cheers!
Posted on: March 30, 2008, 07:24:19 AM - Automerged
OK...i was missing the ZERO, so the correct value for the initialization is
setup_timer_2(T2_DIV_BY_4,249,10);
this way, with a crystal of 4 Mhz you will get exactly an interrupt every 10 ms
Hope this helps
Cheers