11-18-2016 02:18 PM
I am using a Matlab script to control a PCIe-6321. I am trying to simultaneously collect data on two analog input channels while sending a signal with a digital output signal. I cannot get past this error and I haven't found any documentation on it. The weirdest part is that I'm not using an analog output! The last valid output is always a little less than half of what it should be. For example, if the output signal is 1e6x1, then the last valid output scan number is 498552. Here's the code:
s = daq.createSession('ni'); Dch = addDigitalChannel(s,'Dev1','Port0/Line0','OutputOnly'); Ach = addAnalogInputChannel(s,'Dev1',0:1,'Voltage'); Ach(2).TerminalConfig = 'SingleEnded'; Ach(2).Range = [-5 5]; s.Rate = 250000/length(Ach); ActualRate = get(s,'Rate'); L = 2; % number of seconds of each voltage pulse TotalTime = 8; % total output signal length in seconds n = TotalTime/L/2; % number of times to repeat a pair of pulses tempOutputSignal = [5*ones(1,L*ActualRate) zeros(1,L*ActualRate)]; OutputSignal = repmat(tempOutputSignal,1,n)'; OTime = linspace(0,TotalTime,length(OutputSignal)); figure, plot(OTime,OutputSignal); s.queueOutputData(OutputSignal); duration = s.DurationInSeconds; [data,time] = s.startForeground;
11-21-2016 04:11 PM
AnotherDan,
Is this a Matlab error or a hardware error? Do you know where the error occurs in your code? Does it have an associated error number?
If you could attach a screenshot of the error, that would be extremely helpful!
Thanks,
Hannah
Applications Engineering
National Instruments
11-21-2016 07:15 PM
I'm inclined to think it's a hardware error as it does not reference a line in the code as Matlab errors typically do. Sorry I can't provide a screenshot right now, but the entire error reads, "Analog Output underflow event: the last valid scan number was [a number that is a little less than the length of the output signal]".
11-22-2016 04:04 PM
AnotherDan,
An underflow error is due to the output task not having enough samples being written to it to ouput. It is puzzling that you are getting this error when you do not have an analog output.
Does the code run without the error if you do not configure any output tasks? If you only have your input tasks, does the code work? If this is the case, I believe the issue is occuring due to the configuration of the digital output.
Regards,
Hannah
11-22-2016 06:56 PM
Yes, the code worked previously with just analog inputs recording and I have only recently tried to add the digital output. I have not tried different length signals for the digital output, but my understanding of running analog inputs and digital outputs at the same time is that the output length sets the length of the recording. If this is the case, then I don't see how there can be an error due to the output not having enough samples written to it. What do you mean that the issue may be due to the configuration of the digital output?
11-23-2016 12:04 PM
AnotherDan,
The reason that I suggest it is an issue with the digital output channel configuration is that you are getting an analog output error even though you do not have an analog output. That would suggest that the code is configuring the output task incorrectly.
Can you create a digital output task in NI MAX and see if you get the same error? That would help to eliminate hardware as the issue.
Regards,
Hannah
11-28-2016 12:56 PM
I'm not really familiar with NIMAX, so I don't think I did this right. I followed these instructions, https://www.ni.com/getting-started/set-up-hardware/data-acquisition/digital-output, except I didn't actually connect to the DO port.
Similarly (perhaps I should have mentioned this), I did not have the device to which the DO signal would be going to connected when testing in Matlab. I figured that it doesn't really know whether or not it's connected and I didn't want to undo my current set up before debugging the code for the new set up.
One difference that strikes me between the instructions linked above and what I was doing in Matlab is that I was generating the DO in Matlab while NIMAX expects you to connect the DO to a digital signal. There appears to be an option to create the signal in NIMAX in steps 12 and 13 of the link, however, there is no "Properties" option for me when I right-click the device name (even though the example uses the same exact device!).
Could any of these details be significant?
11-29-2016 01:26 PM
You should be able to run a test panel on the device by selecting your device and then clicking on Test Panels on the toolbar. You should then have the option to run a Digital I/O test panel. You can set the ports so that they are all output, and change whether or not they are producing a high or low signal. If this does not cause the overwrite error, then it is most likely an issue with how you are configuring the output task within your code.
It asks you to connect the output to a digital signal, as the task is not going to create a digital signal to be output. Steps 12 and 13 refer to Power Up States, which should not be necessary for configuring your task. They can be accessed by right clicking and selecting the Configure option. You should be able to use a test panel instead of a task to test the digital output, as we just want to see if you can write to a digital channel.
If that works, I suggest going to the MATLAB forums at the following website, as we do not support the DAQmx functionality when used with The MathWorks, Inc. MATLAB ® software. Their forums may have a better idea of whether or not your code is configured correctly for a digital output task.
Regards,
Hannah
MATLAB® and Simulink® are registered trademarks of The MathWorks, Inc.
12-01-2016 10:33 AM
I ran the test panel as instructed and got no errors (it doesn't really say anything, but I assume that's a good sign). I've already posted on the Matlab forums (http://www.mathworks.com/matlabcentral/answers/312945-error-analog-output-underflow-event), but, unfortunately, no one has replied. Thanks for all the help so far. I'll keep trying and post an update if I figure it out.
12-22-2016 03:34 PM - edited 12-22-2016 04:02 PM
Figured it out, but I don't really know what of the many things I tried explains this error. I changed the circuit, which required a change in script.