STACK HARDWARE OVERFLOW

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

STACK HARDWARE OVERFLOW

Post by siliconchip »

Hi all,
first off happy new year to you all, secondly HELP !!!!

my program works as expected in the simulation but when compiling i get the following message,

"D:\flowcode 7\CAL\PIC\PIC_CAL_IO.c: 209: non-reentrant function "_FC_CAL_Port_In_DDR__x" appears in multiple call graphs and has been duplicated by the compiler
Resistance Meter 3 feedback 887 MK5.c: 2278: (1393) possible hardware stack overflow detected; estimated stack depth: 9 (warning)"

ive tried the program in hardware and it doesn't work like in the simulation which i guessed would happen, ive no experience in stack over flow other than i think i may need a different chip ?? but if i understand right the stack on this chip is 8 deep ??and im exceeding this and i think the cause is checking the state of RB0 at the bottom of the program if this is the case how can i improve my program if possible but without changing the chip, this is all guesswork on my part so if im wrong which i believe i am, could some one show me the light at the end of the tunnel please :oops: :oops:

thanks in advance bob
Attachments
Resistance Meter 3 feedback 887 MK5.fcfx
(21.58 KiB) Downloaded 219 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by mnf »

Can't see a particular reason the compiler would complain, but you need to move the call to enable the interrupt outside of the loop... Just after lcd_I2c1::Start should do it.

Start may never quite have the value you expect - you set it in the connect interrupt, but also read the value of B0 in the main loop...

How much RAM does the chip have too??

Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by siliconchip »

hi martin
thanks for the reply ive moved the enable interrupt outside the main loop but still get the error, the chips sram as per data sheet is 368 but when i compile nothing is at 100% other than config bits so i im at a loss, simulation is great but hardware does not work ???

bob

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by mnf »

How much memory does the i2c display use as a buffer?

Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by siliconchip »

hi martin
i really dont know and wouldnt know where to look, im sure this error only occurs since i added the RB0 check,

bob

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by mnf »

No it's not that - it's a 20 character display rather than a graphic display....

There is something odd with the program logic.. Can you move the Switch1::ReadState out of the interrupt (and disable the interrupt icon) - it's probably me - but I can't see the logic of having start read by an interrupt and then setting it from B0 using an input (I assume you want to test/display data whilst the button is pressed - then clear the display on release?)

Also you have:
Capture.PNG
(11.98 KiB) Downloaded 2231 times
- the loop is only entered if the switch state is 1 (input B0->state) then waits for the interrupt to clear state to 0?
Note that I would probably use Switch1::ReadState in the loop?

You also set the lcd cursor too (20,0) followed by printstring("pins 2-6") (if start=2) which may not have the effect desired..

The loop 3 times - which prints different data on 0,1 and 2 - probably needs a delay of some sort - it might run correctly in simulation but it will be many (many) times faster running on the MCU.

Some ideas, at least?


Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by kersing »

The possible stack error occurs if the interrupt fires while the lcd_I2C1::Start() macro is running. As the interrupt is (still) disabled at that point that will not happen so you can ignore the warning. If you want to get rid of it replace the basic_switch1:ReadState() macro with an input icon to read port bit 0.

You should move the interrupt enable out of the loop to just before the loop starts, there is no need to enable it every time the loop runs.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by siliconchip »

hi martin and kersing
thanks for the replys ive added a revised flowchart taking on board your comments i hope but im still getting the error message when compiling ive not tried in hardware yet i would appreciate any feedback cheers


bob
Attachments
Resistance Meter 3 feedback 887 MK6.fcfx
(20.3 KiB) Downloaded 205 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by Benj »

Hi Bob,

Just tried compiling your program here and I get these messages under v7.
D:\Flowcode 7\CAL\PIC\PIC_CAL_IO.c: 209: non-reentrant function "_FC_CAL_Port_In_DDR__x" appears in multiple call graphs and has been duplicated by the compiler
D:\Flowcode 7\CAL\internals.c: 72: (1090) variable "_FCI_TMP_INT" is not used (warning)
D:\Flowcode 7\CAL\internals.c: 71: (1090) variable "_FCI_TMP_STR" is not used (warning)
These can all be ignored and the program should run fine on hardware.

The only warning that would have caused issues would have been this one. But as Kersing says it wouldn't have actually ever been a problem for you.
Resistance Meter 3 feedback 887 MK5.c: 2458: (1393) possible hardware stack overflow detected; estimated stack depth: 9 (warning)

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: STACK HARDWARE OVERFLOW

Post by siliconchip »

hi benj
thanks for the reply, looking at my code could you confirm that i have set up my RB0 int correctly to function ive not had chance to test in the real world yet, cheers


bob

Post Reply