Makro in makro

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

Post Reply
Dmitry Maximenko
Flowcode V4 User
Posts: 36
Joined: Mon Sep 26, 2011 10:26 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Makro in makro

Post by Dmitry Maximenko »

Hello!
I wonder a bit about the macro structure in Flowcode.
When repeating things in the program will then wish to use the macros.
Is it okay to call 1) component macro from a macro.
2) Call the macro from a macro?
Can there be any problems?
Very thankful for all answers
Best Regards
Dmitry

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Makro in makro

Post by DavidA »

Hello Dimitry,

Im sure someone will correct me if im wrong but i think that every time you call a macro from within a macro you add to the call stack, which is an indication of how many times you have nested a macro, there is no problem with going deeper into the call stack but i think most microcontrollers have a maximum call stack depth. 8 rings a bell for some PICs.

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: Makro in makro

Post by Benj »

Hello,

On a 8-bit PIC there is a limitation of a 8 level hardware call stack. That is you can jump up to 8 macros away from main and still know where to return when leaving the macros. An interrupt and any macro calls from this also count as levels on the stack.

If you go over this count then the compiler should warn you about it. If you get the warnings then you can switch on the BoostC software call stack which uses a combination of hardware and software to extend the number of macro jumps possible without getting lost. This however will increase the amount of time to complete an operation.

AVRs, dsPICs and ARM do not have such a strict stack limitation.

IVL
Posts: 17
Joined: Sat Sep 17, 2011 7:10 pm
Location: Belgium
Has thanked: 8 times
Been thanked: 5 times
Contact:

Re: Makro in makro

Post by IVL »

Macro's are often used in 3 contexts
- to reuse a block of code more than once and maintain this code in 1 place only
- a block of code called by an interupt. This is just a special case of the above
- help structuring your code regardless of the fact you are calling this macro only once.

My questions are about the 3th case.

- Is there a way to tell either flowcode or the compiler to un-nest any macro which is used only once ?
This would make a lot of sence to minimize the call stack as a lot of pics can handle only 8...
I know there is some software call stack you can use to increase the max stack size above 8, but it remains a waiste of scare pic resources not to un-nest single used macros.

- about the software call stack, where can i find more information about how to activate/use it ?

Regards,
Ivan

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: Makro in makro

Post by Enamul »

HI,
For your 2nd question...you can see the following post..
http://www.matrixmultimedia.com/mmforum ... ack#p36165
I have seen one post of Ben also but can't find straight way..

Code: Select all

-ld "C:\Program Files\Flowcode\v5\Tools\BoostC\lib" libc.pic16.lib rand.pic16.lib float.pic16.lib -swcs 6 2 "%f.obj" -t PIC%p -d "%d" -p "%f"
Main change is this compiler option..
Enamul
University of Nottingham
enamul4mm@gmail.com

IVL
Posts: 17
Joined: Sat Sep 17, 2011 7:10 pm
Location: Belgium
Has thanked: 8 times
Been thanked: 5 times
Contact:

Re: Makro in makro

Post by IVL »

Just for completeness and helping users how to implement BoostC software stack to avoid stack overflow :

1) In the FlowCode menu select Build, Compiler options
2) choose the tab Linker/Assembler
3) in the parameter box, scroll to the end and add the following parameter :
-swcs 6 2

This should do the trick, it did for me.

Regards,
Ivan

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: Makro in makro

Post by Enamul »

Hi,
I now remember Ben's post ...He told to add as you said. Thanks for the post. Now I can easily find for others..
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply