[Resolved]Use Ln function with 8bit chip (ECIO-40)

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

[Resolved]Use Ln function with 8bit chip (ECIO-40)

Post by Laliloa »

Hi, I'm working on a project for highschool.
So, basically we work on an ethyl alcohol tester and we need to use the Ln function and the exponential function.
However Flowcode doesn't compile the program when we use these functions in our calcul instruction, so we decided to make a test program (see the attachments).
But the flowcode return code is still equal to 1, same for the exponantial one while the pow function work properly.
expo.PNG
ref1
(20.45 KiB) Downloaded 4663 times
If anyone have any idea to help us, it'll be pretty cool.
Regards,
Chloe.
Edit :
Solution :
The problem is that 8-bit PIC uses the BoostC compiler which does not support the Exp and Ln functions, so you have to create your own macros in order to approache these functions.

There is a sample (from SteveM) which contains these functions in order to use them with 8-bit PIC :
SteveM wrote:
ln and exp functions.fcfx
(7.95 KiB) Downloaded 261 times
The float_exp() macro is simple - it is just the pow() function, but with the 'E' value (Euler's number) preset as the number base. The float_ln() macro is a bit more complex - it uses a Taylor Polynomial approximation - so the accuracy and speed may not be quite as good as a proper compiled 'C' version. You can adjust the accuracy (at the cost of some speed), by changing the value of the 'PRECISION' constant in the float_ln() macro - but it is good to three or four decimal places, which should be precise enough for most high school science experiments.
I don't have an ECIO40 to hand, but FC6 compiled the macro's to an ECIO40 .hex file without errors, so hopefully this will help to get your project working.
Last edited by Laliloa on Sun Apr 06, 2014 10:15 pm, edited 1 time in total.

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: [Help]Function Ln

Post by Benj »

Hello Chloe,

If your using 8-bit PIC then the BoostC compiler does not support the Exp and Ln functions. The compilers for AVR and dsPIC do support these functions so would these be an option for you?

Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: [Help]Function Ln

Post by Laliloa »

Thanks you for your anwser.

Currently, i'm using ECIO40 microcontroller(it's an 8 bit pic and i can only use this one).
So, if I'm right i can switch to an other compiler(AVR or dsPic) in order to use my program on my ECIO40 ?
If I correctly understood, can you please tell me how to change the compiler i use, so as to build my program for the ECIO40.

User avatar
SteveM
Posts: 55
Joined: Tue Mar 25, 2014 2:09 pm
Has thanked: 28 times
Been thanked: 65 times
Contact:

Re: [Help]Function Ln

Post by SteveM »

Hi Chloe,

If the ECIO is the device that you must use, then you will not be able to use those other compilers - they work only with their own specific type of chip. But here is an alternative solution - using some little maths tricks to generate the answers using the more simple float functions of the 8bit chip. The file contains two macros - for the ln(x) and exp(x) functions, and a small main flowchart with the test that I used to check the accuracy. If you need to use these macros in the flowchart you have already, simply store each macro using the 'Macro - Export' menu command - then import them into your own file with the 'Macro - Import' menu item.
ln and exp functions.fcfx
(7.95 KiB) Downloaded 279 times
The float_exp() macro is simple - it is just the pow() function, but with the 'E' value (Euler's number) preset as the number base. The float_ln() macro is a bit more complex - it uses a Taylor Polynomial approximation - so the accuracy and speed may not be quite as good as a proper compiled 'C' version. You can adjust the accuracy (at the cost of some speed), by changing the value of the 'PRECISION' constant in the float_ln() macro - but it is good to three or four decimal places, which should be precise enough for most high school science experiments.
I don't have an ECIO40 to hand, but FC6 compiled the macro's to an ECIO40 .hex file without errors, so hopefully this will help to get your project working.

Best Regards
Steve.

Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: [Help]Function Ln

Post by Laliloa »

Thanks for your reply.

Right now, i can't test it on my home computer (i only got free registered flowcode V6) and i receive an error message when i try to open flowcode project from others computer(valid licence) "<start> attribute is missing".
So, i have to wait till tomorrow for test your maccro in my project on a valid flowcode's licence.
I'll let you know, how it goes.

Best Regards,
Chloe.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: [Help]Function Ln

Post by medelec35 »

Hi Chloe,
Laliloa wrote:when i try to open flowcode project from others computer(valid licence) "<start> attribute is missing".
A common cause of 'attribute is missing' is when your flowcode is an earlier version than the flowcode that was used to create the flowchart you're trying to open.

E.g if you have V6.03 and trying to open a flowchart that was created with V6.06

Make sure you have the latest Flowcode version installed.
At the time of writing from here:
http://www.matrixmultimedia.com/mmforum ... 54&t=14600

Martin
Martin

User avatar
SteveM
Posts: 55
Joined: Tue Mar 25, 2014 2:09 pm
Has thanked: 28 times
Been thanked: 65 times
Contact:

Re: [Help]Function Ln

Post by SteveM »

Hi Chloe,
Aaah, yes, this is so easy for us to forget here at Matrix team - as Medelec says, we are often using a newer version of the software than our users! The latest release, v6.0.6, is available HERE - however, please note that this is a pre-release version; we hope to make it an official release in the next few days, so long as no show-stopping bugs are found by the users who are kind enough to help us with testing. Your high school might not want to take the chance with a 'test' version of the software - so, in the mean-time, here is a screenshot of the flowcharts that should not take too long to copy - the 'project explorer' view on the left will show you what variables and constants each macro requires...
maths_funcs_screenshot.PNG
(70.55 KiB) Downloaded 1149 times
The values for the constants should be...
E = 2.718281828 (for both macro's - this is Euler's number)
E_REC = 0.36787944 (this is 1.0/E - multiplying uses much less chip power than dividing, so this constant helps make the macro run a little faster)
PRECISION = 5 (This value seems to give good accuracy without stressing the chip too much)

Best regards.
Steve.

Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: [Help]Function Ln

Post by Laliloa »

Thanks you.
I still got an error into the compilation phase, i got flowcode 6.0.7.
I send you my program, if you saw any problem can you help me ? I still work on it right now.

Best Regards,
Chloe.
Attachments
prog3clean.fcfx
(19.29 KiB) Downloaded 246 times
Last edited by Laliloa on Sun Apr 06, 2014 10:03 pm, edited 1 time in total.

Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: [Help]Function Ln

Post by Laliloa »

Hi, so i have really no idea on what i can do to resolve my problems.
I tryed to change PRECISION or EULER CONSTANT PRECISION, but nothing work.
Any clue to help me getting out of my problem ?

Best Regards,
Chloe.

User avatar
SteveM
Posts: 55
Joined: Tue Mar 25, 2014 2:09 pm
Has thanked: 28 times
Been thanked: 65 times
Contact:

Re: [Help]Function Ln

Post by SteveM »

Hi Chloe,
Apologies for the delay replying to you, I needed to show your code to one of our senior programmers to be sure what the problem was.

The compiler error that you see is, unfortunately, due to a bug in Flowcode - so it is not caused by any error that you have made. Under certain circumstances, adding Strings together to build a message is not working correctly - and this bug has now been passed to our programmers to fix. In the mean-time, you can work around the compiler error by building the message in two steps, as shown in the picture below (you will need to do this for each icon where the message is constructed)...
String message bug.PNG
(38.78 KiB) Downloaded 4517 times
After applying this fix, I experimented with your program, and I have a little advice for you - but, of course, I do not wish to anger your tutor by doing your work for you, so I will give only a small clue!...
You have a decision icon for "draw or do not draw the message" inside your loops. Good, this is excellent programming practice! However, the logic which makes this decision may need some attention in order to avoid an empty screen. :?:

Best Wishes,
Steve.

Laliloa
Posts: 6
Joined: Mon Mar 24, 2014 2:46 pm
Has thanked: 5 times
Been thanked: 2 times
Contact:

Re: [Help]Function Ln

Post by Laliloa »

Thank you very much for all your help and useful information.
My problem seems to be fixed right now I'll go ahead on my project.
I will keep you updated.

Best Regards,
Chloe.

PS : I edited my first post, i wrote the solution in it.

User avatar
SteveM
Posts: 55
Joined: Tue Mar 25, 2014 2:09 pm
Has thanked: 28 times
Been thanked: 65 times
Contact:

Re: [Resolved]Use Ln function with 8bit chip (ECIO-40)

Post by SteveM »

You're welcome; glad to hear that your project is back on track. :)
Steve.

Post Reply