LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String Manipulation for data concatenation

Dear all,

 

Thank you for reading my post.

 

I am using Labview 8.0 on Pentium D 3.4Ghz, 2GB of RAM.

 

I am using a microcontroller PIC24 (on the Explorer 16 development board), which I have programmed to acquire an AC signal at a rate of about 4 kHz. The PIC24 has a 10bit ADC and the acquire value is then padded to16bits in total (format: 0-0-0-0-0-0-d9-d8-d7-d6-d5-d4-d3-d2-d1-d0) as an unsigned int.

 

The serial setting for the pic and my Labview program are 115200, 8 data bits, no parity, 1 stop bit.

 

In order to send the acquired value to my PCs serial port (Remember UART = 8-bits of data only) I divide the 16 bit word into MSB and LSB. I then send the MSB and LSB 8-bit value one after the other.

 

The format I use is:

ADC_High = 0-0-1-d9-d8-d7-d6-d5

ADC_LOW = 1-0-1-d4-d3-d2-d1-d0

 

The total data rate for this communication is about 64kbps.

 

After the VISA Read VI has read and outputted the data (in string format), I am trying to remove the 3-MSB from both ADC_HIGH and ADC_LOW.

 

Once the 3-MSB have been removed, I want to concatenate the two strings (ADC_HIGH and ADC_LOW).

 

After that I want to type cast the concatenated string back to unsigned int and normalize the value.

 

As I am however, new to LV I am having problems.

 

Would some one be as kind as to check the attached VI and give me some advice of what I might be doing wrong?

 

Regards

Alex
0 Kudos
Message 1 of 22
(4,734 Views)
Hi Alex,

This operation would be much simpler if you encoded your data differently on the PIC.  

For Example:
MSB 00-00-00-00-00-00-d9-d8
LSB d7-d6-d5-d4-d3- d2-d1-d0

Then you could simply append the two characters together and then typecast it directly to an I16.

If changing the PIC code isn't an option, you can also perform the bit-by-bit manipulation in LabVIEW to convert the strings to I16.  The attached code should perform this operation, or at least get you close...  You will need to make sure that you only read an even number of characters from your serial port before you pass those charaters to the attached algorithm.  There may be more efficient methods of doing this. 

This code simply creates an array of Booleans out of your input data, then cuts off the most significant 3 bits of all of the integers (using array subset), then resizes the array to concatenate each 5-bit snippet into a 10-bit number.  Then converts those 10-bit arrays into integers.

Cheers,


Message Edited by Spex on 11-13-2007 02:16 PM

Message Edited by Spex on 11-13-2007 02:18 PM
Spex
National Instruments

To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be has a 2x safety factor...
0 Kudos
Message 2 of 22
(4,725 Views)
The boolean operation do a bitwise operation on integers, so you NEVER want to see any "green" in the code. Going via an array of booleans is orders of magnitude less efficient.
 
There are many ways to do all this, for example the following two code examples are a possibility. The top assumes that you have a 2 byte string containing one value. The bottom assumes that you have a long string and you want to get an array of U16 out of it.
 
Modify as needed. You could even add a validity check to see if the extra 6 bits match the expected pattern. 😉
 
 

(Of course the blue diagram constants on the left are U16 formatted in binary and padded with zeroes for clarity)

Message Edited by altenbach on 11-13-2007 02:55 PM
Message 3 of 22
(4,698 Views)

Thanks for both your replies.

 

Both of your solution work fine.

 

Before I start I should first say that I made a mistake when decalring the data type format. The correct is: d1-d2-d3-d4-d5-d6-d7-d8-d9-d10-0-0-0-0-0-0.

 

First to answer Spex’s question on coding the data differently:

 

I had been coding the data exactly as you suggested; however, I have changed the way of doing this for a number for reasons.

 

  1. I would like to know which byte represents what part of the 2-byte data stream. I would thus know that bytes that start with 000 represent MSb and Bytes that start with 100 represent LSB.
  2. I would like to transmit data resultant from a totally different process with in the PIC. Thus a need to clearly distinguish the two different ‘variable data streams’ is needed (e.g. bytes that start with 001/010 represent MSB and LSB respectively of a DC value).

 

However, know I am interested in adding the validity check to verify and distinguish between the two data stream.

 

The function I am looking to implement would require I compare only the first 3 bits of every word (e.g. a1-a2-a3-x-x-x-x-x). Then, I would load the two 5 LSB into an array as per your examples.

 

The attached example seems to work (in LV 8.0). I was just wondering whether there is a better solution to the problem (more efficient, simpler, etc…)?

 

Regards

Alex

0 Kudos
Message 4 of 22
(4,646 Views)
There is no reason for your sequence structure, it makes no difference. Also, you don't need to operate on the entire array of you are only interested in the first value. Why not cast to a U16 directly? Alternatively, if you want to operate on an array, placee the inner code in a loop.
 
To compare bit patterns, you don't need to shift the data, just compare with the correctly shifted value instead.
 
Here's a quick suggestion that might give you some ideas.
 
What you probably want to do to is go back and clip the first char from the input array if the framing is not right. (Not shown)


Message Edited by altenbach on 11-16-2007 12:22 PM
0 Kudos
Message 5 of 22
(4,635 Views)
Sorry, I was a bit too quick with my answer and there is of course a bug. To match the pattern in the 6 extra bits you need of course do as follows:
 
 
(in the old version it would ignore about half the bits...:()


Message Edited by altenbach on 11-16-2007 01:57 PM
0 Kudos
Message 6 of 22
(4,617 Views)

Thanks for your reply altenbach.

You are 100% right that the use of the sequence structure was pointless.

I should have also combined the MSB and LSB checking to just one case structure, as you point out.

You suggest: "I clip the first char from thethe input array if the framing is not right."

Would you be as kind as to ellaborate on this? How would I clip one char if the pattern does not much?

Regards

Alex  

0 Kudos
Message 7 of 22
(4,578 Views)


bogiasac wrote:

You suggest: "I clip the first char from thethe input array if the framing is not right."

Would you be as kind as to ellaborate on this? How would I clip one char if the pattern does not much?


Let's ssume you have a long string, alternating between MSB and LSB. If we get them pairware and process as above, and the pattern does not match, it means that the original string starts with the wrong byte. If you would take the substring starting with element 1 (instead of zero) before processing, the framing for the rest of the data should be correct.
0 Kudos
Message 8 of 22
(4,564 Views)

I am assuming you are referring to the String Subset VI.

 

By removing element one, I understand that I would have to 9 string characters (8 characters + end of line).

 

Please remember that the correct data type format is: d1-d2-d3-d4-d5-d6-d7-d8-d9-d10-0-0-0-0-0-0.

 

Also I have changed the values that represent MSB and LSB. Now 000 represent MSB and the bytes that start with 100 represent LSB. This was simply done so that only one bit changes at a time.

 

However, I am not getting any results. I have attached the modified VI.

 

I would be grateful if you could advise me on it.

 

Regards

Alex

0 Kudos
Message 9 of 22
(4,547 Views)


bogiasac wrote:

I am assuming you are referring to the String Subset VI.

 

By removing element one, I understand that I would have to 9 string characters (8 characters + end of line).

 

Please remember that the correct data type format is: d1-d2-d3-d4-d5-d6-d7-d8-d9-d10-0-0-0-0-0-0.

 

Also I have changed the values that represent MSB and LSB. Now 000 represent MSB and the bytes that start with 100 represent LSB. This was simply done so that only one bit changes at a time.


Your program makes no sense, for example the first case structure depends on the boolean data from the previous run comparison!
  1. How long is your string?
  2. What are the delimiters?
  3. How many U16 patterns (MSB+LSB) do you have.
  4. What output do you want? (Array of U16 for example)

OK, put a typcal string into your control and make it the default, save the VI. Then attach it again. Let's see what you have. 🙂

 
0 Kudos
Message 10 of 22
(4,536 Views)