Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

PRADEEP27

Member

02-13-2014 02:35 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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.

ongeelim

Member

02-13-2014 02:42 AM - edited 02-13-2014 03:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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.

Ee Lim

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~~

altenbach

Knight of NI

02-13-2014 03:03 AM - edited 02-13-2014 03:05 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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.)

ongeelim

Member

02-13-2014 03:29 AM - edited 02-13-2014 03:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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

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~~

GerdW

Knight of NI

02-13-2014 03:39 AM - edited 02-13-2014 03:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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…

ongeelim

Member

02-13-2014 03:48 AM - edited 02-13-2014 03:51 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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

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~~

02-13-2014 04:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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.

GerdW

Knight of NI

02-13-2014 06:22 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

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…

Omar_II

Active Participant

02-13-2014 08:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator