Python SDK & ps5000aSetSigGenArbitrary

Post general discussions on using our drivers to write your own software here
Post Reply
cjkraz
Newbie
Posts: 0
Joined: Mon Oct 29, 2018 2:55 pm

Python SDK & ps5000aSetSigGenArbitrary

Post by cjkraz » Tue Jul 16, 2019 5:10 pm

Hi folks,

I've done some search and how come up with nothing thus far.

So I'm trying to use the Arbitrary Waveform functionality of the Generator on a Picoscope 5242D (This is probably applicable for others as well).

Generally speaking I've got everything setup:

Code: Select all

#Generate our waveform
repPeriod = 0.6667e-3
wf_Ratio = burstPeriod/repPeriod
totalLength = 2**15
burstLength = int(wf_Ratio * totalLength)
totalLength - burstLength

#make our pulse like square wave.
waveform = [32767 if x < burstLength else 0 for x in range(totalLength)]

#Get the phase value:
phase = ctypes.c_uint32()
ps.ps5000aSigGenFrequencyToPhase(scope, 1500.0, 0, len(waveform), ctypes.byref(phase))

#Convert waveform to ctypes:
waveform_ctypes = ctypes.c_int16 * len(waveform)
waveform_ctypes.values = tuple(waveform)

#Try and produce the waveform
handle = scope
offsetVoltage = 1000000 #in uVolts
pkToPk = 2000000 #in uVolts
startDeltaPhase = phase
stopDeltaPhase = phase
deltaPhaseIncrement = 0
dwellCount = 0
arbitraryWaveform = ctypes.POINTER(waveform_ctypes)
arbitraryWaveformSize = len(waveform)
sweepType = 0
operation = 0
indexMode = 0
shots = 5
sweeps = 0
triggerType = 0
triggerSource = 4
extInThreshold = 0

ret = ps.ps5000aSetSigGenArbitrary(handle,\
                                   offsetVoltage,\
                                   pkToPk,\
                                   startDeltaPhase,\
                                   stopDeltaPhase,\
                                   deltaPhaseIncrement,\
                                   dwellCount,\
                                   arbitraryWaveform,\
                                   arbitraryWaveformSize,\
                                   sweepType,\
                                   operation,\
                                   indexMode,\
                                   shots,\
                                   sweeps,\
                                   triggerType,\
                                   triggerSource,\
                                   extInThreshold)
At this point, I'm not sure how I should be passing the waveform array to the function. I know I'm not doing it correctly because I get an error:

Code: Select all

ArgumentError: argument 8: type 'exceptions.TypeError': wrong type
Just looking for that last key piece of information so I can keep on programming.

Thanks!

cjkraz
Newbie
Posts: 0
Joined: Mon Oct 29, 2018 2:55 pm

Re: Python SDK & ps5000aSetSigGenArbitrary

Post by cjkraz » Tue Jul 16, 2019 8:27 pm

So I'm about to answer my own question.

I didn't stop trying to figure this out after I submitted my question, so here's the solution for others who may end up in the same situation.

When you want to generate a custom waveform for the Picoscope's AWG, create the array as a numpy.array.
Once you've generated your desired waveform, you can use some built-in numpy methods to convert the array to a ctypes pointer for the function call. Here is an example of the solution that I found works for me.

Code: Select all

#'waveform' is just a list of values equivalent int16 values before this point
waveform = np.array(waveform, dtype=np.int16)

phase = ctypes.c_uint32()
#get the start & stop DeltaPhase values for the SetSig function.
ps.ps5000aSigGenFrequencyToPhase(scope, 1000, 0, len(waveform), ctypes.byref(phase))

offsetVoltage = 1000000 #in uVolts
pkToPk = 2 #in uVolts
startDeltaPhase = phase
stopDeltaPhase = phase
deltaPhaseIncrement = 0
dwellCount = 0

#########################################
## this is the magic line I was looking for
#########################################

arbitraryWaveform = waveform.ctypes.data_as(ctypes.POINTER(ctypes.c_int16))


arbitraryWaveformSize = len(waveform)
sweepType = 0
operation = 0
indexMode = 0
shots = ctypes.c_uint32(pulses)
sweeps = ctypes.c_uint32(0)
triggerType = 0
triggerSource = 4
extInThreshold = 0
ret = ps.ps5000aSetSigGenArbitrary(
                                    self.handle,
                                    offsetVoltage,
                                    c_uint32(int(pkToPk * 1E6)), 
                                    startDeltaPhase,
                                    stopDeltaPhase,
                                    c_uint32(0),
                                    c_uint32(0),
                                    arbitraryWaveform,
                                    c_int32(len(waveform)),
                                    0,
                                    0,
                                    indexMode, 
                                    c_uint32(1200), 
                                    c_uint32(0),
                                    triggerType,
                                    triggerSource,
                                    c_int16(0))

pantel
Newbie
Posts: 0
Joined: Wed Dec 04, 2019 3:40 pm

Re: Python SDK & ps5000aSetSigGenArbitrary

Post by pantel » Wed Dec 11, 2019 2:47 pm

Hello,

Have you also tried to simultaneously trigger the sig gen and the picoscope channel, so as to capture the generated waveform?

Thanks

Post Reply