01-13-2017 01:01 PM - edited 01-13-2017 01:04 PM
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?
Solved! Go to Solution.
01-13-2017 01:26 PM
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.
01-13-2017 01:52 PM
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!
01-13-2017 03:27 PM
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.
01-17-2017 09:12 AM
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
01-17-2017 09:20 AM
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…
01-17-2017 09:45 AM
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
01-17-2017 09:50 AM
01-17-2017 09:53 AM
oops! In the CAN msg Properties for vib_3, there should have been 9 bits and not 16.
01-17-2017 10:10 AM
I'm getting there? So is each of the locations in the payload a power of 2 or a decimal value?