# LabVIEW

cancel
Showing results for
Did you mean:

## How to combine three 8 bit data to 24 bit and do the convert

Hello everyone,

I am trying to divide 24bit data into three parts (8-bits) and send them to USB6009. So I used high three bits as sign bits (000, 001 and 010) and low 8 bits to transfer data. 000 +8 bits data; 001 +8 bits data, 010 +8bits data.

For the LabVIEW program, I use case structure to identify the sign bits and combine these three parts. However, the program only works well when one type of data input. If I send the 000,001 and 010 together, the program can only process one or two parts of data which cannot give an accurate calculation of the three parts. The VI is attached. If I did not make it clear, please let me know. Thanks for your help.

Mars

Message 1 of 18
(240 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

There should not be any orange anywhere on your diagram except at the very end where you apply the scaling. Learn about datatypes.

Please give a few examples of inputs and expected results. I am sure the code can fit on a postage stamp. Your description is very confusing. Why do you need three bits for the sign?

You seem to get a boolean array as raw data representing a signed integer. How are negative values encoded (two's complement, etc.)

If it works well for "one type of data", please explain what kinds of data works and what does not. What's the important difference?

Do you have a reference for the instrument manual describing the format?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 2 of 18
(218 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

Hi altenbach,

The data I want to transfer to USB 6009 is 24-bits (encoded in 2' complement), e.g. 0100 0110 0101 1111 1100 1000.

I divided it into three parts and add 000, 001, 010 to differentiate them. eg.

first part:        000 0100 0110;

second part:  001 0101 1111;

third part:       010 1100 1000.

11 digital input port are used for the data input. If only put one part in, eg, 000 0100 0110, the program can work and shows 0100 0110 0000 0000 0000 0000, and the final value is 8.75. If the three parts are input together, the program can only show one part, eg 0100 0110 0000 0000 0000 0000 instead of 0100 0110 0101 1111 1100 1000 which is 8.796730042.

If you have any questions, please let me know. Thanks.

Message 3 of 18
(201 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

OK, so the first three bits of each 11 bit packet per iteration gives the byte order and the remaining 8 bits form the three parts of the number. Do they arrive in regular sequence?

Your main problem is that you only process 11 bits per iteration and your case structure outputs the default value for the other two. What you need to do is keep an U8 array containing three elements in a shift register and replace one of the elements according to the three bits. Once all parts have arrived parse it. You really need to do a few simple LabVIEW tutorials first. Is the desired result big endian?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 4 of 18
(178 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

See if this can give you some ideas...

(Try with negative numbers and see if adjustments are needed. This is just a rough starting point. Assuming that the three bit array are guaranteed to arrive in order, you would only update the indicator when the third element is received. You can re-use the U8 array in the shift register forever, of course.)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 5 of 18
(172 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

Here's how you would use it in a while loop where you only get 11 bits per iteration. (Sorry, I don't have drivers, but you should see the point).

Of course you might want to add some validity checks, e.g. if the parts don't arrive in order or don't start out with the first byte, etc.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 6 of 18
(162 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

Hi altenbach,

Thank you so much for the details and advice.

The data should arrive in order. I will doublcheck it. And I will read your advice carefully and keep you posted. I think I have a lot to learn.

Best regards,

Mars

Message 7 of 18
(151 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

Correction: Note that you should actually cast to I32 so the arithmetic shift (=scale by power of two) correctly retains the sign.

Alternatively, you could also avoid the U8 array entirely as follows:

There are many ways to do that, but make sure to test and tweak as needed..

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 18
(110 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

Hello altenbach,

Thanks for your advice. It really helps me find the right direction. After testing, I guess I need a validity check because the first byte seems not to arrive first. Do you have any ideas on how to make three bytes in the correct sequence? I am thinking of two options, 1) check the first byte and wait until finding the right one to start (while loop).2) identify the first 3-bits and put them in the specific row of the array.

Thanks,

Mars

Message 9 of 18
(93 Views)

## Re: How to combine three 8 bit data to 24 bit and do the convert

The question is if you have valid data even if they arrive in the wrong order or if you just want to skip data until we get a valid "first" packet.

You could have an array in a shift register with three elements where you replace the oldest index (high three bits shifted)  and rotate the array to have them in historical order, oldest first (for example). Only if the array is [0,1,2] we have valid data to be displayed and further processed, so used this comparison for the condition of the case structure.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 10 of 18
(88 Views)