Problem with Log Function with ECIO40

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

Moderator: Benj

patl02
Posts: 2
Joined: Fri May 09, 2014 4:23 pm
Been thanked: 2 times
Contact:

Problem with Log Function with ECIO40

Postby patl02 » Fri May 09, 2014 4:47 pm

Hi,
I am developing a flowcode program to obtain a temperature reading using a thermistor. The basic principle is to interface the thermistor to an ADC input using a potential divider. The program reads the ADC value converts the ADC value to voltage across the thermistor and calculates the resistance of the thermistor. The temperature of the thermistor can then be calculate based on the resistance value. The equation relating resistance and temperature requires the log function.
The program runs fine in simulation mode.
However, when I try to Compile to Chip (for ECIO40), the following error messages are shown:
"unknown identifier log", and "arguments of FCI_SHEAD" don't match parameters of call.

Does anybody have experience of this type of problem, or any suggestions for means of resolving it?
Thank you,
patl02.

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

Re: Problem with Log Function with ECIO40

Postby medelec35 » Fri May 09, 2014 7:56 pm

Hi patl02.
ECIO does not support maths functions like LOG, SIN, TAN ATAN ect.
This is a limitation of BoostC compiler that is used within Flowcode when compiling 8bit microcontrollers .
There was talk about changing from BoostC to a different compiler just so additional maths functions can be supported.
only AVR, ARM and dsPIC support the maths functions you require.

For the ECIO you can use the look-up table method.
There are a few tutorial on using look-up tables in the Tips and Tricks section.
Although there is a dedicated look-up table component macro within Flowcode 6.
If you interested in using that I can help you with it.

If you want to use LUT method then Benj posted an excel sheet which makes life easier.
I adapted the spreadsheet for 5V rather than for MIACs
I will see If I still have the spreadsheet I used when I made a temperature sensor using a thermistor.
Another alternative is to use a different type of temperature sensor e.g LM34 see here

Martin
These users thanked the author medelec35 for the post (total 2):
LeighM (Mon May 12, 2014 8:49 am) • prasha920 (Thu Jan 08, 2015 9:13 pm)
Rating: 10.53%
 
Martin

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

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: Problem with Log Function with ECIO40

Postby LeighM » Mon May 12, 2014 8:49 am

In addition to Martin’s comments, there is also a bug in the string conversion for target code generation.
It occurs when numeric conversion is mixed with string concatenation (the FCI_SHEAD error)
We have a fix in the pipeline for the next release, but in the meantime you can work around this by separating any numeric to string conversion into a separate statement.
That is, only concatenate strings.
Regards,

Leigh

Code: Select all

result_string = "some text"
number_x = 1234
number_string = STRING number_x
result_string = result_string + number_string
These users thanked the author LeighM for the post:
Brendan (Sun May 18, 2014 11:46 pm)
Rating: 5.26%
 

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

Re: Problem with Log Function with ECIO40

Postby SteveM » Mon May 12, 2014 12:30 pm

Hi patl02,
You might be able to make use of the file I posted in this post.. There's a macro to calculate the natural logarithm, ln(x), (i.e. a logarithm with base 'e'). You can convert the natural logarithm to a base 10 logarithm by simply dividing the answer by 2.302585 (that's the natural logarithm of 10 - in general, convert to another number base by dividing by the natural logarithm of the new number base). It uses only normal "8-bit" functions to zero in on an approximation, and has been tested before for compiling to an ECIO. Accuracy should be good to around five significant digits, which should be at least as good as interpolating a lookup-table, and should use less of the chip's memory (though it may be a little slower than an LUT).

Best regards,
Steve.

patl02
Posts: 2
Joined: Fri May 09, 2014 4:23 pm
Been thanked: 2 times
Contact:

Re: Problem with Log Function with ECIO40

Postby patl02 » Tue May 13, 2014 10:29 am

Hi Martin, Leigh and Steve,
Thank you all for your prompt replies. All of the information was very useful, and I have used the macro for the Taylor Series approximation for the Ln function successfully.
Best Regards.
patl02
These users thanked the author patl02 for the post (total 2):
SteveM (Tue May 13, 2014 1:39 pm) • medelec35 (Thu Jan 08, 2015 9:34 pm)
Rating: 10.53%
 

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

Re: Problem with Log Function with ECIO40

Postby SteveM » Tue May 13, 2014 1:42 pm

Hi,
Glad to hear you got everything working.
For those users using Flowcode6, you may also be interested to see another solution to the problem of using certain float functions on the smaller 8-bit PICS...
POST: Macro Library - Float Maths 8-bit
Best Regards,
Steve.

Brendan
Posts: 214
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 132 times
Been thanked: 112 times
Contact:

Re: Problem with Log Function with ECIO40

Postby Brendan » Sun May 18, 2014 11:59 pm

LeighM wrote:In addition to Martin’s comments, there is also a bug in the string conversion for target code generation.
It occurs when numeric conversion is mixed with string concatenation (the FCI_SHEAD error)
We have a fix in the pipeline for the next release, but in the meantime you can work around this by separating any numeric to string conversion into a separate statement.
That is, only concatenate strings.
Regards,

Leigh

Code: Select all

result_string = "some text"
number_x = 1234
number_string = STRING number_x
result_string = result_string + number_string


Thanks Leigh.

This build-time error was driving me nuts for a while until I found this thread (I was concatenating 'StringPhrase + ToString$(NumberVariable') within the LCD component print string box. As you suggest, I can confirm that pre-conversion of NumberVariable to NumberString, followed by simple concatenation of the two string variables StringPhrase + NumberString, fixed it :D


All the best,
Brendan