optimization flowchart

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

optimization flowchart

Post by bercioiu »

Hi all! I have made a clock in Flowcode. I'm new in programming and do not know how to optimize my flowchart to fit in MCU. Untill now the clock have the following options:

- Display the hour in 12 or 24 Hour mode
- Daylight saving mode
- Alarm clock
- Snooze for 5 mins
- Chime mode:
- hour
- half hour
- hour and half hour
- off
- thermometer (in C or F)
- Temperature min/max
- Display the Gregorian calendar with leap correction.

wish list:
- second temperature sensor
- Set the day of week for alarm

but the space of the memory is limited... Please, if you have time, look on the program and advised me how to optimize code. Thank you in advance!
Attachments
CLOCK.fcf
(219.34 KiB) Downloaded 488 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: optimization flowchart

Post by Benj »

Hello,

Your program looks quite modular and well organised, there may be some optimisation you can do but without going through the program with a comb it's hard to tell. Would a pin compatible chip upgrade be possible to give you more memory.

Eg 16F1937 or 16F1939?

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: optimization flowchart

Post by bercioiu »

Thanks for your quick replay Benj! There is a tutorial from which I can learn how to write the code more efficient (economical) ? I think what I wrote there it can be done much better otherwise.
I ordered new chips recommended by you.

Thanks again!

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: optimization flowchart

Post by JonnyW »

Hi. Optimization just tends to be one of those things you learn out of necessity over time - there are no hard and fast rules as every platform has subtle differences. For example, on platforms with a floating point co-processor doing some calculations in floating point greatly speeds up your program, where as on other platforms this can greatly slow it down.

This is a list of rough guidelines that may make code more efficient. It is completely dependant on the program being written though:
  • Avoid replicating code - if you are doing the same calculations over and over again, consider using a macro instead to wrap up this code.
  • See if using a loop to do repetitive actions reduces code rather than repeating similar actions over and over.
  • Use a switch icon instead of multiple nested decision icons if possible as the same variable does not need to be checked multiple times.
  • Use local variables for temporary calculations - eg: Instead of having a Temp_C and Temp_F, could you just keep one and use a conversion macro to calculate the other on-the-fly?
  • Consider what variables are needed in calculations and which are not - if you are storing data in global variables just to print that information out, why not use local variables and discard the info after it is displayed.
  • On the PIC, use shifts instead of divisions (where possible) - this can save small amounts space as well as speed as there is no need to call the divide routines.
  • Use bit-flags instead of multiple variables for states. This depends on your use but can save on RAM when you have a large amount of flags, and code space where you are checking multiple flags at once.
  • Comment your code clearly. Obviously this does not save space in the short term, but it is often easier to optimize code when it it immediately obvious what t does, rather than having to sit and think about it for a minute.
  • Use constants instead of hard-coded numbers. This is mainly for legibility though, but is similar to the reasons why you should comment your code.
I hope this is useful.

Jonny

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: optimization flowchart

Post by bercioiu »

Thanks for your advice! It definitely help me to get started.

Post Reply