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: 

How do I set the range for USB-6009 using DAQmxSetAIRngLow/High?

Hello,
 
I have recently upgraded my software to DAQmx 7.50. I am using a USB-6009 and programming my software in C++.
 
I am trying to make sure that my sensor voltages are comming with the appropriate resolution i.e. that the entire voltage swing is being quantized with the 14-bits. I would like to set this voltage range on the USB-6009 unit, but I am having problems doing so for my differential inputs.
 
I use AICreateVoltageChannel to create the channel, and set my min and max values to -2.5 and 2.5 respectively. However, I am still unsure of the actual resolution comming out. When I run DAQmxGetMax (or Min) they spit out 1235716...same goes for DAQmxGetAIRngLow (or High). This is the same regardless if I call the SETAiRngLow (or High)...doesn't seem like the value changes.
 
Anyone have experience with setting the range in C++? I was offered a LabView solution, but this would not work within my framework...
 
Thanks for the help!
0 Kudos
Message 1 of 8
(3,267 Views)
In the other thread, I posted this:

If the latter, I would guess that an error occurred and that number is whatever was in that variable by chance. If it's an error code, you've got other troubles. That's not a standard DAQmx error code that I recognize.

In any case, as was pointed out earlier, for RSE channels, the only choice is a range of +-10 V (gain of 1). If you use differential inputs, you have several other choices. It seems possible (but not likely) that the driver isn't doing anything because there are no choices.

How about posting code so that we can inspect it and try to see what might be going on?
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
Message 2 of 8
(3,251 Views)

Hello ElectricNathan,

You can set the min and max values therefore setting the range by using the AICreateVoltageChannel function.  Then, you can call DAQmxGetAIMax or Min to verify what the values have been set to.  When I use the Create Channel function and then get the values I have just set, they are what I expect. 

To do this, I just modified an existing example that installed with the NI-DAQmx driver, you can find examples at:  C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In

The configuration function calls I used are:

DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-2.5,2.5,DAQmx_Val_Volts,"");

DAQmxGetAIMax(taskHandle,"Dev1/ai0",&max);

Notice from the NI-DAQmx C Reference Help File that "max" is a float64. 

Please let me know if this does not clear up the problem for you.

Thanks!

Laura

 

Message 3 of 8
(3,249 Views)
Thanks Laura and John for your replies.


John: Here is a code snippet:

float64 stuff;

DAQmxErrChk (DAQmxCreateAIVoltageChan(task2,"Dev1/ai0","input1",DAQmx_Val_Diff,-2.5,2.5,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(task2,"Dev2/ai2","",DAQmx_Val_RSE,-10,10,DAQmx_Val_Volts,NULL));

DAQmxErrChk (DAQmxGetAIMax(task2,"input1", stuff));
printf("\nThe max for Dev1 is: %d",stuff);

DAQmxErrChk (DAQmxStartTask(task2));

Then I do some reading and stop the task. The problem is that the 'printf' line always gives me: "The max for Dev1 is: 1235716"

So how am I supposed to know the actual max and min limits the DAQ is using and most importantly: what's my range??

The fact that there are single ended measurements happening simultaneously during differential acquisition shouldn't matter (I think) because I would assume that the RSE measurements would be -/+10V and the differential inputs would be whatever I set them to (if I knew how and could verify this).

One other thing to note is that it doesn't seem to matter where I stick the GetAIMax call, after or before the StartTask, it always returns the same thing. I also tried SetAIMax with the same results.
0 Kudos
Message 4 of 8
(3,240 Views)
Ah, ha!

printf("\nThe max for Dev1 is: %d",stuff);

stuff is a float64, but you're printing it with an integer format. Try this:

printf("\nThe max for Dev1 is: %g",stuff);
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
Message 5 of 8
(3,235 Views)
Hi John,

Oops! You're right...however: even with %g, the string that it prints out is:

"The max for Dev1 is: 6.10525e-318".

Still not getting the correct max....I tried a SetAIMax prior to the GetAIMax as well with the same result.

EDIT: Still another oops, should have been %f...with that I get: "The max for Dev1 is: 0.000000"

Any suggestions?


Message Edited by ElectricNathan on 09-09-2005 11:06 AM

0 Kudos
Message 6 of 8
(3,226 Views)
Wow, what a stupid mistake! I was reading my 'stuff' variable not remembering that it is an array! As soon as I checked stuff[0] I got all the answers I needed. The Get and Set work for all of Min, Max, High and Low. So, I'm assuming that since I only need to look after the High and Low, I am ready to use this code!


Thanks again for all the help. My apologies for the amount of time spent looking for such a simple mistake!

(Of course %g (short decimal floating point) works!)

Message Edited by ElectricNathan on 09-09-2005 11:17 AM

0 Kudos
Message 7 of 8
(3,219 Views)
Here's another one, that the compiler should have picked up:

DAQmxErrChk (DAQmxGetAIMax(task2,"input1", stuff));

The third parameter should be a pointer to stuff:

DAQmxErrChk (DAQmxGetAIMax(task2,"input1", &stuff));

I tried the same call in my own application with my own USB-6008, and the calls worked as expected.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
Message 8 of 8
(3,213 Views)