From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

logical shift not working?

Solved!
Go to solution

Hi,

I am trying to convert 16-bit data to 12-bit data by using logical bit shift function. But it turns out that logical bit shift output just produces 0. I can't figure out why. can someone help?? Thanks.

I am using USB-6211.

0 Kudos
Message 1 of 10
(1,779 Views)

Your problem is you are dealing with the actual voltage measurement instead of the raw ADC value.  I'm not sure if you can get the raw ADC value with the DAQ Assistant.  I know there is an option for that with the actual DAQmx API.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(1,749 Views)

Hi Joeb,

 

After analyzing the Logical Shift function I have come to conclude that it displaces the number given any number of bits (y) rather than decreasing the resolution of the representation of the data, so in your case this wouldn't seem like the appropriate approach to me. 

 

Converting 16 bit data to 12 bit would require to disable (or set as always false) the 4 least significant bits, I think this attached approach would be a better fit. Let me know if this is helpful to your application.

 

Regards,

Boolean array approach.png

 

PD: And yes, you would need to have access to the raw data

Message 3 of 10
(1,739 Views)

Hi Crossulz and AlejandroJ,

Thanks for the reply. I am new to this LabView and I have been struggling with the DAQmx API...since I am not using DAQAssistant anymore. 

As an alternate, I created  a DAQassistant and configured it. Then I converted it to NI-DAQ Code using "Generate NI-DAQ Code". I have attached my VI. 

However, I am unable to pass the 16 bit raw data to "numeric to boolean array" function since it says that the source is 16 bit integer and sink is 32 bit integer. Could you provide a solution for this? 

Thanks!! 

0 Kudos
Message 4 of 10
(1,720 Views)

@AlexJ. wrote:

Converting 16 bit data to 12 bit would require to disable (or set as always false) the 4 least significant bits, I think this attached approach would be a better fit. Let me know if this is helpful to your application.

 

Regards,

Boolean array approach.png

 

PD: And yes, you would need to have access to the raw data


Rube!  All you need to do is AND the I16 with 0xFFF0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 10
(1,709 Views)
Solution
Accepted by topic author averagejoeb

Thank you so much @crossrulz and @Santo_13! I tried both ways and finally was able to make it work using logical shift.

I was able to convert the data (raw data) to 12 bit by using logical shift. But I am not getting expected output. I am not sure if this is related to logical shift or something else.

I set the input range as 3.3 V (max) and 0V (min), with terminal configuration as RSE. I am giving 3.3V input to a1 channel.

When I am selecting the polymorphic selector for DAQmxRead as "Analog 1D DBL 1Chan NSamp", I receive the output as 3.3V as expected (please refer to "analog.png" image). But since I need raw data, I change the polymorphic selector to "Raw 1D U16". And when I change it to raw data, I get 1V equivalent values as shown in both the waveforms (in front panel) for 16 bit and 12 bit (please refer to raw data.png image).

In "12 bit" waveform, instead of getting output at ~1200, I should get the values as 4096 and in "16 bit" waveform, instead of ~20000, I should get the output at 65536, since I am giving 3.3 V, which is max. Can someone please help? I feel like I am doing a stupid mistake here. I have attached my project too (you might have to download both vi...not sure how they are related but one won't open without another). Thanks! 

Download All
0 Kudos
Message 6 of 10
(1,697 Views)

For your USB-6211, the actual range you will get with a max of 3.3V is the –5 V to 5 V range.  So your multiplier should be 10/65535 for 16-bit and 10/4096 for 12-bit (5V - -5V = 10V).  So using your 20000 value, I get (20000)*10/(65535) = 3.0517578125V.  1200*10/4096 = 2.9296875V.  This looks about right to me.

 

Though, I'm a little concerned because I'm not sure how this will work with the negative values considering you are getting U16 values.  I would expect to need to subtract an offset as well.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 10
(1,687 Views)

Finally got around to messing around with this.  You will want to have the raw data come out as an array if I16 in order to easily handle negative values.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(1,685 Views)

Thank You so much, I got it now. How -5V to 5V corresponds to 3.3V ....I would have to check that! Since I only have to deal with positive values ...I thnk I don't have to worry about dealing with offset and all 🙂

0 Kudos
Message 9 of 10
(1,661 Views)

@averagejoeb wrote:

Thank You so much, I got it now. How -5V to 5V corresponds to 3.3V ....I would have to check that!


Read the data sheet (there is a link in your other thread).  You will see a list of ~5 ranges that can be used.  The driver will set the range to the smallest that will work for your desired max and min.  In your case, the 3.3V max and 0V min will make the actual range -5V to +5V.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 10 of 10
(1,654 Views)