Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Hex Data to an Analog Form

I am reading Hex data from the serial port a little like this 0FFF0FFF0FFFOFFF0000000000000000 .This is when I alternate between 5V and GND. 0FFF represents 5V and 0000 represents gnd. There will also be intermediate Hex values. My vi converts each Hex value to its corresponding four bit binary ie 0 becomes 0000 F becomes 1111 but I want it to parse the data four bits at a time so first four bits are converted into binary next four bita are converted to binary etc
0 Kudos
Message 1 of 4
(4,156 Views)
I do not see the reason why you would like to do so, but AND your hex value with 0x0f to get the lower nibble and AND it with 0xf0 for the upper one. The latter should be shifted right by 4 positions in order to uese the very same conversion function as with the lower nibble.

Greetings from Germany!

--

Uwe
0 Kudos
Message 2 of 4
(4,154 Views)
Well what am I trying to do is to convert the Hex values to an Analog waveform what is the best way of doing this
0 Kudos
Message 3 of 4
(4,152 Views)
Well, you stated in your first message that a value of 0x0fff is 5V and 0x0000 is 0V. So what you schould do is:
1 Have a VI or independend while or whatever reading bytes at serial port and append it to a variable or shift register or queue or whatever storage place.
2 Find a pair of characters, where the first one is below 16 (0x0?) and the second is > 15 (This assumes your data is somehow distributed in its data range, so that the high nibble of your low byte is >1 most of the time). This synchronises your conersion vi.
If you found such a pair, delete all characters _before_ that pair, than
a remove the next pair of characters,
b unflatten it to a U16,
c re-check synchronity (U16.AND.0xf000 == 0)
d restart with 2, if not sync'd
e else multiply this by 5/4096 - voila!
0 Kudos
Message 4 of 4
(4,146 Views)