AVERAGE FLOATING POINT

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

Moderator: Benj

Post Reply
maxtisc
Posts: 110
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 9 times

AVERAGE FLOATING POINT

Post by maxtisc »

Hi Team
I wanted to ask you if anyone has ever done a FIFO floating point average, I would need to do this type of average on a sample of 50 results after they have been converted by a sensor with SPI interface, looking in the forum it does not seem like anyone has already done so, what is the correct approach for you?
Thank you

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

Re: AVERAGE FLOATING POINT

Post by medelec35 »

Hi.
I'm using a BME280 Temperature/Humidity/Pressure Sensor.
So I could calculate altitude, It was vital the pressure float results were ultra-stable.
To do that I used
Very stable readings.png
Very stable readings.png (145.45 KiB) Viewed 2886 times
The altitude was so stable it could measure the height of me lol.
Note: I used ground to keep floats rounded up to 2dp.
Martin

maxtisc
Posts: 110
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 9 times

Re: AVERAGE FLOATING POINT

Post by maxtisc »

Hello Medelec35
thanks for your submission but I think it is not good for my work, I had already done such a thing, if I understand correctly yours is a mathematical average made on 150 samples, and having a loop of 1 mS it can be said that the result that you could theoretically see on a display would be every 150mS, unfortunately my times are much longer as I receive new data only every 200mS so with an average set to 50 I have a new value to send to the display every 10Sec, I would need it a FIFO type average, that when I filled the buffer, I update the oldest data with the new one and recalculate the result, and I would have an update every 200mS
I hope I have understood your example, otherwise correct me
thanks for your help

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: AVERAGE FLOATING POINT

Post by mnf »

Here's an example using a FIFO list of data (just random data here...)
fifo.fcfx
(12.69 KiB) Downloaded 197 times
The macro AddValue does all the work - main just pumps in data and displays debug to UART (with a lomg delay that could be reduced for simulation...)

Martin

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: AVERAGE FLOATING POINT

Post by chipfryer27 »

Thanks Martin

A new string to my bow.

Regards

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: AVERAGE FLOATING POINT

Post by mnf »

No problem, hope it is useful

If speed is important then make the sum global and subtract the existing value (buffer[pos]) before adding the new value... Then you can remove the loop too...

Math

maxtisc
Posts: 110
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 9 times

Re: AVERAGE FLOATING POINT

Post by maxtisc »

Great Martin, looks like what I needed, in simulation works well, soon I try to do it in my program
thank you very much

Post Reply