LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

9-bit Signed Temperature

Solved!
Go to solution

Hi,

 

I tried to do a 9-bit 2's complement to determine the signed bit. I wrote in text-based, and it was work fine; however, I tried to convert LabVIEW. It seem that the digital thermometer is not taking a negative temperature. Could anybody help me look through this code? Here is the text-based code.

 

if ((tempdata & 256) == 256

   tempdata = ((((tempdata & 255) ^ 255) + 1) * -1);

else

   tempdata;

 

When I used the "Read Field" module to read a 16-bit temperature data, but I only care bit 7-15. However, the "Read Field" module takes care extracting the data into 9-bit. The data that I read from the "Read Field" module is returned to numeric U32. So I used the returned data determine if the MSB is equal to one.

Download All
0 Kudos
Message 1 of 7
(2,889 Views)

I don't understand the ^255 within your text based code.

 

However the AND 255 makes sense to get the 8 bits.  However you aren't doing that in your LabVIEW code.  The Number to Boolean is going to give you a 16-element boolean array (assuming the blue wire coming from the read subVI is 16 bit.)  And you are never masking off those 8 bits.  I'm not so sure you even need to do any conversions from number to boolean array and back again.

0 Kudos
Message 2 of 7
(2,884 Views)

Hi,

 

Thank you for your quick input. I also confused myself. Maybe I should write in this sequence.

 

1. The module "Read Field" will read the 16 bit temperature data from a device, returned to the output as U32 data type. The module automatically takes care extracting the bit D15-D7.

2. So I used the unsigned 32 bit decimal number to determine the MSB bit (I'm not sure if I do need to convert back to binary).

3. Do a 2's complement mathematical operation to get the negative sign.

4. Multiply by 0.5C because the device temp (C) is LSB = 0.5C.

 

I have attached the file. Please advise if this is correct. I checked by entering the number. Would you please show me how to implement two complement in LabVIEW. Please help! Thanks.

0 Kudos
Message 3 of 7
(2,850 Views)

Should I use the FXP?

0 Kudos
Message 4 of 7
(2,844 Views)
Solution
Accepted by topic author caahsc

When you are doing a bit operation, you shouldn't forget to verify position still. Your case statement with "1" isn't valid. It needs to be "256".

 

9bit signed.png

 

This should be the result you're looking for.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

0 Kudos
Message 5 of 7
(2,831 Views)

Hi bsvare,

 

Indeed, that's what I am looking for. Thank you so much for your help.

0 Kudos
Message 6 of 7
(2,809 Views)

Perhaps it's simpler to use the functions built-in for this. (See Numeric->Fixed-point palette)

 

(I screenshotted the properties dialog setup for the cast and added it to the BD for illustration only.)

Convert Integer to 9.8 signed FXP

 

Best regards,

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
0 Kudos
Message 7 of 7
(2,777 Views)