LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

i want to send 10 bit ADC from PIC via serial communicaton. i send it separetly 8 bit first then the other 2 bit. how to program in labview to capture those two packet then combine it togother

i want to send 10 bit ADC from PIC mCu via serial communicaton.
 i send it separetly 8 bit first then the other 2 bit (2 bit --> with zero at 6 bit from LSB).



how to program in labview to capture those two packet and then combine it together
so i have 10 bit in lab view

thank you
0 Kudos
Message 1 of 12
(5,940 Views)
You can only read bytes from the serial port. This means you need to read two bytes and then use standard programming to get your 10 bits. How you do it depends on what you're trying to eventually get. Are you trying to get an array of booleans, or an integer value, or a string?
Message 2 of 12
(5,927 Views)
from my mCU ( PIC16f873), i send the data as 2 bytes (16 bits separately). As far as i know, PC will recognize it as strings (showed in ASCII)

What i want to know is how to program the labview to capture the data every 2 bytes (16 bits).
On visa serial of labview, it capture 1 byte(8 bits) as 1 strings and I need to convert it to 2 bytes as 1 strings. then it will be plotted to graph

thanks before







please tell me if you don't understand my english.
sorry, my english is bad
0 Kudos
Message 3 of 12
(5,915 Views)
There is an example that ships with LabVIEW that is called "Basic Serial Write and Read" that shows you how to use the VISA functions to write/read from the serial port. You did not indicate if the two bytes are a response to some command, or whether the PIC is just sending out these 2 bytes on its own. Assuming it's in response to a command you can use the sequence of commands as shown in the example to read two bytes. The "Bytes at Port" is used to tell the VISA Read how many bytes to read. In your case you can probably just wire a constant of "2" to the VISA Read function. This means you'll get a string that consists of two bytes.

Now that you have your two bytes, you just need a number. If I understood you correctly, all that you should need to do is to wire the string that you got from the VISA Read into the Type Cast function to type cast the string into an I16 as shown below:


Message Edited by smercurio_fc on 05-01-2007 01:57 PM

Message 4 of 12
(5,911 Views)
Close, but now quite. You need to specify to the VISA Read how many bytes to read, not how many bits. Thus, the input would be 2, not 16. It's also not clear why you're trying to use the "String to Byte Array". The Type Cast will give you a number based on what data type you wired. You're basically telling it how to interpret the string. In this case we're telling it to interpret the string a 16-bit value, so we'll get a 16-bit integer. I know you said you wanted a 10-bit, but you can't have that. You'll get a 16-bit with 6 bits set to zero. Note: I did not completely understand what you said so we may need to change this slightly, but we want to get the communication and reading collection working first.

Also, since you seem to be setting this in a loop you probably want to monitor this or to collect the data. For that you need a shift register. See attached for a modified version of your attempt. You need to set the datatype to I16 or U16 based on whether the value you get from the PIC is signed or unsigned.


Message Edited by smercurio_fc on 05-01-2007 02:28 PM

Download All
Message 6 of 12
(5,894 Views)
One note about the example I provided: There's no delay in the loop so it runs as fast as possible, which means it will hog all the CPU. In your actual application you will want to put a small delay so that the computer has the opportunity to do other things it needs to do.
Message 7 of 12
(5,890 Views)


@smercurio_fc wrote:
One note about the example I provided: There's no delay in the loop so it runs as fast as possible, which means it will hog all the CPU. In your actual application you will want to put a small delay so that the computer has the opportunity to do other things it needs to do.


I think you are wrong, most likely will the VISA function time out if no bytes are ready!

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 12
(5,879 Views)

Andeh,

I also hope you are appending some sort of start or stop character at the begining or end of the two bytes. If you don't, you're going to have some problems. Without it, you won't know if the first and second bytes read are the low or high order bytes sent.

0 Kudos
Message 9 of 12
(5,877 Views)
Ton, you are correct in your statement, but then I'm not working with a whole lot of information here, so I had to make a ton of assumptions, and that's obvious from the crude nature of my example. One of them was that the PIC was continuously sending out data, or at least the frequency at which it sent out data was high enough not to cause a timeout. This is not an unreasonable assumption, since some meters work this way. A Fluke meter and Tektronic meter I've used in the past worked this way.
0 Kudos
Message 10 of 12
(5,870 Views)