support for firmware v 0.2, add ADC cal data
This commit is contained in:
@@ -10,6 +10,7 @@ import numpy as np
|
||||
|
||||
CMD_READ_RAW = 0
|
||||
CMD_READ_SMOOTHED = 1
|
||||
CMD_READ_CAL_CONSTANTS = 2
|
||||
CMD_GET_ENABLED_CHANNELS = 10
|
||||
CMD_GET_SAMPLE_RATE = 11
|
||||
|
||||
@@ -40,6 +41,24 @@ class TriggerReport:
|
||||
def __str__(self):
|
||||
return "EventReport(edge %d, pretrig len %d, ts %d, data %s)" % (self.edge, self.pretrig, self.timestamp, self.data)
|
||||
|
||||
class ADC_CalData:
|
||||
def __init__(self, pp:gex.PayloadParser):
|
||||
self.VREFINT_CAL = pp.u16() # ADC raw value for VREFINT, 30C ambient
|
||||
self.VREFINT_CAL_VADCREF = pp.u16() # Analog reference voltage during VREFINT calibration (mV) +-10mV
|
||||
|
||||
self.TSENSE_CAL1 = pp.u16() # ADC raw value in point 1
|
||||
self.TSENSE_CAL2 = pp.u16() # ADC raw value in point 2
|
||||
self.TSENSE_CAL1_TEMP = pp.u8() # Temperature for point 1 (Celsius) +-5C
|
||||
self.TSENSE_CAL2_TEMP = pp.u8() # Temperature for point 2 (Celsius) +-5C
|
||||
self.TSENSE_CAL_VADCREF = pp.u16() # Analog reference voltage during TSENSE calibration (mV) +-10mV
|
||||
|
||||
def __str__(self):
|
||||
return "ADC_CalData(VREFINT=%d at Vref=%d mV, TSENSE_%dC=%d, TSENSE_%dC=%d at Vref=%d mV)" % \
|
||||
(self.VREFINT_CAL, self.VREFINT_CAL_VADCREF,
|
||||
self.TSENSE_CAL1_TEMP, self.TSENSE_CAL1, self.TSENSE_CAL2_TEMP, self.TSENSE_CAL2, self.TSENSE_CAL_VADCREF)
|
||||
|
||||
# TODO utility for converting raw values to real voltage / temperature
|
||||
|
||||
class ADC(gex.Unit):
|
||||
"""
|
||||
ADC device
|
||||
@@ -161,6 +180,13 @@ class ADC(gex.Unit):
|
||||
msg = self._query(CMD_GET_ENABLED_CHANNELS)
|
||||
return list(msg.data)
|
||||
|
||||
def get_calibration_data(self):
|
||||
"""
|
||||
Read ADC calibration data
|
||||
"""
|
||||
msg = self._query(CMD_READ_CAL_CONSTANTS)
|
||||
return ADC_CalData(gex.PayloadParser(msg.data))
|
||||
|
||||
def set_sample_rate(self, freq:int):
|
||||
""" Set sample rate in Hz. Returns the real achieved frequency as float. """
|
||||
pb = gex.PayloadBuilder()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
## UNITS.INI
|
||||
## GEX v0.1.0 on STM32F072-HUB
|
||||
## built Mar 28 2018 at 00:42:03
|
||||
|
||||
[UNITS]
|
||||
# Create units by adding their names next to a type (e.g. DO=A,B),
|
||||
# remove the same way. Reload to update the unit sections below.
|
||||
|
||||
# Digital output
|
||||
DO=ce
|
||||
# Digital input with triggers
|
||||
DI=irq
|
||||
# Neopixel RGB LED strip
|
||||
NPX=
|
||||
# I2C master
|
||||
I2C=
|
||||
# SPI master
|
||||
SPI=spi
|
||||
# Serial port
|
||||
USART=
|
||||
# 1-Wire master
|
||||
1WIRE=
|
||||
# Analog/digital converter
|
||||
ADC=
|
||||
# Shift register driver (595, 4094)
|
||||
SIPO=
|
||||
# Frequency and pulse measurement
|
||||
FCAP=
|
||||
# Capacitive touch sensing
|
||||
TOUCH=
|
||||
# Simple PWM output
|
||||
PWMDIM=
|
||||
# Two-channel analog output with waveforms
|
||||
DAC=
|
||||
|
||||
[DO:ce@2]
|
||||
# Port name
|
||||
port=B
|
||||
# Pins (comma separated, supports ranges)
|
||||
pins=6, 2
|
||||
# Initially high pins
|
||||
initial=
|
||||
# Open-drain pins
|
||||
open-drain=
|
||||
|
||||
[DI:irq@3]
|
||||
# Port name
|
||||
port=B
|
||||
# Pins (comma separated, supports ranges)
|
||||
pins=8-7
|
||||
# Pins with pull-up
|
||||
pull-up=
|
||||
# Pins with pull-down
|
||||
pull-down=
|
||||
|
||||
# Trigger pins activated by rising/falling edge
|
||||
trig-rise=
|
||||
trig-fall=
|
||||
# Trigger pins auto-armed by default
|
||||
auto-trigger=
|
||||
# Triggers hold-off time (ms)
|
||||
hold-off=100
|
||||
|
||||
[SPI:spi@1]
|
||||
# Peripheral number (SPIx)
|
||||
device=1
|
||||
# Pin mappings (SCK,MISO,MOSI)
|
||||
# SPI1: (0) A5,A6,A7 (1) B3,B4,B5
|
||||
# SPI2: (0) B13,B14,B15
|
||||
remap=1
|
||||
|
||||
# Prescaller: 2,4,8,...,256
|
||||
prescaller=64
|
||||
# Clock polarity: 0,1 (clock idle level)
|
||||
cpol=0
|
||||
# Clock phase: 0,1 (active edge, 0-first, 1-second)
|
||||
cpha=1
|
||||
# Transmit only, disable MISO
|
||||
tx-only=N
|
||||
# Bit order (LSB or MSB first)
|
||||
first-bit=MSB
|
||||
|
||||
# SS port name
|
||||
port=B
|
||||
# SS pins (comma separated, supports ranges)
|
||||
pins=1-0
|
||||
+5
-2
@@ -8,9 +8,12 @@ from matplotlib import pyplot as plt
|
||||
from scipy.io import wavfile
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
adc = gex.ADC(client, 'a')
|
||||
adc = gex.ADC(client, 'adc')
|
||||
|
||||
adc.set_active_channels([3])
|
||||
print(adc.get_calibration_data())
|
||||
print(adc.get_channels())
|
||||
|
||||
adc.set_active_channels([1])
|
||||
rate=500
|
||||
fs = adc.set_sample_rate(rate)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user