Thanks Kurt,
We will figure it out. Probably implementing several common decoding
method.
On 13/09/2019 11:17, Kurt Van Dijck wrote:
Hi,
On vr, 13 sep 2019 10:38:23 +0200, Romain Forlot [IoT.bzh] wrote:
Hi everyone,
I have a question about signed numbers in CAN, but I try to handle sign of a
signal's value whenever it is a signed value.
I would like to have something that works in any cases obviously but for
what I found, signed value in CAN bus isn't standardized.
You can have:
* signal on N-1 bits, with the subtracted bit representing the sign
* either with 1's complement
* or 2's complement.
You could have some bitfield not encoded within classics bytes but in 3 or
13 bits by example, so it could complicate the computing of the signed value
depending on the chosen method.
A common method is to define a range, like -1000 to 1000 to be encoded
into 0..2000 unsigned.
In this example, you require 11bits.
The advantages of doing so are:
1) it's not so difficult to convert to/from bitfields, i.e.
as you found, properly decoding a negative number from an 11bit value
is a bit obscure.
2) it leaves explicit room for special/fault codes, above the defined range.
Kind regards,
Kurt
--
Romain Forlot - Embedded Engineer - IoT.bzh
romain.forlot@xxxxxxx -www.iot.bzh - +33675142438