PROTEUS showing Stack overflow error - Page 1
Forum section: electronics / general

author: khatus
author_rank: Regular Contributor
timestamp: October 28, 2018, 03:23:06 pm
content: I wanted to generate a delay of 1ms by using PIC18F2550 Timer0 Interrupt Service Routine using MIKROC for picwhen i tried to simulate this in PROTEUS, i got some errorsQuoteHere is my code..Code://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 herePulse =~ 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

author: newbrain
author_rank: Super Contributor
timestamp: October 28, 2018, 06:34:48 pm
content: 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 routinehas to bevoid interrupt(void), while in your code it'svoid 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, theivvector andicsflag 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.

author: khatus
author_rank: Regular Contributor
timestamp: October 28, 2018, 06:41:34 pm
content: Thanks!! It works!!But why i can't used any other function name other thanvoid interrupt(void) ??

author: newbrain
author_rank: Super Contributor
timestamp: October 28, 2018, 07:47:18 pm
content: 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).

author: khatus
author_rank: Regular Contributor
timestamp: October 28, 2018, 08:28:08 pm
content: 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??

author: JPortici
author_rank: Super Contributor
timestamp: October 28, 2018, 08:31:33 pm
content: There is no trick. Just read the documentation. "P18 priority interrupts" in the page linked above

author: newbrain
author_rank: Super Contributor
timestamp: October 28, 2018, 08:48:55 pm
content: Quote from: khatus on October 28, 2018, 08:28:08 pmClick Here!Seriously, the link is in my first answer!