LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create control for 12bit integer.

Solved!
Go to solution

 

Hi

i have attached sample code and screenshot.first i configured each control for how much maximum bit i want to write.again i converted that decimal value into hexadecimal integer string for each control.again all bit i combined to make single hexadecimal frame(this should be 29 bit).now i want to pass these string in to U-32 bit indicator.but U-32 bit indicator not showing exact same value  like frame.some MSB bit is missing.so please tell me where is the fault.

Download All
0 Kudos
Message 11 of 17
(1,455 Views)
Solution
Accepted by Risuraj

You are making mistakes on how you are merging numbers into hexadecimal digits.

 

Your first 12 bits you are converting into 3 hexadecimal characters.  That is fine since hex character can handle 4 bits.

Then for bits 12 and 13, you are converting the bits to a hex character.  which means they are either 0 or 1.  So you are throwing off all data and the place values.

 

It is almost like saying the number 3 consists of 3 1's and thus writing it as 111.

 

What you need to do is use the bit shifting functions in the numeric data manipulation palette and using the AND function to combine the individual pieces into a single 32 bit value.  You shouldn't be playing with string functions because it just doesn't work the way you are trying to force it to work.

0 Kudos
Message 12 of 17
(1,447 Views)

Hi rishijha,

 

why don't you follow my suggestions - and why did it take so long to provide an example?

check.png

(You could also achieve the same as RavensFan suggested: using AND, multiply and add functions. This is basic bit stuffing!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 13 of 17
(1,446 Views)

Hi,

Your first 12 bits you are converting into 3 hexadecimal characters. That is fine since hex character can handle 4 bits.

so if my number is combination of 4bit 8bit and 12bit like that then i can use same what i have followed programming.

What you need to do is use the bit shifting functions in the numeric data manipulation palette and using the AND function to combine the individual pieces into a single 32 bit

can u share some example??

0 Kudos
Message 14 of 17
(1,429 Views)
Solution
Accepted by Risuraj

@Risuraj wrote:

What you need to do is use the bit shifting functions in the numeric data manipulation palette and using the AND function to combine the individual pieces into a single 32 bit

can u share some example??


Well, you would mask with AND (In case there are stray bits outside the valid range), shift accordingly, and merge with OR.

 

Here is a simple example, see if it makes sense (assuming the input is an array, but you can always build one if needed ;)):

 

MergeBits.png

0 Kudos
Message 15 of 17
(1,424 Views)

The above solution is the most generic and can be adapted more easily to new scenarios because only one simple array of counts needs to be changed. If performance is absolutely essential, you can of course pre-compute the masks and shifts (e.g. using the above code ;)) and do as follows:

 

MergeBitsLUT.png

0 Kudos
Message 16 of 17
(1,397 Views)

And if you can somehow guarantee that the input is clean and there are no stray bits outside the valid range for each input value, you can even omit the masking. Masking was just for safety, but always a good idea. 😄

 

MergeBitsLUTsimple.png

0 Kudos
Message 17 of 17
(1,394 Views)