|
| 1 | +import ctypes |
| 2 | +import numpy as np |
| 3 | +from time import sleep |
| 4 | +import math |
| 5 | + |
| 6 | +from picosdk.ps2000 import ps2000 as ps |
| 7 | +from picosdk.functions import assert_pico2000_ok, adc2mV |
| 8 | +from picosdk.PicoDeviceEnums import picoEnum |
| 9 | + |
| 10 | +import matplotlib.pyplot as plt |
| 11 | + |
| 12 | +import gen_sq_wave as square |
| 13 | +import os |
| 14 | + |
| 15 | +# Create status ready for use |
| 16 | +status = {} |
| 17 | + |
| 18 | +# Open 2000 series PicoScope |
| 19 | +# Returns handle to chandle for use in future API functions |
| 20 | +status["openUnit"] = ps.ps2000_open_unit() |
| 21 | +assert_pico2000_ok(status["openUnit"]) |
| 22 | +# Create chandle for use |
| 23 | +chandle = ctypes.c_int16(status["openUnit"]) |
| 24 | + |
| 25 | +t_sq = np.linspace(0,1,1024) |
| 26 | +# waveform = np.array(waveform) |
| 27 | +waveform = square.gen_square(2*np.pi*t_sq, 0.2, 0) |
| 28 | + |
| 29 | +# plot AWG waveform to output |
| 30 | +plt.plot(waveform[:]) |
| 31 | +print("Plotting waveform to output...") |
| 32 | +plt.show() |
| 33 | +# Once user closes the plot Window the waveform will be output enabled |
| 34 | + |
| 35 | +# change the datatype to ctypes.c_uint8 |
| 36 | +arbitraryWaveform = waveform.astype('uint8') |
| 37 | +arbitraryWaveformSize = ctypes.c_int32(len(waveform)) |
| 38 | +WaveformSize = len(waveform) |
| 39 | + |
| 40 | +frequecy = 1000 # Hz |
| 41 | +print("Frquency is ", frequecy) |
| 42 | + |
| 43 | +# Code to calulate FrequencyToPhase for 2000 series AWG |
| 44 | +# deltaPhase=((f*s)/maxBuffer)*phaseAcc*(1/ddsFreq) |
| 45 | +# phase =((f*s)/4096)*(32^2)*(1/48000000) |
| 46 | +phaseCal = ((frequecy*WaveformSize)/4096)*math.pow(2,32)*(1/48000000) |
| 47 | +print("Which converts to AWG Phase value of ", phaseCal) |
| 48 | +#Cast float value to interger |
| 49 | +phase = ctypes.c_uint32(int(phaseCal)) |
| 50 | + |
| 51 | +arbitraryWaveformPointer = arbitraryWaveform.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) |
| 52 | + |
| 53 | +print("AWG buffer_length is ", arbitraryWaveformSize) |
| 54 | +pkToPk = ctypes.c_uint32(1500000) |
| 55 | +offsetVoltage = ctypes.c_int32(0) |
| 56 | +sweeps = ctypes.c_uint32(0) |
| 57 | +startDeltaPhase = phase |
| 58 | +stopDeltaPhase = phase # when frequency sweep is not required set it equal to startDeltaPhase |
| 59 | +deltaPhaseIncrement = ctypes.c_uint32(0) # when frequency sweep is not required set it to 0 |
| 60 | +dwellCount = ctypes.c_uint32(0) # when frequency sweep isn't required set it equal to 0 |
| 61 | +# PS2000_SWEEP_TYPE |
| 62 | +# PS2000_UP 0 |
| 63 | +# PS2000_DOWN 1 |
| 64 | +# PS2000_UPDOWN 2 |
| 65 | +# PS2000_DOWNUP 3 |
| 66 | +sweepType = 0 #ctypes.c_unt32(0) |
| 67 | + |
| 68 | +print("Output AWG waveform") |
| 69 | +status["ps2000_set_sig_gen_arbitrary"] = ps.ps2000_set_sig_gen_arbitrary(chandle, offsetVoltage, |
| 70 | + pkToPk, |
| 71 | + startDeltaPhase, |
| 72 | + stopDeltaPhase, |
| 73 | + deltaPhaseIncrement, |
| 74 | + dwellCount, |
| 75 | + arbitraryWaveformPointer, |
| 76 | + arbitraryWaveformSize, |
| 77 | + sweepType, |
| 78 | + sweeps) |
| 79 | +assert_pico2000_ok(status["ps2000_set_sig_gen_arbitrary"]) |
| 80 | + |
| 81 | + |
| 82 | +print("Delay for 10 seconds...") |
| 83 | +sleep(10) |
| 84 | + |
| 85 | +# Close unitDisconnect the scope |
| 86 | +# handle = chandle |
| 87 | +status["close"] = ps.ps2000_close_unit(chandle) |
| 88 | +assert_pico2000_ok(status["close"]) |
| 89 | + |
| 90 | +# display status returns |
| 91 | +print(status) |
| 92 | + |
| 93 | + |
| 94 | + |
0 commit comments