Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

11-20-2020 11:13 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

11-20-2020 11:52 AM - edited 11-20-2020 11:53 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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?

11-20-2020 12:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi altenbach,

Thanks for your reply. I will check the data type.

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.

11-20-2020 03:14 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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?

11-20-2020 03:49 PM - edited 11-20-2020 03:55 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.)

11-20-2020 04:11 PM - edited 11-20-2020 04:13 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

11-20-2020 06:20 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

11-21-2020 12:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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..

11-22-2020 01:27 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

11-22-2020 02:57 PM - edited 11-22-2020 03:27 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.