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: 

Max/Min values do not seem to stay fixed when using DAQmxSetAIMax() in NIDAQmx

I am using NIDAQmx and C++ for analog input on a PCI-MIO-16E-4.
I am trying to implement an autorange feature and thus need to modify the expected max and min values in the task channel

I set up the task and max/min at +/- 10 volts and take an AI reading. I then find the max and min of my data and modify the Max/Min of the channel but when I query the Max/Min levels they are set back to +/- 10Volts.

Even If I try to modify the levels just after channel creation but before the task is started I do not see a change.

See the following code snippet.

DAQmxErrChk( DAQmxCreateTask("",&this->taskHandle_AI));

//Create Analog Voltage on "Dev1/ai0"
DAQmxErrChk( DAQmxCreateAIVoltageChan(this->taskHandle_AI,"Dev1/ai0","",DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NULL));

double level;
DAQmxErrChk( DAQmxGetAIMax(taskHandle_AI,"Dev1/ai0",&level)); //Max level is +10.0
DAQmxErrChk( DAQmxSetAIMax(taskHandle_AI,"Dev1/ai0",level/2)); //Set Max level to +5.0
DAQmxErrChk( DAQmxGetAIMax(taskHandle_AI,"Dev1/ai0",&level)); //Max level is back at +10.0 ????????


Please help
0 Kudos
Message 1 of 3
(2,686 Views)
Here is what's going on. Anytime you query an attribute through a get fuction, the task is automatically verified by the driver before returning the value. Through the verification process, the driver may coerce certain attributes to reflect the actual values that will be used by the driver. In this case, the driver uses the min/max values to determine which input range the hardware should use. The driver will always pick the smallest range supported in hardware that encompasses the desired range specified by the user. In this case, you initially specified a desired range of +/- 10 volts. When you read back the maximum value, you received a value of 10 as expected. Then you changed the maximum input limit to 5 volts. However, the minimum input limit is still set at -10 volts. Since the desired range is now -10 to +5 volts, the driver still picks the +/-10 volt range to accomodate signals down to -10 volts. The driver also coerces the maximum input limit to +10 volts to indicate that you may receive readings up to 10 volts even though you indicated you only expected to measure up to 5 volts. To achieve a bipolar auto-ranging function, you will need to set both the maximum and minimum values. I hope this helps.
0 Kudos
Message 2 of 3
(2,676 Views)
Thanks RedDog,

It all makes sense now and I've got my code to work. Why couldn't NI give a bit more documentation on their functions????
0 Kudos
Message 3 of 3
(2,658 Views)