I am experiencing an issue when programmatically building a DAQmx task with custom scales. Under the right circumstances, the DAQmx simulated output is not staying within the confines of my requested max & min of the channel.
My end goal: create a DAQmx task dynamically such that it mimics the existing behavior of a task preconfigured in MAX.
I am attaching a reproducing case of sample code for reference.There are two labled diagram disable structures that I will reference to explain the different situations where the issue occurs.
In MAX, I am using a simulated cDAQ 9178 with an NI 9220 in slot 1.
The program dynamically creates a DAQmx task and adds 4 channels, each with their own custom scale.
The problem comes from the first situation (1.1 & 2.1 enabled). I have set the min of Chnl4 to -51 and the max to 49; however, the output of the DAQmx acquisition shows Chnl4 extending from -175 to about 100. Inspecting the DAQmx channel with a property node, AI max and AI min are 324 and -176, respectively. I have not been able to figure out where these numbers are coming from.
If you disable the first diagram (enable 1.2) such that only chnl4 is enabled, the DAQmx acquisition output will stay within range even though the DAQmx channel property node still claims the max & min are 324 and -176 still. In fact, we will see the same behavior if we simply modify the physical channel of chnl4 to be 'after' the other three channels (change from ai0-> ai4).
Diagram 2.2 uses 'map ranges' custom scales. Enabling 1.1 & 2.2 we see that the DAQmx Channel property node now lists the max & min of chnl4 correctly. Additionally, although the output is still the larger amplitude waveform, it is clipped at -51 & 49. It is my understanding that the programmer is not in control of the frequency/amplitude of a simulated wave so this clipping is fine and expected.
It seems that if I create the channels 'in order' the issue does not present itself. However, the way I am dynamically creating the task, I cannot guarantee the ordering of the channels.
I am aware that the max & min inputs of the create channel VI are post-scaled values.
- Why is the max & min only being taken into account when using a 'map ranges' scale, or if the channels are declared 'in order'?
- Why does the DAQmx Channel property node show different max & mins than configured? And where are these numbers coming from?
Solved! Go to Solution.
You mentioned that creating the channels in order resolves the weird behavior you're seeing. If you add error wires between each Create Channel VI, you'll ensure that each channel is created in order.
Here is some more information about flow control:
Thank you for the response; however, I think you misunderstood what I meant when I was referring to ordering. Dataflow is enforced in my sample program with the task reference wire - the issue is stemming from the order in which I create the channels.
I was referring to the ordering of declaring the channels eg: Mod1/ai1 then Mod1/ai2 then Mod1/ai3 then Mod1/ai4. The issue presents itself when I declare the channels out of 'order': Mod1/ai1 then Mod1/ai2 then Mod1/ai13 then Mod1/ai0.
I cannot guarantee that I will be creating channels for the task in ascending order in relation to the physical channel. The real issue is why the lower and upper bounds on my channel are not being followed - the ordering is simply a strange piece of data I discovered along the way.
If you wanted to control the creation of those channels, you could use a flat sequence structure around each Create Channel VI to ensure that the order the channels are declared is controlled.
Thank you again, but I do understand how to control the data flow of the application.
The issue is that I cannot know the order in which they will be created because I am creating the task dynamically. As I mentioned previously, the ordering is not the focus of the issue. The question is why are my scales/max/min not being followed.
Creating the task dynamically means that I do not have the ordering information beforehand. As I create the channels within my task I retrieve the physical channel, one channel at a time. In my actual application, I have a loop with a 'create channel' inside and the task on the shift register - dynamically adding channels to the task.
Because I don't know all of the physical channels ahead of time I cannot force my program to create the channels in 'order' and am not sure that I should have to.
If there is, in fact, a legitimate reason why I must declare them in order then I can understand that (for example, Delta-sigma modules require that the master be declared first, though I would be receiving an error if this were the case). However, I am not aware of anything like this for the NI 9220.
It looks like the property is using the minimum and maximum of the module instead of the minimum and maximum inputs you are trying to apply to the virtual channel. Since we're looking at linear scaling, that means the equation is y = mx + b, or y = -25(voltage) + 74. The NI 9220 has a range of -10 V to 10 V, and applying this to your scaling results in the -176 and 324 values you are seeing.
This actually is happening with all 4 channels, in that the output of the min/max property node is the minimum and maximum for the full scale of the channel after adjusting for the scaling instead of the inputs you use for the DAQmx Create Virtual Channel.
I don't exactly understand the behavior of the simulated output (it does weird things some times), but I do know that it is expected to output a +/-10 V Sine wave. Your maximum and minimum inputs are not meant to enforce the allowable input range, but are rather meant to help the driver determine what input range to use if the device has multiple ranges. The driver will coerce those values to the appropriate range, but given that the NI 9220 only has one range (+/-10V) it results in the behavior you are seeing.
You can double check me on this by removing the custom scaling from the picture entirely. You'll notice that using a +/-5 V range still results in return values of +/-10 V for the minimum and maximum.
Based on this, I believe you're seeing expected behavior as far as the return values for the minimum and maximum of the channels. I don't know why the simulated waveforms aren't consistent with this, but keep in mind that it is simulated and may not behave the same as an actual device would.
Thanks for the response and clarification. I was misinterpreting the functionality of the max/min inputs of the create channel VI.
Input Limits (Maximum and Minimum Values) - This document explains that the max/min are used to determine which range the DAQ will use (if it has multiple ranges).
I will agree that the simulated data is a little funky, but I'm happy to understand this functionality better now.
I was trying to avoid using the "Map Ranges" scale; however, it looks like I may need to if I want to truly clip out data that is out of my desired range.