11-04-2019 02:58 PM
Hi all, maybe someone has an answer to this.
I inherited a test setup, equipped with a USB-6212, and have been trying to get it to work with C# instead of the previous LabView program, for sustainability's sake.
Things have been going well, except as I'm reading my analog inputs, the value suddenly drops to -0.001V during operation, then rebounds within a couple samples (typical value ~1V). I've been looking through several forums, trying to find an explanation but nothing has come up. So far, I've tried connecting all other AI interfaces to ground to reduce noise, varying the sampling rates, and checking the results in MAX.
I have seen something like this before with other NI equipment and LabView code, is this non-continuous measurement behavior just inherent to NI gear, and I need to employ more averaging and zero rejection?
Here's my initialization code:
try { for (i = 0; i < _seqChanToRead; i++) { _anaReader.AIChannels.CreateVoltageChannel(Datalogger.AIPhysicalChannels[i], "", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts); } _anaReader.Timing.ConfigureSampleClock("", 6, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 2); _anaReader.Control(TaskAction.Verify); } catch (Exception ex) { string message = ex.ToString(); string caption = "Initialization Error"; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } _analogIn = new AnalogMultiChannelReader(_anaReader.Stream); _analogIn.BeginReadSingleSample(RecalcAnalog, null); } private void RecalcAnalog(IAsyncResult ar) { _interpret = _analogIn.EndReadSingleSample(ar); MeasureCurrent = _interpret[0]; MeasureVoltage = _interpret[1]; _analogIn.BeginReadSingleSample(RecalcAnalog, null); }
11-05-2019 10:00 AM
I was able to mitigate the issue, by averaging good reads and omitting bad reads. Not sure if this is the best way to handle this though. I'd prefer being able to 100% trust hardware reads, but I fear its a side effect of having one physical DAC multiplexed to several terminals inside the DAQ.
Since I'm reading a 4-20mA signal translated to a 1-5V signal, I am able to just lop off all values of less than 0.01V. I also switched to a Multisample Reader, so as to get a better average and upped the Timing frequency to 100s/sec, reading continuously with a buffer size of 1000.
private void RecalcAnalog(IAsyncResult ar) { int[] counter = { 0, 0, 0 }; double[] holder = { 0, 0, 0 }; double[,] _interpret = _analogIn.EndReadMultiSample(ar); for (int i = 0; i < _samplesRead; i++) { if (_interpret[0, i] > 0.01) { counter[0] += 1; holder[0] += _interpret[0, i]; } if (_interpret[1, i] > 0.01) { counter[1] += 1; holder[1] += _interpret[1, i]; } if (_interpret[2, i] > 0.01) { counter[2] += 1; holder[2] += _interpret[2, i]; } } MeasureCurrent = (counter[0] == 0) ? MeasureCurrent : holder[0] / counter[0]; MeasureVoltage = (counter[1] == 0) ? MeasureVoltage : holder[1] / counter[1]; MeasureReturn = (counter[2] == 0) ? MeasureReturn : holder[2] / counter[2]; _analogIn.BeginReadMultiSample(_samplesRead, RecalcAnalog, null); }