Problem with heaps & Stacks when compiling

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Problem with heaps & Stacks when compiling

Postby daveb0360 » Wed Aug 22, 2012 1:04 am

Hi All,
With much help from certain class individuals on the forum, I got my code working in simulation and in Real Pic.

We wrote the code around a 12F617.

However, I then tried to recompile for a 12F675 as my target board had this in place - soldered.
I changed the chip configuration in FC and re-exported the hex for the 12F675. The compiler returned the following for the 617.
File name: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
Generated by: Flowcode v4.5.18.74
Date: Wednesday, August 22, 2012 00:41:11
Licence: Professional
Registered to: Dave Benning


http://www.matrixmultimedia.com


Launching the compiler...
c:\program files (x86)\matrix multimedia\flowcode v4\boostc\boostc_pic16_flowcode.exe -v -t PIC12F617 "HeaterControlVgdb2tst.c"
BoostC Optimizing C Compiler Version 7.04 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


HeaterControlVgdb2tst.c
Starting preprocessor: c:\PROGRA~2\MATRIX~1\FLOWCO~1\boostc\pp.exe HeaterControlVgdb2tst.c -i c:\PROGRA~2\MATRIX~1\FLOWCO~1\boostc\include -d _PIC12F617 -la -c2 -o HeaterControlVgdb2tst.pp -v -d _BOOSTC -d _PIC16 -d _CHAR_INDEX


.

HeaterControlVgdb2tst.c success

success

Return code = 0

Launching the linker/assembler...
c:\program files (x86)\matrix multimedia\flowcode v4\boostc\boostlink_pic.exe -ld "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\lib" libc.pic16.lib flowcode.pic16.lib rand.pic16.lib float.pic16.lib "HeaterControlVgdb2tst.obj" -t PIC12F617 -d "C:\Users\Dave\Desktop\Projects\Wash" -p "HeaterControlVgdb2tst"
BoostLink Optimizing Linker Version 7.03
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday


Warning unreferenced functions removed:
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_INT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_S in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_Ms in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
isinf in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCD_ADC0_ReadAsByte in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
FCD_ADC0_ReadAsVoltage in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
FCD_ADC0_ReadAsString in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
FCD_ADC1_ReadAsByte in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
FCD_ADC1_ReadAsVoltage in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c
FCD_ADC1_ReadAsString in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst.c

Building CASM file
Memory Usage Report
===================
RAM available:128 bytes, used:64 bytes (50.0%), free:64 bytes (50.0%),
Heap size:64 bytes, Heap max single alloc:31 bytes
ROM available:2048 words, used:738 words (36.1%), free:1310 words (63.9%)



success

Return code = 0

FINISHED


But this was what I got when I compiled for the 675.....and the board doesn't work at all....nada.......nothing.....

File name: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
Generated by: Flowcode v4.5.18.74
Date: Wednesday, August 22, 2012 00:59:26
Licence: Professional
Registered to: Dave Benning


http://www.matrixmultimedia.com


Launching the compiler...
c:\program files (x86)\matrix multimedia\flowcode v4\boostc\boostc_pic16_flowcode.exe -v -t PIC12F675 "HeaterControlVgdb2tst675.c"
BoostC Optimizing C Compiler Version 7.04 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


HeaterControlVgdb2tst675.c
Starting preprocessor: c:\PROGRA~2\MATRIX~1\FLOWCO~1\boostc\pp.exe HeaterControlVgdb2tst675.c -i c:\PROGRA~2\MATRIX~1\FLOWCO~1\boostc\include -d _PIC12F675 -la -c2 -o HeaterControlVgdb2tst675.pp -v -d _BOOSTC -d _PIC16 -d _CHAR_INDEX


.

HeaterControlVgdb2tst675.c success

success

Return code = 0

Launching the linker/assembler...
c:\program files (x86)\matrix multimedia\flowcode v4\boostc\boostlink_pic.exe -ld "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\lib" libc.pic16.lib flowcode.pic16.lib rand.pic16.lib float.pic16.lib "HeaterControlVgdb2tst675.obj" -t PIC12F675 -d "C:\Users\Dave\Desktop\Projects\Wash" -p "HeaterControlVgdb2tst675"
BoostLink Optimizing Linker Version 7.03
http://www.sourceboost.com
Copyright(C) 2004-2011 Pavel Baranov
Copyright(C) 2004-2011 David Hobday


Warning unreferenced functions removed:
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_INT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_S in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_Ms in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
isinf in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCD_ADC0_ReadAsByte in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
FCD_ADC0_ReadAsVoltage in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
FCD_ADC0_ReadAsString in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
FCD_ADC1_ReadAsByte in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
FCD_ADC1_ReadAsVoltage in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c
FCD_ADC1_ReadAsString in: C:\Users\Dave\Desktop\Projects\Wash\HeaterControlVgdb2tst675.c

Building CASM file
Memory Usage Report
===================
RAM available:64 bytes, used:64 bytes (100.0%), free:0 bytes (0.0%),
Heap size:0 bytes, Heap max single alloc:0 bytes
ROM available:1024 words, used:743 words (72.6%), free:281 words (27.4%)



success

Return code = 0

FINISHED


Can anyone enlighten me as to what's wrong? No errors are reported but differences in Heap and Allocation are apparent..........is this what's stopping my code from working on the 675? and why does it happen?

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Wed Aug 22, 2012 9:31 am

Hi Dave,
I think your issue is close to the following issue...as your RAM seems fine, ROM also fine.
viewtopic.php?f=5&t=2166&p=3566&hilit=heap+size#p3566
Can you please post the program you are trying to compile so that we can check whether we can replicate the situation?
Enamul
University of Nottingham
enamul4mm@gmail.com

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby daveb0360 » Wed Aug 22, 2012 11:36 am

Hi Enamul,
The problem is more serious.
I wrote the code for the 12F617 but had a 675 soldered to the board.........I changed chip in FC to 617 and exported files to hex etc. No Problems.

However, NOW the programmer is destroying my 617 chips during programming!!! :evil: :twisted: :?
Of Course, I'd like to understand what this heap & stack problem might be.....but more urgently, WHY IS MY PICKIT 2 PROGRAMMER DESTROYING MY 617's ???????
I am following the programming specs to the letter and the same hardware has had a 675 chip reprogrammed many times without damage.......I DON'T LIKE THESE 617 CHIPS :!: :cry: !!!!!

Files attached.
Attachments
Heater control_Various.zip
(162.21 KiB) Downloaded 142 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Wed Aug 22, 2012 11:53 am

Hi,
I think it's completely PICkit2 issue. It has no link with FC. Your program is compiling fine in both the chips. I don't have any pickit2 in hand to test with PIC12f617 but someone with that could come-up with a solution. I will read through PICKIT2 user guide and will let you know if I notice any thing.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Wed Aug 22, 2012 12:07 pm

Hi Dave,
Regarding Heap size...
When the application is built, the linker uses RAM memory left after allocation of global and local variables as a heap. When some memory gets allocated at run
time by the 'alloc' call, it gets allocated from this heap. The bigger the heap, the more run time objects can exist at any given time.

Code: Select all

void* alloc(unsigned char size)

Dynamically allocate memory 'size' bytes long. Max size is 127 bytes. Returns NULL if memory can't be allocated.

Code: Select all

void free(void *ptr)

Free memory previously allocated by 'alloc'. Passing any other pointer will lead to unpredictable results.

So in your case as you have used 64 bytes of RAM which is the max amount of RAM can be used in PIC12f675 so no heap left. But in case of 12f617, 64 heap left as the RAM is 128 and you have used 64 Byte.
Hope this is clear :)
So as I have mentioned in my last post, no problem is in FC..you have problem in programmer. I would suggest you to buy one EB006-08 Board to solve the problem now and at the same time try to sort the problem of PICKIT2.
Enamul
University of Nottingham
enamul4mm@gmail.com

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby daveb0360 » Wed Aug 22, 2012 1:52 pm

Hi Enamul,
I have used this PK2 with lots of different pics in the past without issue. However, until the last update, the PK2 was not compatible with 617...I had to download an updated definition file to make 617 appear in the supported list.
MPLAB application still lists the 617 as 'NOT SUPPORTED' by PK2..... so....I think you are right! I think the PK2 does not properly support the 617 even though it is included in the latest files.

I think you got the memory allocation back to front with the 617 v 675....the 617 has twice the ram of 675....which is why Martin suggested I use it in the first place.

The best solution might be to cut down my code so it fits with a little spare space onto the 675.......I know the 675 programs ok with PK2 because that's what I've been developing with. It only failed when I filled the ram. How much do I have to cut out to make this heap problem go away?

I'm gonna get a better programmer soon but not yet.......no spare money at the moment...until then, I have to find the best workaround to solve this issue.

Cheers
Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Wed Aug 22, 2012 2:09 pm

Hi,
Thanks. I have corrected 675 vs 617..Are you facing any problem in running current program in PIC12f675? If not just try to save some space in ROM, don't bother as long as it accommodates in RAM.
Enamul
University of Nottingham
enamul4mm@gmail.com

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby daveb0360 » Wed Aug 22, 2012 5:51 pm

Hi Guys,
It would seem, It is still unknown why it wasn't working but I suspect it was the WDT symbol entered at the top of the code........when I removed it and disabled it in config (see image)......the 617 works in the breadboard.
I'm not going to try the 675 now as I suspect it's the same issue......not a memory issue at all.......I'll try it another time.
For now, I feel content that programmer hasn't been killing my chips and I stand a chance of finalising this at last...
Dave
Attachments
Working 617 config.PNG
Working 617 config.PNG (26.38 KiB) Viewed 6510 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Wed Aug 22, 2012 6:10 pm

Hi,
One thing I always do, I disable watchdog timer in the code first of all. I have seen that you are clearing watchdog timer in the c code..I don't know why. If you disable that in config you don't need to clear that in program. Yes of course this watchdog could cause lots of trouble. So it's better to keep it aside if you are not expert to use it.
Enamul
University of Nottingham
enamul4mm@gmail.com

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby daveb0360 » Thu Aug 23, 2012 12:40 pm

Understood Enamul,
But......This circuit MUST have a way of preventing lock up to avoid the heater going overtemp during use.

Any suggestions?

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby Enamul » Thu Aug 23, 2012 2:19 pm

yes. I have designed a circuit using analog components to work around that problem. I'll post that to-night.
These users thanked the author Enamul for the post:
daveb0360 (Fri Aug 24, 2012 3:15 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8541
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby medelec35 » Thu Aug 23, 2012 6:08 pm

Its just personal choice with watchdog timer. Our company has been selling a heater that is software driven for about 10 years with no issues and watchdog timer is enabled.
I have also developed a product a year ago and I enabled watchdog timer. Its important it does not reset since if resets once then the day count that stored in EEPROM will not be correct.
Since only updates after a full 24Hrs. After been running on mains for 200days, diagnostics via RS232 is still showing 200days.

I will not develop any product without watchdog enabled.

Tip: Do not place any clear watchdog commands or any delays (since if auto watchdog is enabled, a delay will automatically place clear watchdog command) within any interrupts.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 190 times
Been thanked: 140 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby petesmart » Thu Aug 23, 2012 10:39 pm

Hi Martn,

You make some very good points.

When you get a moment, would it be possible to create one of your very informative tutorial posts on the topic?

A basic how to on watch dog implementation would be very helpful.

Hope it's not a too cheeky request :mrgreen:

Best

Pete
sorry about that Chief!

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8541
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby medelec35 » Fri Aug 24, 2012 8:55 am

I would like to clarify:
I’m not stating I believe Enamul is wrong, as indeed you can use hardware to reset.

If going down watchdog route.
What I would recommend is always develop project with watchdog disabled first!
You must be happy that final project is working the way you intended before watchdog is enabled.
If you don’t and project not working the way its intended, then you won’t know if watchdog timeout or mistake in flowchart is causing issue.

@Pete I will see what I can do :wink:
These users thanked the author medelec35 for the post (total 2):
petesmart (Fri Aug 24, 2012 11:50 am) • daveb0360 (Fri Aug 24, 2012 3:15 pm)
Rating: 10.53%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby daveb0360 » Fri Aug 24, 2012 3:15 pm

Hi Guys,
Since the use of WDT is so complex and fraught with possible problems, would someone mind 'inserting' and configuring it into my code for me when I've finished it please. It's such an important aspect to my design that I don't want to 'trial and error' it.
Ideally, I'd like to use external watchdog but I don't have the luxury of time or cost freedom.

Cheers

Dave

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8541
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Problem with heaps & Stacks when compiling

Postby medelec35 » Fri Aug 24, 2012 5:28 pm

daveb0360 wrote:Since the use of WDT is so complex and fraught with possible problems

Hi Dave it's not really that bad.
You may find that by just enabling Auto clear watchdog (matrix added that to make it easier) within View, project Options and enabling watchdog timer in configuration options (Flowcode V4) is all that's required. Of course we can help you, but may be worrying about nothing.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.