News:

Let's find out together what makes a PIC Tick!

Main Menu

faster way to send floats as ascii decimal

Started by rockybooth, Mar 10, 2021, 07:15 PM

Previous topic - Next topic

rockybooth

Hi:
Congratulations for the new developments that seem underway.  I have used this toolset for perhaps the last 20 years on and off.  Currently I am modifying code to adapt one of our products to a new application. We use an 18F2520 running with a 3.687MHz clock to transmit data from the UART at 115200 baud.  For years we have done this without issue, and the data transmitted have been 4 byte floats transmitted as 8 bit binary.  This takes about 350uS to transmit the 4 bytes using the HRSOUT float command.  However, if use HRSOUT DEC float command, it takes around 40mS, presumably because converting the internal float to a string in ASCII DECIMAL is very slow.
I am currently using Proton BASIC Compiler 3.5.9.9

I would appreciate knowing if the current versions of new compilers might offer any improvements.  I am reluctant to just try them as it takes weeks to test the results before we can release such significant changes.

Thanks

top204

#1
Download the latest compiler version and see page 412 of its manual:
https://sites.google.com/view/rosetta-tech/home

QuoteDeclare Float_Display_Type = Fast or Standard
By default, the compiler uses a relatively small routine for converting floating point values to
decimal, ready for Rsout, Print, Str$ etc. However, because of its size, it does not perform any
rounding of the value first, and is only capable of converting relatively small values. i.e. approx
6 digits of accuracy. In order to produce a more accurate result, the compiler needs to use a
larger routine. This is implemented by using the above Declare.
Using the Fast model for the above Declare will trigger the compiler into using the more accurate floating point to decimal routine. Note that even though the routine is larger than the standard converter, it actually operates much faster.
The compiler defaults to Standard if the Declare is not issued in the BASIC program.

The Float_Display_Type declare has been in the language for many years now.

Another fast way is to convert the floating point value into integers, for its main and fractional values, then transmit the integer values with an ASCII decimal point transmitted as well between them. This isn't as accurate, but it is a fast method.

rockybooth

 ;D
Thanks very much. I see for some reason I had tried that in the past, but deleted that option.  I just tried it and it decreased the time from start to end of the transmission from 87mS to 2.4mS.  I'd say that is peachy!!!

Since that is a small code change, I will probably go with that for now.  However I will download the latest proton 8 compiler.
It sounds like you are working on a new compiler (Positron).  For the 18F devices, what kind of changes do you hope for? Or is that for a different family of devices?
Rocky

top204

#3
It is purely a name change from "Proton" to "Positron8" and "Proton24" to "Positron16".

I made the mistake of trust in the past and I never trademarked the names I thought up in the first place, so someone else has now!

The compiler default's to the, original, slower Floating Point ASCII conversion routine because it produces smaller code, and on some devices that is important. If I had made the newer, faster and more accurate, Float display routine the default, a lot of earlier programs written by people would not have fitted in their device because it uses more code memory, so I made it a Declare to enable/disable it. I try my hardest to make the compilers as backward compatible as possible.


Simon

If you want to really cut your data down to the minimum work out what resolution you want and the range that you need to cover.

For example if you are measuring say room temperature you may only need to cover -10 to +40 degrees C. At 0.25  resolution you could store that in a just one byte.