PROTEUS showing Stack overflow error

Thread Starter

khatus

Joined Jul 2, 2018
89
I wanted to generate a delay of 1ms by using PIC18F2550 Timer0 Interrupt Service Routine using MIKROC for pic
when i tried to simulate this in PROTEUS, i got some errors

[PIC18 STACK] PC=0x0038. Stack overflow is forcing device reset. [U1]


Here is my code..
C:
//Timer0, Prescaler 1:8; TMR0 Preload = 6; Actual Interrupt Time : 1 ms//
#define Pulse LATB


/***************Interrupt Service Routine for Timer1******************/
void interrupt_Timer0_ISR()
//void interrupt_1()
{
if (TMR0IF_bit)
  {
    TMR0IF_bit = 0;    /* Make Timer0 Overflow Flag to '0' */
    TMR0L    = 0x06;

  //Enter your code here
    Pulse =~ Pulse;   /* Toggle PortB at of 500 Hz */

   }
}

void Timer0_start()
{
    T0CON = 0xC2;
    TMR0L    = 0x06;/* Load Count for generating delay of 1ms */

    GIE_bit =1;        /* Enable Global Interrupt */
   
    TMR0IE_bit =1;    /* Enable Timer0 Overflow Interrupt */
    TMR0IF_bit = 0;

}
void main()
{
   // OSCCON =0x72;    /* Configure oscillator frequency to 8MHz */
    TRISB = 0;      /* Set as output Port */
    Pulse = 0xff;      /* Send high on PortB */
    Timer0_start();

    while(1);

}

My question is what is Stack overflow???
Please correct my code if there is any error
 

Ian Rogers

Joined Dec 12, 2012
871
Stack overflow is just that.... The stack has 16 levels and your program has achieved 16+..
As your program ONLY has an ISR I assume that a rogue interrupt is firing causing issues..

As you didn't include a snapshot of your config box, I can't see what could be causing your problem..

"Stack overflow" shouldn't even be displayed if the compiler is worth any salt!!
The error is hardware stack and not software stack...…

Is your watchdog running?????
 

MrChips

Joined Oct 2, 2009
23,221
How does the compiler know which is the interrupt ISR?
Is the name of the ISR predetermined in the interrupt vector table?
Should you not be declaring:
void interrupt Timer0_ISR(void)

Did you clear the interrupt flag in the ISR?
 

jayanthd

Joined Jul 4, 2015
906
Mention your oscillator or crystal frequency to fix the code.

You should use something like this.

Code:
void interrupt() {
    if((TMR1IE_bit) && (TMR1IF_bit)) {
         TMR1IF_bit = 0;
         //Reload timer here.
         //Set a flag here 
    }
}
Use flag test in main loop and run the reuired code in main loop and after running the reuired code in main loop clear the flag.
 
Top