Page 1 of 1
Flowcode for ARM print decimal
Posted: Sat Oct 25, 2008 3:20 pm
by tinker
hello support
just trying out flocode for arm.
declaired a variable as a floating point var,
applied some math
then using LCD print number tried to display the number, but I only get the integer and no numbers to the right of decimal point.
tried both FROUNd and FMOD, but both the same.
I note that selecting LCD print number has guide text along the lines number(int) does this mean this facility can nt be used for floating point numbers ?
regards jane
Re: Flowcode for ARM print decimal
Posted: Mon Oct 27, 2008 11:02 am
by Benj
Hello Jane
Please see this example for printing out floating point numbers.
Re: Flowcode for ARM print decimal
Posted: Mon Oct 27, 2008 10:26 pm
by tinker
Hi Ben
thank you for the pointer re printing a decimal number to the lcd. I understand the code, however it does not lend itself for use with 2 or more decimal places.
for example 3.09 would print as 3.0, hen multiplying by 10, and *100 changes the scale value.
I have no specific application, but I find it incredible that a product like this is unable to deal with printing decimal numbers. If I were setting a radio set to channel frequency, then 88.3750 Mhz etc etc.
is there a "C" solution? or can we peek registers to get the numbers to the RHS of the decimal point?
cheers jane
Re: Flowcode for ARM print decimal
Posted: Tue Oct 28, 2008 9:34 am
by Steve
Floating point numbers are relatively new in Flowcode and they are not directly compatible with many of the components (such as the LCD). V4 will have better support for them.
Floating point numbers are stored intenally in a special format, and are not stored with separate registers for the LHS and RHS of the decimal point. Also, floating point numbers are not always exact: for example, 0.3 might be stored internally as 0.299999999999. This is an issue with all floating point implementations, and not just with Flowcode. I could show you similar issues with Excel.
The example Ben provided should give you an idea of how to do display the values of floating pojt numbers. I have expanded his example (see attached) so you can select the required precision. This technique is by no means perfect, but should be ok for most applications.
Re: Flowcode for ARM print decimal
Posted: Wed Oct 29, 2008 11:08 am
by Sean
It is possible to use a small amount of C code to allow formatted, floating-point values to be printed on the LCD. The gcvt() function from the stdlib library converts a floatingpoint value (double) into a string. The resulting string can be displayed on the LCD using the Flowcode, LCD component, Print string finction.
The attached file OSstubs.c should be copied into the Tools\Global folder of the Flowcode_ARM installation.
Each program using this function will require the following adding to the 'Definitions and function declarations' section of the 'supplementary code' window:
#include <stdlib.h>
#include <OSstubs.c>
int errno;
It will also be necessary to declare a Flowcode string variable to receive the converted floating-point value.
The format of the gcvt() function is: gcvt(Value, Precision, String).
Value is the floating point (doube) variable to be converted.
Precision is the maximum number of digits to be converted.
String is the name of the string variable to receive the converted text string.
The use of Flowcode variables in C code follows the standard rules explained elsewhere:
Flowcode floating-point variable Float1 can be accessed as FCV_FLOAT1 in C code.
Flowcode string variable PrntBuff can be accesses as FCV_PRNTBUFF in C code.
The attached Flowcode program provides a simple example.
Re: Flowcode for ARM print decimal
Posted: Wed Oct 29, 2008 8:54 pm
by tinker
Thanks for the info Sean, printing the number as a string is fine, I will try your code later next week when I get back home.
The other methods do not work when the first digit is a zero eg 38.0725 etc.
cheers
jane