LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting 32 bit data into 8 and 25 bits for computing coincidence logic

Hello Everybody.

 

I am working with Single photon counters in my lab. There are two separate TTL pulses that come from two detectors and fed to two channels in Counter that registers the arrival times of two Photons individually. The data is written in unsigned integer 32 bit block, where the first 6 bits will contain channel information (Channel 1 or channel 2), and the next 25 bits will have the arrival time corresponding to each channel. 

 

All I have to do is find the diffrence between the arrival time of the two channels. My Question is how will I make labview to "Read only the first 6 bits" and display channel information and next 25 bits and display the corresponding time information. I saw a VI under data manipulations that breaks int32 into two 16 bits but in my case it is breaking 32 bit into 6 and 25. 

 

Thanks for any help. 

0 Kudos
Message 1 of 9
(5,959 Views)

Hi PRADEEP27,

 

Your question seems a bit confusing as you have only 32-bit number, but you want to split into 6-bit (or 8-bit) number and 25-bit number, in which the total number of bits are 31 bit (or 33 bit). Do you mean 32-bit --> 6-bit and 26-bit OR 8-bit and 24-bit?

 

Anyway, you'll need a few of these functions to make this work:

1) Number to Boolean Array function: This will convert the 32-bit number into 32-bit boolean array.

http://zone.ni.com/reference/en-XX/help/371361K-01/glang/number_to_boolean_array/

2) Split 1D Array function: This will help you to split 32-bit into 6-bit and 26-bit boolean arrays.

http://zone.ni.com/reference/en-XX/help/371361K-01/glang/split_1d_array/

3) Boolean Array to Number function: This will convert back both the 6-bit number into 26-bit boolean arrays to unsigned 32-bit numbers.

http://zone.ni.com/reference/en-XX/help/371361K-01/glang/boolean_array_to_number/

 

Here is the screenshot of the code for your reference.

Capture.PNG

 

Ee Lim



See that button on the left side of this post...

If you feel my post is helpful, all you need is just (at most) 2 seconds to click that button, to show your appreciation. Thank you~~



Message 2 of 9
(5,953 Views)

All you need to do is some bitwise operations. For the first 6 bits, just do a right-shift by 26bits. To get the next 25 bits, do a bitwise AND with a binary number containing 26 1s and right-shift by one.

 

Well, you are not defining one of the bits (6+25=31bits, while you start out with 32bits. In the post title you specify 8 and 25 bits, which is more than 32 bits! So, what is it really?).

 

If you want to drop the last bit, just right-shift the 26 bits by one position. This is the general idea, you can easily look at any selection of bits this way (simply mask with as needed and right-shift).

 

(the long diagram constant is in binary format %032b, the others are in decimal)

 

 

(going via boolean arrays as suggested is significantly less efficient and uses 8x more memory.)

 

 

Message 3 of 9
(5,934 Views)

As what altenbach suggested, going using boolean arrays uses more memory.

I also did a mistake in the screenshot. Before splitting the array, it will look for the index array starting from the least to most significant bits, so place the constant value of 26 instead of 6 as shown in the screenshot (which gives out 26-bit data on the top terminal instead).

 

You can follow altenbach's idea, but if you really want to split the 32-bit to 6-bit and 26-bit (in which the sum of number of bits of both splitting number is exactly 32-bit), there's a shortcut in doing that, where you only need 1 function, which is Quotient & Reminder function.

 

http://zone.ni.com/reference/en-XX/help/371361K-01/glang/quotient_and_remainder/

 

All you need to do is to wire your data to x and binary value of "00000011111111111111111111111111" and the reminder (x-y*floor(x/y)) is your last 26-bit value and the integer quotient (floor(x/y)) will be your 1st 6-bit value.

 

Ee Lim



See that button on the left side of this post...

If you feel my post is helpful, all you need is just (at most) 2 seconds to click that button, to show your appreciation. Thank you~~



0 Kudos
Message 4 of 9
(5,917 Views)

Hi Ee Lim,

 

Altenbachs suggestions is still more efficient!

Simple boolean commands and logical shifts are handled in a processor much faster than "complicated" math like division (as Q&R is a division operation). When you have the FPGA toolkit available you can easily check that by comparing the resources needed for Altenbachs solution and your Q&R approach…

 

I admit that using a single Q&R function on a standard PC will not hurt performance, but even there Altenbach's approach may be faster when it comes to analyzing big data chunks…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(5,906 Views)

Hi GerdW,

 

Thanks for the feedback.

 

You're right about this statement, logical shifts and boolean functions are much faster to handle in processor, particularly with big set of binary data.
Will take that as a note to me.

 

Anyway, its entirely up to thread starter to decide what's the best method for his/her case, in terms of simplicity and performance.

 

Ee Lim



See that button on the left side of this post...

If you feel my post is helpful, all you need is just (at most) 2 seconds to click that button, to show your appreciation. Thank you~~



0 Kudos
Message 6 of 9
(5,895 Views)

Thank you every body for replying quickly, I highly appreciate that. I am very sorry to confuse with the details that I have quoted for my question. I will give precise explanation on how I wish to design my logic. 

 

Time record consists of 32 bits. These 32 bits are again split into three parts:
(1) the time tag  (25 bits)-----arrival time of a photon basically.
(2) the channel (6 bits)
(3) a "special" bit (1 bit)

To process one time tag I need to do the following sequence:
(a) check the special bit ->if this is "1" then check the channel bit
(a.1) ->  if this (Channel bit) is"63" (corresponds to 3F in Hexadecimal) then this record is a an overflow.
(a.2) -> if this is "0" then the record comes from 1st channel and the time tag corresponds to the arrival time of the signal on the 1st channel.
(b) anything else is  2nd channel and the time tag corresponds to the arrival time of the signal on the 2nd channel.

So, what I need to do is to make a loop that reads the these records one by one and processes each time tag. 

 

 I will be so grateful  if you could provide some ideas on how this can be effectively implemented in Labview? I have attached a VI in which I have to make modifications. 

 

Altenbach and Ee lim 's ideas are super helpful. Thank you once again. 

 

0 Kudos
Message 7 of 9
(5,878 Views)

Hi Pradeep,

 


I will give precise explanation on how I wish to design my logic


 

Well, you missed the most important part: which bits are assigned to which data part?

Is this "special bit" the LSB or the MSB or somewhere in between?

Do you have a C code fragment that explains that data structure?

 

Again:

All you have to do is apply some AND and SHIFT functions to your data to get all information you want…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 9
(5,866 Views)

What you need is a bit field data type.

 

Provide the ability to use bit fields in clusters

Omar
0 Kudos
Message 9 of 9
(5,853 Views)