Python 2000a control of picoscope 2208B SetSimpleTrigger and Random Noise Issues

Having problems ? let us know the details here
Post Reply
lafinney
Newbie
Posts: 1
Joined: Fri Sep 17, 2021 3:59 pm

Python 2000a control of picoscope 2208B SetSimpleTrigger and Random Noise Issues

Post by lafinney »

Hello,

I am just trying to set up a simple trigger, where I trigger on ChA with a rising edge threshold level. I occasionally see my pulse that expect ChA to trigger on, however, there are random spikes with equivalent V that I think might be causing issues with the trigger? And these spikes do not appear in the PicoScope software. I have attached images of both, and below is the code I am using. Note: I switch the autotrigger to 0 when I try to trigger off ChA, but used 100 ms to demonstrate the noise spikes I see along with the pulse I'm measuring. Also as you can see, the peak voltage values do not match up in the software and python.

Note2: I downloaded the block sample for the ps2000a from github, and just made a couple small changes to timebase and SetSimpleTrigger.

Thanks!

# PS2000A BLOCK MODE EXAMPLE
# This example opens a 2000a driver device, sets up two channels and a trigger then collects a block of data.
# This data is then plotted as mV against time in ns.

import ctypes
import numpy as np
from picosdk.ps2000a import ps2000a as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok

# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}

# Open 2000 series PicoScope
# Returns handle to chandle for use in future API functions
status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None)
assert_pico_ok(status["openunit"])

# Set up channel A
# handle = chandle
# channel = PS2000A_CHANNEL_A = 0
# enabled = 1
# coupling type = PS2000A_DC = 1
# range = PS2000A_2V = 7
# analogue offset = 0 V
chARange = 7
status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 1, chARange, 0)
assert_pico_ok(status["setChA"])

# Set up channel B
# handle = chandle
# channel = PS2000A_CHANNEL_B = 1
# enabled = 1
# coupling type = PS2000A_DC = 1
# range = PS2000A_2V = 7
# analogue offset = 0 V
chBRange = 7
status["setChB"] = ps.ps2000aSetChannel(chandle, 1, 1, 1, chBRange, 0)
assert_pico_ok(status["setChB"])

# Set up single trigger
# handle = chandle
# enabled = 1
# source = PS2000A_CHANNEL_A = 0
# threshold = 1024 ADC counts
# direction = PS2000A_RISING = 2
# delay = 0 s
# auto Trigger = 1000 ms
threshold = 32512
status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, threshold, 2, 0,100)
assert_pico_ok(status["trigger"])

# Set number of pre and post trigger samples to be collected
preTriggerSamples =10
postTriggerSamples = 50
totalSamples = preTriggerSamples + postTriggerSamples


# Get timebase information
# handle = chandle
# timebase = 8 = timebase
# noSamples = totalSamples
# pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs)
# pointer to totalSamples = ctypes.byref(returnedMaxSamples)
# segment index = 0
timebase = 312500 #this should be 10 ms timebase
timeIntervalns = ctypes.c_float()
returnedMaxSamples = ctypes.c_int32()
oversample = ctypes.c_int16(0)
status["getTimebase2"] = ps.ps2000aGetTimebase2(chandle,
timebase,
totalSamples,
ctypes.byref(timeIntervalns),
oversample,
ctypes.byref(returnedMaxSamples),
0)
assert_pico_ok(status["getTimebase2"])


# Run block capture
# handle = chandle
# number of pre-trigger samples = preTriggerSamples
# number of post-trigger samples = PostTriggerSamples
# timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases)
# oversample = 0 = oversample
# time indisposed ms = None (not needed in the example)
# segment index = 0
# lpReady = None (using ps2000aIsReady rather than ps2000aBlockReady)
# pParameter = None
status["runBlock"] = ps.ps2000aRunBlock(chandle,
preTriggerSamples,
postTriggerSamples,
timebase,
oversample,
None,
0,
None,
None)
assert_pico_ok(status["runBlock"])

# Check for data collection to finish using ps2000aIsReady
ready = ctypes.c_int16(0)
check = ctypes.c_int16(0)
while ready.value == check.value:
status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready))

# Create buffers ready for assigning pointers for data collection
bufferAMax = (ctypes.c_int16 * totalSamples)()
bufferAMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example
bufferBMax = (ctypes.c_int16 * totalSamples)()
bufferBMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example

# Set data buffer location for data collection from channel A
# handle = chandle
# source = PS2000A_CHANNEL_A = 0
# pointer to buffer max = ctypes.byref(bufferDPort0Max)
# pointer to buffer min = ctypes.byref(bufferDPort0Min)
# buffer length = totalSamples
# segment index = 0
# ratio mode = PS2000A_RATIO_MODE_NONE = 0
status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(chandle,
0,
ctypes.byref(bufferAMax),
ctypes.byref(bufferAMin),
totalSamples,
0,
0)
assert_pico_ok(status["setDataBuffersA"])
print("BufferMin = ", bufferAMin)
print("BufferMax = ", bufferAMax)

# Set data buffer location for data collection from channel B
# handle = chandle
# source = PS2000A_CHANNEL_B = 1
# pointer to buffer max = ctypes.byref(bufferBMax)
# pointer to buffer min = ctypes.byref(bufferBMin)
# buffer length = totalSamples
# segment index = 0
# ratio mode = PS2000A_RATIO_MODE_NONE = 0
status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(chandle,
1,
ctypes.byref(bufferBMax),
ctypes.byref(bufferBMin),
totalSamples,
0,
0)
assert_pico_ok(status["setDataBuffersB"])

# Create overflow location
overflow = ctypes.c_int16()
# create converted type totalSamples
cTotalSamples = ctypes.c_int32(totalSamples)

# Retried data from scope to buffers assigned above
# handle = chandle
# start index = 0
# pointer to number of samples = ctypes.byref(cTotalSamples)
# downsample ratio = 0
# downsample ratio mode = PS2000A_RATIO_MODE_NONE
# pointer to overflow = ctypes.byref(overflow))
status["getValues"] = ps.ps2000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 0, 0, ctypes.byref(overflow))
assert_pico_ok(status["getValues"])


# find maximum ADC count value
# handle = chandle
# pointer to value = ctypes.byref(maxADC)
maxADC = ctypes.c_int16()
status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC))
assert_pico_ok(status["maximumValue"])
print("maxADC = ", maxADC)

# convert ADC counts data to mV
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC)

# Create time data
time = np.linspace(0, (cTotalSamples.value) * timeIntervalns.value, cTotalSamples.value)

# plot data from channel A and B
plt.plot(time, adc2mVChAMax[:])
#plt.plot(time, adc2mVChBMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

# Stop the scope
# handle = chandle
status["stop"] = ps.ps2000aStop(chandle)
assert_pico_ok(status["stop"])

# Close unitDisconnect the scope
# handle = chandle
status["close"] = ps.ps2000aCloseUnit(chandle)
assert_pico_ok(status["close"])

# display status returns
print(status)
Attachments
InSoftwareExample_01.png
Example_NoTrigger.png
Example_NoTrigger.png (13.16 KiB) Viewed 9286 times

bennog
Advanced User
Advanced User
Posts: 206
Joined: Mon Nov 26, 2012 9:16 am
Location: Netherlands

Re: Python 2000a control of picoscope 2208B SetSimpleTrigger and Random Noise Issues

Post by bennog »

It looks like you set the scope in +/- 2V range and measuring mv values.
This are single digit values AKA noise.
You need to set the scope to +/- 50 mV or +/- 20mV the you have the 256 steps more distributed against you signal values.

Benno

bennog
Advanced User
Advanced User
Posts: 206
Joined: Mon Nov 26, 2012 9:16 am
Location: Netherlands

Re: Python 2000a control of picoscope 2208B SetSimpleTrigger and Random Noise Issues

Post by bennog »

O and you are capturing in the ns range while your pulse is 10 ms long. So your capture sample rate is far to high.

Benno

Post Reply