06-30-2021 12:57 PM
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.
Solved! Go to Solution.
06-30-2021 02:11 PM
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.
06-30-2021 02:43 PM - edited 06-30-2021 02:53 PM
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,
PD: And yes, you would need to have access to the raw data
06-30-2021 04:44 PM
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!!
06-30-2021 07:27 PM
@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,
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.
06-30-2021 09:51 PM
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!
07-01-2021 05:54 AM
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.
07-01-2021 06:47 AM
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.
07-01-2021 12:23 PM
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 🙂
07-01-2021 12:31 PM
@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.