Skip to content

Commit

Permalink
Changed the WaveGen to save the current analog output values
Browse files Browse the repository at this point in the history
at the beginning of the scan, and to restore them at the end.
This prevents the issue of the ao record values not matching
the actual output voltage at the end of the scan.
  • Loading branch information
MarkRivers committed Nov 6, 2024
1 parent 644b64a commit c317107
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions measCompApp/src/drvMultiFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ class MultiFunction : public asynPortDriver {
int numWaveGenChans_;
int numWaveDigChans_;
int pulseGenRunning_[MAX_PULSE_GEN];
int waveGenSavedOutput[MAX_ANALOG_OUT];
int waveGenRunning_;
int waveDigRunning_;
int startPulseGenerator(int timerNum);
Expand Down Expand Up @@ -1585,6 +1586,8 @@ int MultiFunction::startWaveGen()
firstChan = i;
firstType = waveType;
}
// Save the current value of the analog output so it can be restored at the end of the scan
getIntegerParam(i, analogOutValue_, &waveGenSavedOutput[i]);
// Cannot mix user-defined and internal waveform types, because internal modifies dwell time
// based on frequency
if (((firstType == waveTypeUser) && (waveType != waveTypeUser)) ||
Expand Down Expand Up @@ -1674,14 +1677,34 @@ int MultiFunction::startWaveGen()
int MultiFunction::stopWaveGen()
{
int err;
int range;
int enable;
int status=0;
waveGenRunning_ = 0;
static const char *functionName = "stopWaveGen";

setIntegerParam(waveGenRun_, 0);
ULMutex.lock();
#ifdef _WIN32
err = cbStopBackground(boardNum_, AOFUNCTION);
#else
err = ulAOutScanStop(daqDeviceHandle_);
#endif

// Set the analog outputs back to their value before the scan
for (int i=0; i<numAnalogOut_; i++) {
getIntegerParam(i, waveGenEnable_, &enable);
if (!enable) continue;
getIntegerParam(i, analogOutRange_, &range);
#ifdef _WIN32
status = cbAOut(boardNum_, i, range, waveGenSavedOutput[i]);
#else
Range ulRange;
mapRange(range, &ulRange);
status = ulAOut(daqDeviceHandle_, i, ulRange, AOUT_FF_NOSCALEDATA, (double) waveGenSavedOutput[i]);
#endif
reportError(status, functionName, "calling AOut");
}
ULMutex.unlock();
return err;
}
Expand Down

0 comments on commit c317107

Please sign in to comment.