Jump to content

Conversion on values received via CAN


Recommended Posts

Is there a way to convert values that are not exactly linear but change with some logic?

Example - I have a Bosch steering angle sensor that transmits position and rotation speed over CAN bus. The conversion as per data sheet for similar sensor (multiplier is a bit different in my case, but logic is the same):

Absolute Angle Position:
     • Signed (integer)
     • Angle position [degree] = N · 0.1, for 0 < N ≤ 32767 (N - digital value of the message) = (N-65536) · 0.1, for N > 32767

So, for rotation to one side it goes from 65536 and down, and for other side - from 0 and up.

In both cases value changes by only about 6000 (which represents 780 deg in each direction)

 

Link to post
Share on other sites

Did all of that information come from the same datasheet?  It seems that the formula completely misses the point that the line above it says the data format is signed integer.  Which is exactly what the formula is doing - converting a unsigned integer to signed? 

So provided your receiving device can interpret a signed integer (Link can) you dont need to do any of this, it will directly receive "-1000" for 100deg in one direction and "1000" for 100deg in the other direction.

Link use the same 0.1 resolution but has a -3000 offset so the only thing you need to do is set the type to signed and add an offset of 30000 (3000/0.1).  I dont know your byte position or byte order but scaling will look something like this:

oc0ClIx.png

Link to post
Share on other sites

Well, the fragment with the conversion was copy-pasted from this datasheet: https://www.bourns.com/docs/automotive/datasheets/non-contact-steering-angle-sensor-type-6002.pdf

I believe this sensor in fact transmits value "N", not signed integer and formula is indeed used to convert it.

I also was using Bosch motorsport steering angle sensor document:  https://www.bosch-motorsport.com/content/downloads/Raceparts/Resources/pdf/Data Sheet_191153675_Steering_Wheel_Angle_Sensor_LWS.pdf

Actual sensor is Bosch part from some Citroen C4 and although everything mostly similar to the info from datasheets above, some parameters are different. Among those is probably the scale for some reason, because in my case raw value changes exactly by 2816(which is 256*11) per one full 360 deg revolution, so considering that after around 780 deg in either side sensor throws error, I assumed that the range is the same and raw values should be 0...6101 and 65536...59435 for each respective side. I only checked 360 deg to each side though.

Link to post
Share on other sites

If you set it up as per my example above it will work correctly.  No need to use a formula to covert to signed if the data is already formatted as signed.  This is whats known as two's compliment and is common in CAN bus for values that must read both positive and negative

As an example, your raw value of decimal 59435 that you mentioned above is sent across the CAN bus as ones and zeros, so binary 1110 1000 0010 1011 or it can be more easily represented as hex 0xE82B.  If you put either of those values into an online converter and convert it to a 16bit signed integer you will get the correct -6101 result.  

YKy0gOz.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...