float16 for 8bit Controller

24 views
Skip to first unread message

bernha...@googlemail.com

unread,
Aug 4, 2017, 5:36:09 PM8/4/17
to UAVCAN
Hi,

I implement the "simple sample" on a small STM8 Controller for Send data types oder 1110 messages.
But ich have a Problem with float16 Format.
The function in the "simple sample " dosn't work on 8bit.
I found a lot of Infos about float16 numbers.
Miniformat with 16 bits hast other names like "half precision" or "half".
But how can i calculate it?
Have someone an idea?
Regards
Bernhard

Pavel Kirienko

unread,
Aug 5, 2017, 12:28:15 PM8/5/17
to bernha...@googlemail.com, UAVCAN
Hi Bernhard,

Could you please clarify which exact function is not working, and why do you think it doesn't? It's going to be hard to provide a meaningful response otherwise.

Thanks,
Pavel.


--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/uavcan/c535955f-6c4f-4ab3-8ab2-c7a78063a478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bernha...@googlemail.com

unread,
Aug 5, 2017, 5:01:15 PM8/5/17
to UAVCAN, bernha...@googlemail.com

Hi Pavel,

I implemented the function "uint16_t make_float16(float value)" from the "simple sensor example"

*****************
    DataFloat16 = make_float16(temperature);
    payload[2] = (DataFloat16 >> 0)  & 0xFF;
    payload[3] = (DataFloat16 >> 8)  & 0xFF;
***************************

If i debug my program with the tempeature of 27,8351173°C in my variable "tempeature" i got the return value from the "make_float16" function from 0x7FFF which i send on the bus.
The UAVCAN GUI Tool decode me this messages

******************************
device_id: 1

temperature: nan

error_flags: 0

******************************

Regards

Bernhard


Pavel Kirienko

unread,
Aug 5, 2017, 5:14:37 PM8/5/17
to bernha...@googlemail.com, UAVCAN
Bernhard,

Perhaps the size of int on your MCU is 16 bit? If this is the case, the problem might be caused by overflowing integer literals and bit shifting beyond the most significant bit. Consider adding the L suffix to all large integer literals, as shown here: https://paste.ee/p/Jw7v5.

If the above suggestion helped, please consider submitting a pull request with these modifications here: https://github.com/UAVCAN/uavcan.github.io/blob/master/Examples/Simple_sensor_node/simple_sensor_node.c

Thanks!

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.

bernha...@googlemail.com

unread,
Aug 5, 2017, 5:32:15 PM8/5/17
to UAVCAN, bernha...@googlemail.com
Hi Pavel,

it look better.

Here my trace
RX    23:27:24.650633    10045601    01 00 D2 4E 00 C8           ...N..    1        uavcan.equipment.device.Temperature  ==>nan
RX    23:27:24.650633    10045601    02 00 D9 4E 00 C9           ...N..    1        uavcan.equipment.device.Temperature  ==>27,3966

RX    23:27:26.670748    10045601    01 00 FF FF 00 CA           ......    1        uavcan.equipment.device.Temperature  ==>nan
RX    23:27:26.670748    10045601    02 00 E9 4E 00 CB           ...N..    1        uavcan.equipment.device.Temperature  ==>27,6406

RX    23:27:28.538855    10045601    01 00 FF FF 00 CC           ......    1        uavcan.equipment.device.Temperature  ==>nan
RX    23:27:28.538855    10045601    02 00 E3 4E 00 CD           ...N..    1        uavcan.equipment.device.Temperature  ==>27.5469

RX    23:27:30.576972    10045601    01 00 C6 4E 00 CE           ...N..    1        uavcan.equipment.device.Temperature  ==>27.0938
RX    23:27:30.576972    10045601    02 00 DA 4E 00 CF           ...N..    1        uavcan.equipment.device.Temperature  ==>27.4062

RX    23:27:32.599087    10045601    01 00 FF FF 00 D0           ......    1        uavcan.equipment.device.Temperature  ==>nan
RX    23:27:32.599087    10045601    02 00 FF FF 00 D1           ......    1        uavcan.equipment.device.Temperature  ==>nan

in some cases the calculation resulte is nan.

Regards

Bernhard

Pavel Kirienko

unread,
Aug 5, 2017, 5:38:39 PM8/5/17
to bernha...@googlemail.com, UAVCAN
A stray overflow has probably crept into the code. Try to generate a sequence of numbers with a fixed step and see if there are any patterns that can be observed. Double check the code and make sure that no overflows are taking place. Most importantly, enable all compiler warnings. Compilers are usually smart enough to warn you about this kind of error unless you're suppressing or ignoring their warnings, which nobody should ever do.

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.

bernha...@googlemail.com

unread,
Aug 5, 2017, 5:48:25 PM8/5/17
to UAVCAN, bernha...@googlemail.com

Hi Pavel,

here i record some values.
Input           output   GUI Tool
27.2162399  20174   27.2188
27.8847237  20217   27.8906
27.4587364  65535   nan
27.8953323  20217   27.8906

The other idea from you i make it next time.
I'm not a expert with float calculation.
We speak about this format?

********************************

The IEEE 754 standard specifies a binary16 as having the following format:

**************************************
==> i must only increase the the lower 10 bits (significand precision)

Regards

Bernhard



Regards

Bernhard

Pavel Kirienko

unread,
Aug 5, 2017, 5:51:03 PM8/5/17
to bernha...@googlemail.com, UAVCAN
Yes, we're using IEEE 754 binary16. Sorry, I can't remotely debug the code for you, you will have to do that yourself. If you have any other questions, feel free to ping me again.

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.

bernha...@googlemail.com

unread,
Aug 5, 2017, 6:06:45 PM8/5/17
to UAVCAN
No problem.
You are the Joker for the big Problems. ;-)))
I make the Tests the next days.
Now it's time for sleeping.
Thanks for your time.

RegardS

Bernhard

Reply all
Reply to author
Forward
0 new messages