Jump to content
  • 0

Applying AnalogOutConfigure dynamically (fStart=3) for master-slave configured channels in Analog Discovery Studio


hargan123

Question

I am working on a python project using Analog Discovery Studio where I need to change the amplitude of two phase synchronized analog output channels based on a voltage acquired in an Analog input channel. I find that using fStart=3 for applying changes dynamically makes the output channels go to zero. 

 

Attaching a toy example code where the two synchronized output channel amplitudes are changed every 10 ms by a fixed amount. For this example, the two AnalogOut channels were acquired through the two AnalogIn channels. 

 

dwf.FDwfAnalogOutConfigure(hdwf, c_int(-1), c_int(1)) works but there is intermittency in output; there is a delay in setting new amplitudes. 

 

dwf.FDwfAnalogOutConfigure(hdwf, c_int(-1), c_int(3)) makes outputs go to zero rather than apply immediately. 

 

My application is similar to this: Analog Discovery 2 | Support for modulation signal input for resolver testing

 

Is support for modulation using external signal added now?  It would be great if someone could help on this.

master-slave-fStart1.PNG

master-slave-fStart3.PNG

MasterSlaveAnalogOutModulation.py

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hi @hargan123

The following should be used:
FDwfDeviceAutoConfigureSet(hdwf, 0)
....
FDwfAnalogOut*Set ... // set parameters
FDwfAnalogOutConfigure(hdwf, channel, 1) // start
...
FDwfAnalogOut*Set ... // change parameters or set all
FDwfAnalogOutConfigure(hdwf, channel, 3) // apply
...
FDwfAnalogOutConfigure(hdwf, channel, 0) // stop

FDwfDeviceAutoConfigureSet
0 - disabled: Device will be configured when calling FDwf*Configure. It is recommended for complex apps to prevent device configuration with each parameter setting.
1 - enabled (default): Any FDwf*Set will configure the device stopping the respective instrument.
3 - dynamic: Any FDwf*Set will configure the device without stopping the instrument.

FDwf*Configure
0 - stop
1 - start
3 - dynamic, configure without changing the state

Link to comment
Share on other sites

  • 0

@attilaI'm getting some unstable / not repeatable results when using custom analog output on the ADP3250 and wondered if it might be related to these commands *Configure *ConfigureSet which I don't quite understand.  This is the relevant portion of my code ... do I need to be putting some FDwfAnalogOutConfigure(hdwf, 3 or 0 or 1) things in there somewhere?  Where? I don't understand what those commands are doing "stop" "start" "dynamic" ??

Thank you!!

#I don't know what this does but many examples have it:
# 0 = the device will be configured only when calling FDwf?Configure
# dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))

#set up the waveform generator
dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcCustom) #set custom waveform
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(hzFreq)) #set buffer length (repeat rate)
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(drive_amp)) #amplitude in volts
dwf.FDwfAnalogOutRunSet(hdwf, c_int(0), c_double(1.0/hzFreq)) # run for 1 period
dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(1.0/hzFreq)) # wait one pulse time
dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(0), c_int(1)) # repeat 1 times

#Load samples into output buffer
dwf.FDwfAnalogOutNodeDataSet(hdwf, c_int(0), AnalogOutNodeCarrier, rgdSamples, c_int(cSamples)) #upload waveform data to buffer

# send out waveform
dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1))

 

Link to comment
Share on other sites

  • 0

Hi @Robert White

FDwf[Analog|Digital][Out|In]Configure
0. will stop the AWG
1. will start the AWG
3. will apply the new settings without changing the state, like adjusting the amplitude, frequency..., use this with AutoConfigure 0

On 10/19/2021 at 12:26 PM, attila said:

FDwfDeviceAutoConfigureSet
0 - disabled: Device will be configured when calling FDwf*Configure. It is recommended for complex apps to prevent device configuration with each parameter setting.
1 - enabled (default): Any FDwf*Set will configure the device stopping the respective instrument.
3 - dynamic: Any FDwf*Set will configure the device without stopping the instrument.

 

Link to comment
Share on other sites

  • 0

@attila OK ... so ... something like this? 

I'm looping, changing the buffer on the wavegen in each loop iteration, and then reading data in on the scope.  This will work for some number of iterations (mabye a 100 maybe more) but then it will get stuck ... the loop will keep running but the result returned from the scope will always be the same - its like it didn't have time to trigger or something ... it's not repeatable ... sometimes it will work for a number of iterations and then get into the state where the scope buffer is always the same ...

Are my AutoConfigureSet() and AnalogOutConfigure() functions looking right?? Thank you!!

#Set AutoConfigure Off
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))

#Set up scope to trigger on analog out
dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcAnalogOut1) # trigger scope on analog-out 1 start
dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(cSamples/Fs/2)) # T0 on left, trigger the first sample

#set up the waveform generator
dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcCustom) #set custom waveform
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(hzFreq)) #set buffer length (repeat rate)
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(drive_amp)) #amplitude in volts
dwf.FDwfAnalogOutRunSet(hdwf, c_int(0), c_double(1.0/hzFreq)) # run for 1 period
dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(1.0/hzFreq)) # wait one pulse time
dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(0), c_int(1)) # repeat 1 times

for n in range(1,1000)

	#Calculate new cSamples

    #Load samples into output buffer
    dwf.FDwfAnalogOutNodeDataSet(hdwf, c_int(0), AnalogOutNodeCarrier, rgdSamples, c_int(cSamples)) #upload waveform data to buffer
  
    #enable wavegen and send out waveform
    dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1))

    while True: #wait for acquisition to be ready (should trigger automatically on analog out start)
    	dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
    	if sts.value == DwfStateDone.value :
      		break
    	time.sleep(0.001)

	#disable wavegen ready for next buffer  (not sure this is needed, trying to get buffer updates to be stable)
  	dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(0))

	dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), rg0, c_int(0), len(rg0)) # get channel 0 data, start from sample 0       
  	      

 

Edited by Robert White
Link to comment
Share on other sites

  • 0

Hi @Robert White

I don't see in this code the Scope being fully configured and started. You may want to set the sampling rate, trigger position, number of samples... Then call FDwfAnalogInConfigure to start it before FDwfAnalogOutConfigure, with a delay if you are capturing pre-trigger samples to perform buffer refill, since it will look for trigger event only after prefill is done.
The default 'acqmodeSingle' will restart the capture.

Link to comment
Share on other sites

  • 0

Thanks - yes - I have a number of lines setting up the scope which I left out of the code to try to keep it shorter ... here they are:

# initialize the oscilloscope
# capture up to 32Ki samples
nBufMax = c_int()
dwf.FDwfAnalogInBufferSizeInfo(hdwf, 0, byref(nBufMax))
nSamples = min(NumSamples, nBufMax.value)
rg0 = (c_ushort*nSamples)() #analog measurement array chan0
rg1 = (c_ushort*nSamples)() #analog measurement array chan1

#set up acquisition
SampleRate=c_double(Fs) 
dwf.FDwfAnalogInFrequencySet(hdwf,SampleRate)
dwf.FDwfAnalogInBufferSizeSet(hdwf, nSamples)
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_int(1)) #channel 0 enable
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_int(1)) #channel 1 enable
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(Range0)) # Chan 0 range Vpk2pk
dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(0), c_double(Offset0)) #Chan 0 Offset (V) 
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(Range1)) # Chan 1 range Vpk2pk
dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(1), c_double(Offset1)) #Chan 1 Offset (V) 

Maybe the problem is what you mention about the delay for capturing pre-trigger samples ... I'll try putting a couple of delays in.  My intention is to capture starting at the same time the analog out waveform starts with the lines:

#Set up scope to trigger on analog out
dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcAnalogOut1) # trigger scope on analog-out 1 start
dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(cSamples/Fs/2)) # T0 on left, trigger the first sample

 

Link to comment
Share on other sites

  • 0

I think I fixed my instability problem.  It seems sometimes I was starting the wavegen output a little too early and the scope wasn't yet ready to trigger.  I added this chunk of code before starting the wavegen and it now appears to work every time.  

	    dwf.FDwfAnalogOutNodeDataSet(hdwf, c_int(0), AnalogOutNodeCarrier, rgdSamples, c_int(cSamples)) #upload waveform data to buffer
            
            #Adding this wait seems to solve stability problems.
            while True: #wait for acquisition to be ready
                dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
                if sts.value == DwfStateArmed.value :
                    break
                time.sleep(0.001)

            #This is needed too:
            time.sleep(0.001)
                
            #enable wavegen (send out waveform)
            dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1))

 

Edited by Robert White
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...