fround command pic 24fFV

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

Moderator: Benj

Post Reply
Roy
Flowcode V4 User
Posts: 17
Joined: Thu Jul 30, 2009 9:13 am
Location: New Zealand
Been thanked: 1 time
Contact:

fround command pic 24fFV

Post by Roy »

Sir I am trying to use the fround command to limit a floating variable to 2 decimal places. It appears not to work in the simulation.

EMA_APHIA = 0.90

EMA_APHIA = fround (EMA_APHIA,2)

when I run the simulation I get 0.899999976------------lots more.
Does this command work in the simulation or only once complied?
While my program is not yet complete as I test each part as I go I have attached the flowcode file MAP_4CH_24FV_master_slave.fcfx
I have read the articles on the forum that tend to indicate the command does not work on 16bit PIC chips.
Can someone please enlighten me as to what I am doing wrong.
Thanks
Attachments
MAP_4CH_24FV_master_slave.fcfx
(35.67 KiB) Downloaded 10 times
Regards
Roy

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: fround command pic 24fFV

Post by mnf »

One way to do this is to multiply the value by 100 (for 2 decimal places) and assign to an integer...
Note that not all numbers can be represented exactly by fp variables.

Can I also suggest an upgrade to v10 it's free and v4 is now very old

Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: fround command pic 24fFV

Post by kersing »

Please keep in mind computers work in ones and zeros, not floating point numbers. As a result some floating point numbers can not be represented exactly and are a close approximation. Check https://floating-point-gui.de/ for an easy explanation or https://ece.uwaterloo.ca/~dwharder/Num ... /paper.pdf for the heavy theory.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Roy
Flowcode V4 User
Posts: 17
Joined: Thu Jul 30, 2009 9:13 am
Location: New Zealand
Been thanked: 1 time
Contact:

Re: fround command pic 24fFV

Post by Roy »

Thanks for your comments . I am using version V8.
I would like to use the value in an EMA calculation (1-alhpia) as part of a filter.
It seems to work in my 8 bit version of the program.
Regards
Roy

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: fround command pic 24fFV

Post by kersing »

Calculations with the numbers should be fine, it is just displaying for us humans that doesn’t work as expected.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply