Skip to content

Commit 5b7599d

Browse files
author
neil.hamilton
committed
Merge pl1000-streaming-example into master
2 parents f0001ec + 4eeab99 commit 5b7599d

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

picosdk/functions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ def adc2mV(bufferADC, range, maxADC):
2323
bufferV = [(x * vRange) / maxADC.value for x in bufferADC]
2424

2525
return bufferV
26+
27+
def adc2mVpl1000(bufferADC, range, maxADC):
28+
"""
29+
adc2mVpl1000(
30+
c_short_Array bufferADC,
31+
int range,
32+
c_int32 maxADC
33+
)
34+
35+
Takes a buffer of raw adc count values and converts it into millvolts
36+
"""
37+
38+
bufferV = [(x * range) / maxADC.value for x in bufferADC]
39+
40+
return bufferV
2641

2742
def mV2adc(millivolts, range, maxADC):
2843
"""
@@ -39,6 +54,18 @@ def mV2adc(millivolts, range, maxADC):
3954

4055
return adcValue
4156

57+
def mV2adcpl1000(millivolts, range, maxADC):
58+
"""
59+
mV2adc(
60+
float millivolts,
61+
int range,
62+
c_int32 maxADC
63+
)
64+
Takes a voltage value and converts it to adc counts
65+
"""
66+
adcValue = round((millivolts * maxADC.value)/range)
67+
68+
return adcValue
4269

4370

4471
def splitMSOData(dataLength, data):

picosdk/pl1000.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def _pl1000Inputs():
5454
'PL1000_OPEN_PROGRESS_COMPLETE' : 1,
5555
}
5656

57+
pl1000.PL1000_BLOCK_METHOD = make_enum([
58+
"BM_SINGLE",
59+
"BM_WINDOW",
60+
"BM_STREAM",
61+
])
62+
5763
doc = """ PICO_STATUS pl1000CloseUnit
5864
(
5965
int16_t handle
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
# PL1000 SINGLE MODE EXAMPLE
5+
# This example opens a pl1000 device, sets up the device for capturing data from channel 1.
6+
# Then this example collect a sample from channel 1 and displays it on the console.
7+
8+
import ctypes
9+
import numpy as np
10+
from picosdk.pl1000 import pl1000 as pl
11+
import matplotlib.pyplot as plt
12+
from picosdk.functions import adc2mVpl1000, assert_pico_ok
13+
from time import sleep
14+
15+
# Create chandle and status ready for use
16+
chandle = ctypes.c_int16()
17+
status = {}
18+
19+
# open PicoLog 1000 device
20+
status["openUnit"] = pl.pl1000OpenUnit(ctypes.byref(chandle))
21+
assert_pico_ok(status["openUnit"])
22+
23+
# set sampling interval
24+
usForBlock = ctypes.c_uint32(10000000)
25+
noOfValues = ctypes.c_uint32(1000000)
26+
channels = ctypes.c_int16(1)
27+
28+
status["setInterval"] = pl.pl1000SetInterval(chandle, ctypes.byref(usForBlock), noOfValues, ctypes.byref(channels), 1)
29+
assert_pico_ok(status["setInterval"])
30+
31+
# start streaming
32+
mode = pl.PL1000_BLOCK_METHOD["BM_STREAM"]
33+
status["run"] = pl.pl1000Run(chandle, 1000000, mode)
34+
assert_pico_ok(status["run"])
35+
36+
sleep(usForBlock.value / 1000000)
37+
38+
values = (ctypes.c_uint16 * noOfValues.value)()
39+
oveflow = ctypes.c_uint16()
40+
41+
status["getValues"] = pl.pl1000GetValues(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(oveflow), None)
42+
assert_pico_ok(status["getValues"])
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()
62+
63+
# close PicoLog 1000 device
64+
status["closeUnit"] = pl.pl1000CloseUnit(chandle)
65+
assert_pico_ok(status["closeUnit"])
66+
67+
# display status returns
68+
print(status)

0 commit comments

Comments
 (0)