Author Topic: PROTEUS showing Stack overflow error  (Read 3155 times)

0 Members and 1 Guest are viewing this topic.

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: gl
PROTEUS showing Stack overflow error
« on: October 28, 2018, 03:23:06 pm »
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

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


Here is my code..

Code: [Select]

//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

 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1918
  • Country: se
Re: PROTEUS showing Stack overflow error
« Reply #1 on: October 28, 2018, 06:34:48 pm »
Disclaimer: I don't do PICs and mikroC, so take this with a hefty pinch of salt...

But it would seem that the interrupt service routine has to be void interrupt(void), while in your code it's void interrupt_Timer0_ISR(): I fear your ISR is never used, hence the timer interrupt flag is never reset and the global interrupts never re-enabled.

If you want to use your own name, the iv vector and ics flag must be specified.

AFAICS, the PIC18F2550 limits the number of nested calls to 31 and the meaning of the Stack Overflow error is that the code is exceeding that number, causing an automatic reset.

Since there are no nested calls in your code, it's probably just the program going off its rails when trying to execute a non-existent ISR.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: gl
Re: PROTEUS showing Stack overflow error
« Reply #2 on: October 28, 2018, 06:41:34 pm »
Thanks!! It works!!


But why i can't used any other function name other than  void interrupt(void) ??
« Last Edit: October 28, 2018, 06:46:51 pm by khatus »
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1918
  • Country: se
Re: PROTEUS showing Stack overflow error
« Reply #3 on: October 28, 2018, 07:47:18 pm »
As described in the page I linked, in fact, you can.

For the PIC18 architecture, ISR are not exactly the same as regular functions (e.g. they need a special return instruction), so the compiler needs to be told that a specific function is an ISR.
In mikroC this can happen in two ways:
  • You name your function interrupt() or interrupt_low()
  • You name it as you please, but specify the interrupt vector (iv) and the context save flag (ics)

Other architectures, notably Arm, can use any regular void f(void) as interrupt handler (as long as it's pointed by the interrupt vector table).
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 166
  • Country: gl
Re: PROTEUS showing Stack overflow error
« Reply #4 on: October 28, 2018, 08:28:08 pm »
I don't know how to specify the interrupt vector (iv) and the context save flag (ics).

I have never heard that before.do you have any link for this tricks??
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3921
  • Country: it
Re: PROTEUS showing Stack overflow error
« Reply #5 on: October 28, 2018, 08:31:33 pm »
There is no trick. Just read the documentation. "P18 priority interrupts" in the page linked above
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1918
  • Country: se
Re: PROTEUS showing Stack overflow error
« Reply #6 on: October 28, 2018, 08:48:55 pm »
I don't know how to specify the interrupt vector (iv) and the context save flag (ics).

I have never heard that before.do you have any link for this tricks??

Click Here!
 :-// Seriously, the link is in my first answer!
Nandemo wa shiranai wa yo, shitteru koto dake.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->