From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send 12 bit on serial port

Hello
        I was working on receiving 8 bit from an ADC using the receiving  part of this program and it worked fine ,now my goal is to receive data from an 12 bit ADC.Now I have two quetions:

1)    I tried to change the data bit value to 6 in both visa write and read but I received the sine signal out of shape ,when I tried to put 6 data bit in the visa write add 8 in the read I received the right signal please if any one can explain why?.

2)
    I want to use the receive loop to receive a signal from an 12 bit ADC, but the serial port only receives 8 bit max so if I divided the 12 bits into two 6 bits and send them how can I rejoin them after the visa read.

thank you


0 Kudos
Message 1 of 12
(6,562 Views)
The resolution of ADC is something else as Data Bits in serial communication. Smiley Very Happy
0 Kudos
Message 2 of 12
(6,556 Views)
In serial communication you read/write bytes, not bits. Thus, in order to read 12 bits you need to read 2 bytes. Your use of the VISA Set I/O Buffer Size function doesn't make much sense, though I suspect it's due to this fundamental misunderstanding.

You may want to peruse this KB article: Serial Communication Overview.
0 Kudos
Message 3 of 12
(6,538 Views)

To send 12 bits, just use two 8bits (bytes).

From the second byte, use only the 4 least significant bits, and ignore the rest

0 Kudos
Message 4 of 12
(6,531 Views)
To keep track of which byte contains the high order bits and which one has the low order bits, split the 12 bit data into two bit groups. Send these as the 6 least significant bits in a byte. Make the most significant bit a 0 for the low order byte and a 1 for the high order byte.

Example: Let the data bits be d12, d11, d10, d9, d8, d7, d6, d5, d4, d3, d2, d1. Then the low order byte would be 0,0,d6,d5,d4,d3,d2,d1 and the high order byte would be 1,0,d12,d11,d10,d9,d8,d7. You need to decide which is sent first. If the receiver gets out of synchronization, it can discard one byte to resynchronize.

Lynn
0 Kudos
Message 5 of 12
(6,524 Views)

Thank you all for your replies


        Form what I understand about serial port that it can work on 4 modes (5 bit, 6 bit, 7 bit or 8 bit) so wouldn’t be easier to use the 6 bit mode to transfer 12 bit instead of using 8 bit than try to detect and remove the 4 extra bits.

        So my question is how to rejoin the 6 bits and make labview understand it as 12 bits, or in case of 8 bits how to remove (ignore) the extra bits than rejoin the bits left.

         For example if the binary number is 111111000000 than I divide it into two 6 bits it will be 111111 and 000000 which are two different points so how rejoin them and make them one point again.


        My last question is how labview deals with strings when plotting them on a graph. Does it read the whole string and plot it because ;than I think their will be no problem or it divide it into (8,16 or 32 bits) and in that case it will be a problem to make it understand 12 bits.



Thank you all for your patience

0 Kudos
Message 6 of 12
(6,495 Views)
When you read in from the serial port, even if you are only sending/receiving 6 data bits, the result from the VISA read will still be a string where each character will be the ASCII value of the 6 bit portion of the character set.  (ASCII 0 to 63).  Once you've determined which is the high byte and which is the low byte, you will need to convert the character to a U8.  Then multiply the high byte by 64 (2^6) and add the low byte.  There are probably better ways to do this programmatically using Join numbers and bit shifts and rotates, but I'll leave it up to others to suggest that.
 


ziad h. wrote:

 

        My last question is how labview deals with strings when plotting them on a graph. Does it read the whole string and plot it because ;than I think their will be no problem or it divide it into (8,16 or 32 bits) and in that case it will be a problem to make it understand 12 bits.



This question makes no sense.  You can't plot "strings" to a graph.Smiley Surprised
0 Kudos
Message 7 of 12
(6,492 Views)

I was working on sending the 12 bit by dividing it into two bytes for example 111111000000 will be 00001111 & 11000000 in this way if I read 16 bit the value won’t change. I tried to rejoin the bits in labview using the type cast after the string then U8 then index array then join numbers, but I couldn’t plot the signal on a graph I think it’s because I don’t have an array of points to plot just one point.

So if that’s the problem can any body tell me how to put the points in a new array?

            I attached the VI with the massage. The problem is at the receiving loop.


Thank you
0 Kudos
Message 8 of 12
(6,467 Views)
Try a Waveform Chart.  It will allow you to plot a point at a time, and it also maintains a history of previously plotted points.
 
For a Waveform Graph, yes you would need to build an array.  Look at the Build Array function on the array palette.  Set it for concatenate inputs.  Use a shift register to maintain the array from one iteration to the next.


Message Edited by Ravens Fan on 05-31-2008 01:32 PM
0 Kudos
Message 9 of 12
(6,460 Views)
Thank you  Ravens Fan


    I  used your idea on the receive part and it worked fine but it has two problems:

1) when  I use the waveform graph  it keeps  increasing the X scale infinitely.
2) when using the waveform chart and set the chart history to 100 it work fine at first but it goes out of shape after a while.

I think that's all due to the n dimention array is there a way to make a 100 dimention array in a way that new elements erase old ones.

Another thing I wanted to be sure I understand it right, on the sending loop I should set the “digital waveform to binary” to U16 so that at the receiving part the chart (or graph) will read it as U32 ,but shouldn’t the receiving signal be different than the sent signal; since different points.

I attached the new VI.


Thank you
0 Kudos
Message 10 of 12
(6,422 Views)