Skip to content

Commit 1a93bd0

Browse files
committed
SigGen example
1 parent 33fe878 commit 1a93bd0

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

ps4000aExamples/ps4000aSigGen.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#
2+
# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
# PicoScope 4000 (A API) Series Signal Generator Example
5+
# This example demonstrates how to use the PicoScope 4000 Series (ps4000a) driver API functions to set up the signal generator to do the following:
6+
#
7+
# 1. Output a sine wave
8+
# 2. Output a square wave
9+
# 3. Output a sweep of a square wave signal
10+
11+
import ctypes
12+
from picosdk.ps4000a import ps4000a as ps
13+
import time
14+
from picosdk.functions import assert_pico_ok
15+
16+
17+
# Gives the device a handle
18+
status = {}
19+
chandle = ctypes.c_int16()
20+
21+
# Opens the device/s
22+
status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None)
23+
24+
try:
25+
assert_pico_ok(status["openunit"])
26+
except:
27+
# powerstate becomes the status number of openunit
28+
powerstate = status["openunit"]
29+
30+
# If powerstate is the same as 282 then it will run this if statement
31+
if powerstate == 282:
32+
# Changes the power input to "PICO_POWER_SUPPLY_NOT_CONNECTED"
33+
status["ChangePowerSource"] = ps.ps4000aChangePowerSource(chandle, 282)
34+
# If the powerstate is the same as 286 then it will run this if statement
35+
elif powerstate == 286:
36+
# Changes the power input to "PICO_USB3_0_DEVICE_NON_USB3_0_PORT"
37+
status["ChangePowerSource"] = ps.ps4000aChangePowerSource(chandle, 286)
38+
else:
39+
raise
40+
41+
assert_pico_ok(status["ChangePowerSource"])
42+
43+
# Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz
44+
# handle = chandle
45+
# offsetVoltage = 0
46+
# pkToPk = 2000000
47+
# waveType = ctypes.c_int16(0) = PS4000A_SINE
48+
# startFrequency = 10 kHz
49+
# stopFrequency = 10 kHz
50+
# increment = 0
51+
# dwellTime = 1
52+
# sweepType = ctypes.c_int32(0) = PS4000A_UP
53+
# operation = 0
54+
# shots = 0
55+
# sweeps = 0
56+
# triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING
57+
# triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE
58+
# extInThreshold = 0
59+
wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SINE']
60+
sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UP']
61+
triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING']
62+
triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE']
63+
extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used
64+
65+
status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold)
66+
assert_pico_ok(status["SetSigGenBuiltIn"])
67+
68+
# Pauses the script to show signal
69+
time.sleep(10)
70+
71+
# Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz
72+
# handle = chandle
73+
# offsetVoltage = 0
74+
# pkToPk = 2000000
75+
# waveType = ctypes.c_int16(1) = PS4000A_SQUARE
76+
# startFrequency = 10 kHz
77+
# stopFrequency = 10 kHz
78+
# increment = 0
79+
# dwellTime = 1
80+
# sweepType = ctypes.c_int32(0) = PS4000A_UP
81+
# operation = 0
82+
# shots = 0
83+
# sweeps = 0
84+
# triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING
85+
# triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE
86+
# extInThreshold = 0
87+
wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SQUARE']
88+
sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UP']
89+
triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING']
90+
triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE']
91+
extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used
92+
93+
status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold)
94+
assert_pico_ok(status["SetSigGenBuiltIn"])
95+
96+
# pauses the script to show signal
97+
time.sleep(10)
98+
99+
# Output square wave with an up-down sweep, ranging from 10-100 kHz in 5 kHz increments every 1 second.
100+
# handle = chandle
101+
# offsetVoltage = 0
102+
# pkToPk = 2000000
103+
# waveType = ctypes.c_int16(1) = PS4000A_SQUARE
104+
# startFrequency = 10 kHz
105+
# stopFrequency = 100 kHz
106+
# increment = 5 kHz
107+
# dwellTime = 1
108+
# sweepType = ctypes.c_int32(2) = PS4000A_UPDOWN
109+
# operation = 0
110+
# shots = 0
111+
# sweeps = 0
112+
# triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING
113+
# triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE
114+
# extInThreshold = 0
115+
wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SQUARE']
116+
sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UPDOWN']
117+
triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING']
118+
triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE']
119+
extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used
120+
121+
status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold)
122+
assert_pico_ok(status["SetSigGenBuiltIn"])
123+
124+
# Pauses the script to show signal
125+
time.sleep(36)
126+
127+
# Closes the unit
128+
# Handle = chandle
129+
status["close"] = ps.ps4000aCloseUnit(chandle)
130+
assert_pico_ok(status["close"])
131+
132+
# Displays the status returns
133+
print(status)

0 commit comments

Comments
 (0)