pico-python
pico-python copied to clipboard
Issues With changing the sampling interval
Hello, I just started using these scripts to run my picoscope via the terminal. I am running into an issue in that I am not able to easily change the length of recording and the sampling rate. I am new to hardware scripting so any help would be great! I am probably missing something dumb.
It would help if you shared the code you are using. Could you please share that?
if name == "main": print(doc)
print("Attempting to open Picoscope 2000...")
ps = ps2000.PS2000()
# Uncomment this line to use with the 2000a/2000b series
# ps = ps2000a.PS2000a()
print("Found the following picoscope:")
print(ps.getAllUnitInfo())
waveform_desired_duration = 50E-3
obs_duration = 3 * waveform_desired_duration
sampling_interval = obs_duration / 4096
(actualSamplingInterval, nSamples, maxSamples) = \
ps.setSamplingInterval(sampling_interval, obs_duration)
print("Sampling interval = %f ns" % (actualSamplingInterval * 1E9))
print("Taking samples = %d" % nSamples)
print("Maximum samples = %d" % maxSamples)
# the setChannel command will chose the next largest amplitude
channelRange = ps.setChannel('A', 'DC', 2.0, 0.0, enabled=True,
BWLimited=False)
print("Chosen channel range = %d" % channelRange)
ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True)
ps.setSigGenBuiltInSimple(offsetVoltage=0, pkToPk=1.2, waveType="Sine",
frequency=50E3)
ps.runBlock()
ps.waitReady()
print("Waiting for awg to settle.")
time.sleep(2.0)
ps.runBlock()
ps.waitReady()
print("Done waiting for trigger")
dataA = ps.getDataV('A', nSamples, returnOverflow=False)
dataTimeAxis = np.arange(nSamples) * actualSamplingInterval
ps.stop()
ps.close()
f = open("test.bin", "wb")
s = struct.pack('f'*len(dataA), *dataA)
f.write(s)
f.close()
# Uncomment following for call to .show() to not block
# plt.ion()
plt.figure()
plt.plot(dataA, label="Clock")
plt.grid(True, which='major')
plt.title("Picoscope 2000 waveforms")
plt.ylabel("Voltage (V)")
plt.xlabel("Time (ms)")
plt.legend()
plt.show()
the same on as the one colin has in the examples folder: https://github.com/colinoflynn/pico-python/blob/master/examples/ps2000_demo.py
Do you get any error?
This is my error(Error calling _lowLevelGetTimebase) I change waveform_desired_duration from 50E-6 to 50E-2. I thought this means the time of the waveform.
If i recall correctly, timebase is something like the sampling time.
Was that your understanding?
I ran into this issue too! This seems to be because of the "sampling_interval = obs_duration / 4096" line. I think sometimes the calculation will result in taking more samples than the maximum (My 2204a can only sample 3968 samples) and that makes the setting of the interval fail. I reduced the divisor and got it working!
patches are welcome. happy to review and to release.
it is appreciated if you can justify the patch with a screenshot from documentation.