LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN MSG PAYLOAD: Will I need to configure for 2 bytes if I need a 9 bit msg

Solved!
Go to solution

Utilizing the "CAN Loopback Test" example in the Frame Out Stream mode, I have a CAN channel that I created which represents vibration utilizing an accelerometer. I would like to obtain 9 bits of resolution so that I can represent values in the range of -128 g's to + 127.5 g's with a resolution of .5 g's. Do I need to configure the channel for 16 bits (2 bytes) even though I will only be utilizing 9 bits? I noticed that the payload (I'm assuming this is the data being tranmitted) is limited to 1 byte per frame. Does that mean I need to utilize 2 frames, the first frame containining bits 0 thru 7 and the second frame containing the 9th bit?

0 Kudos
Message 1 of 17
(4,395 Views)

It sounds like you're confusing bits and bytes. A CAN frame can contain up to 8 bytes (64 bits) of data. To transmit 9 bits, you will need to transmit 2 bytes (16 bits) which will fit easily in a single frame.

Message 2 of 17
(4,382 Views)

It looks like I didn't do a good job with my explanation or maybe just a matter of semantics. I understand that 1 byte = 8 bits. Referencing the "CAN Loopback Test.vi", the Ouput Data array contains a payload of 1 byte so I can only output 8 bits from array index 0. So, I am concluding that if I want to output 9 bits, I need to output 1 bit from array index 1. :. 8 bits from array index 0 and the 9th bit from array index 1.

The description is a little confusing to me in that the "number to read" input on the XNET Read (FRAME CAN).vi is described as "number of frame values desired", however the input is actually an indexed array of clusters containing 1 byte of payload data. A frame is actually 8 bytes not one byte. I just want to make sure I'm interpretting this right. Thanks! Smiley Wink

0 Kudos
Message 3 of 17
(4,364 Views)

XNET Read returns an array of frames - an array of clusters, where the cluster structure represents a CAN frame, and each frame is one array element. Within the frame cluster, the "payload" element is an array of up to 8 elements. So, when you tell it to read N frames, you get an array of N clusters, and each cluster contains a payload of up to 8 bytes.

Message 4 of 17
(4,346 Views)

This is specifically what I am trying to accomplish:

 

Accelerometer data (little endian)

2 bytes per accelerometer channel changed to 9 bits per accelerometer channel

(9 bits = 512) +128 g to -128 g.

Resolution = .5 g per bit

Offset = -128 g

 

Is this how it would be represented:

Please refer to attachment

 

 

Download All
0 Kudos
Message 5 of 17
(4,303 Views)

Hi sfrosty,

 

basic recommendation: read the manual for your accelerometer. There you will /should find the description of the CAN messages!

 

Your "CAN MSG Properties" image is on the right track. The only thing unknown here is the placing of the data in the message: you might stuff 2×9 bits like you do in your "message overview" - but I guess using 16bit entries for each accelerometer value is more probable…

Your "CAN 512" image confuses me: I guess you still are confused of bytes and bits! The payload array is an array of bytes - and you seem to use 9 bytes in two CAN message frames…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 17
(4,298 Views)

So than each value in the payload is actually an integer representing a byte in base 10? So is the depiction I attached to represent the number 256 correct? 255 + 1

0 Kudos
Message 7 of 17
(4,288 Views)

Hi sfrosty,

 

So is the depiction I attached to represent the number 256 correct? 255 + 1

Wrong!

256 = 1*2^8 + 0*2^0 = bytes 0, 1 (LSB first)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 17
(4,282 Views)

oops! In the CAN msg Properties for vib_3, there should have been 9 bits and not 16.

 

0 Kudos
Message 9 of 17
(4,281 Views)

I'm getting there? So is each of the locations in the payload a power of 2 or a decimal value?

0 Kudos
Message 10 of 17
(4,273 Views)