|
9 | 9 | import numpy as np |
10 | 10 | from picosdk.pl1000 import pl1000 as pl |
11 | 11 | import matplotlib.pyplot as plt |
12 | | -from picosdk.functions import adc2mV, assert_pico_ok |
| 12 | +from picosdk.functions import adc2mVpl1000, assert_pico_ok |
13 | 13 | from time import sleep |
14 | 14 |
|
15 | 15 | # Create chandle and status ready for use |
|
22 | 22 |
|
23 | 23 | # set sampling interval |
24 | 24 | usForBlock = ctypes.c_uint32(10000000) |
25 | | -noOfValues = ctypes.c_uint32(100000000) |
| 25 | +noOfValues = ctypes.c_uint32(1000000) |
26 | 26 | channels = ctypes.c_int16(1) |
27 | 27 |
|
28 | 28 | status["setInterval"] = pl.pl1000SetInterval(chandle, ctypes.byref(usForBlock), noOfValues, ctypes.byref(channels), 1) |
29 | 29 | assert_pico_ok(status["setInterval"]) |
30 | 30 |
|
31 | 31 | # start streaming |
32 | 32 | mode = pl.PL1000_BLOCK_METHOD["BM_STREAM"] |
33 | | -status["run"] = pl.pl1000Run(chandle, noOfValues, mode) |
| 33 | +status["run"] = pl.pl1000Run(chandle, 1000000, mode) |
34 | 34 | assert_pico_ok(status["run"]) |
35 | 35 |
|
36 | | -sleep(5) |
| 36 | +sleep(usForBlock.value / 1000000) |
37 | 37 |
|
38 | | -values = (ctypes.c_uint16 * noOfValues)() |
| 38 | +values = (ctypes.c_uint16 * noOfValues.value)() |
39 | 39 | oveflow = ctypes.c_uint16() |
40 | 40 |
|
41 | 41 | status["getValues"] = pl.pl1000GetValues(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(oveflow), None) |
42 | 42 | assert_pico_ok(status["getValues"]) |
43 | 43 |
|
| 44 | +# convert ADC counts data to mV |
| 45 | +maxADC = ctypes.c_uint16() |
| 46 | +status["maxValue"] = pl.pl1000MaxValue(chandle, ctypes.byref(maxADC)) |
| 47 | +assert_pico_ok(status["maxValue"]) |
| 48 | +inputRange = 2500 |
| 49 | +mVValues = adc2mVpl1000(values, inputRange, maxADC) |
| 50 | + |
| 51 | +# create time data |
| 52 | +interval = (0.01 * usForBlock.value)/(noOfValues.value * 1) |
| 53 | + |
| 54 | +timeMs = np.linspace(0, (len(mVValues)) * interval, len(mVValues)) |
| 55 | + |
| 56 | +# plot data |
| 57 | + |
| 58 | +plt.plot(timeMs, mVValues[:]) |
| 59 | +plt.xlabel('Time (ms)') |
| 60 | +plt.ylabel('Voltage (mV)') |
| 61 | +plt.show() |
44 | 62 |
|
45 | 63 | # close PicoLog 1000 device |
46 | 64 | status["closeUnit"] = pl.pl1000CloseUnit(chandle) |
|
0 commit comments