Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 65 additions & 24 deletions bindings/python/ts_calibration.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,76 @@
#
# Copyright (C) 2025 / Nate Meyer / nate.devel@gmail.com

from libc.stdint cimport uint32_t, int32_t, uint8_t, uint16_t
from libc.stdint cimport uint32_t, int32_t, uint8_t, int8_t, uint16_t


cdef extern from "ts_calibration.h":

ctypedef void* tsHandle_t

cdef struct tsChannelCalibration_s:
int32_t buffer_uV
int32_t bias_uV
int32_t attenuatorGain1M_mdB
int32_t attenuatorGain50_mdB
int32_t bufferGain_mdB
int32_t trimRheostat_range
int32_t preampLowGainError_mdB
int32_t preampHighGainError_mdB
int32_t preampAttenuatorGain_mdB[11]
int32_t preampOutputGainError_mdB
int32_t preampLowOffset_uV
int32_t preampHighOffset_uV
int32_t preampInputBias_uA

ctypedef tsChannelCalibration_s tsChannelCalibration_t
cdef enum:
TS_CAL_NUM_PATHS = 11
TS_CAL_NUM_LOADS = 11
TS_CAL_NUM_RATES = 8

cdef enum tsChannelsActive_e:
TS_CHAN_NONE = 0b0000
TS_CHAN_0 = 0b0001
TS_CHAN_1 = 0b0010
TS_CHAN_0_1 = 0b0011
TS_CHAN_2 = 0b0100
TS_CHAN_0_2 = 0b0101
TS_CHAN_1_2 = 0b0110
TS_CHAN_3 = 0b1000
TS_CHAN_0_3 = 0b1001
TS_CHAN_1_3 = 0b1010
TS_CHAN_2_3 = 0b1100
TS_CHAN_0_1_2_3 = 0b1111

ctypedef tsChannelsActive_e tsChannelsActive_t

cdef struct tsAfePathCalibration_s:
double bufferInputVpp
double trimOffsetDacZeroC
double trimOffsetDacZeroM
double trimOffsetDacScale
uint32_t trimDPot

ctypedef tsAfePathCalibration_s tsAfePathCalibration_t

cdef struct tsAfeCalibration_s:
double attenuatorScale
tsAfePathCalibration_t highPgaPathCal[TS_CAL_NUM_PATHS]
tsAfePathCalibration_t lowPgaPathCal[TS_CAL_NUM_PATHS]

ctypedef tsAfeCalibration_s tsChannelCalibration_t

cdef struct tsAdcLoad_s:
uint32_t rate
double[4] scale

ctypedef tsAdcLoad_s tsAdcLoad_t

cdef struct tsAdcLoadCalibration_s:
tsChannelsActive_t channels
tsAdcLoad_t conf[TS_CAL_NUM_RATES]

ctypedef tsAdcLoadCalibration_s tsAdcLoadCalibration_t

cdef struct tsAdcGain_s:
uint32_t rate
int8_t[8] gain


cdef struct tsAdcBranchGain_s:
tsChannelsActive_t channels
tsAdcGain_s conf[TS_CAL_NUM_RATES]

ctypedef tsAdcBranchGain_s tsAdcBranchGain_t

cdef struct tsAdcCalibration_s:
uint8_t branchFineGain[8]
tsAdcLoadCalibration_t loadCal[TS_CAL_NUM_LOADS]
tsAdcBranchGain_t branchFineGain[TS_CAL_NUM_LOADS]

ctypedef tsAdcCalibration_s tsAdcCalibration_t

Expand All @@ -46,12 +91,6 @@ cdef extern from "ts_calibration.h":

ctypedef tsChannelCtrl_s tsChannelCtrl_t

cdef struct tsScopeCalibration_s:
tsChannelCalibration_t afeCal[4]
tsAdcCalibration_t adcCal

ctypedef tsScopeCalibration_s tsScopeCalibration_t

int32_t thunderscopeChanCalibrationSet(tsHandle_t ts, uint32_t channel, tsChannelCalibration_t* cal)

int32_t thunderscopeChanCalibrationGet(tsHandle_t ts, uint32_t channel, tsChannelCalibration_t* cal)
Expand All @@ -61,3 +100,5 @@ cdef extern from "ts_calibration.h":
int32_t thunderscopeAdcCalibrationGet(tsHandle_t ts, tsAdcCalibration_t* cal)

int32_t thunderscopeCalibrationManualCtrl(tsHandle_t ts, uint32_t channel, tsChannelCtrl_t* ctrl)

int32_t thunderscopeCalibrationManualAdcFineGain(tsHandle_t ts, uint8_t[8] fineGain)
13 changes: 12 additions & 1 deletion bindings/python/tslitex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cdef class Channel:
def Calibration(self):
cdef int32_t retVal
cdef ts_calibration.tsChannelCalibration_t calibration
retVal = ts_calibration.thunderscopeChanCalibrationSet(self.dev, self._channel, &calibration)
retVal = ts_calibration.thunderscopeChanCalibrationGet(self.dev, self._channel, &calibration)
if retVal != tslitex.TS_STATUS_OK:
raise ValueError(f"Failed to get Channel {self._channel} Calibration ({retVal})")
return calibration
Expand Down Expand Up @@ -202,6 +202,17 @@ cdef class Thunderscope:
if retVal != tslitex.TS_STATUS_OK:
raise ValueError(f"Failed to get ADC Calibration ({retVal})")
return calibration

def ManualAdcFineGain(self, fineGain: bytearray[8]):
cdef int32_t retVal
cdef unsigned char[8] gain = fineGain

if len(fineGain) != 8:
raise ValueError("ADC Fine Gain must by exactyly 8 bytes")

retVal = ts_calibration.thunderscopeCalibrationManualAdcFineGain(self._tsHandle, <uint8_t*>&gain[0])
if retVal != tslitex.TS_STATUS_OK:
raise ValueError(f"Failed to manually set ADC FineGain Parameters {fineGain}")

def firmwareUpdate(self, bitfile):
if type(bitfile) is not bytes:
Expand Down
190 changes: 80 additions & 110 deletions doc/data/fcal.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,123 +15,68 @@
"type": "string",
"description": "UTC date/time in ISO 8601 format"
},
"channel1": {
"type": "object",
"frontend": {
"type": "array",
"maxItems": 4,
"properties": {
"attenuatorScale": {
"type": "number"
"channel": {
"type": "integer"
},
"paths": {
"type": "array",
"items": {
"$ref": "/schemas/channelPathCalibration"
}
},
"pgaLoadScales":{
"type": "array",
"items": {
"$ref": "/schemas/pgaLoadScale"
}
}
}
},
"channel2": {
"type": "object",
"properties": {
"attenuatorScale": {
"type": "number"
},
"paths": {
"path": {
"type": "array",
"items": {
"$ref": "/schemas/channelPathCalibration"
}
},
"pgaLoadScales":{
"type": "array",
"items": {
"$ref": "/schemas/pgaLoadScale"
}
}
}
},
"channel3": {
"adc":{
"type": "object",
"properties": {
"attenuatorScale": {
"type": "number"
},
"paths": {
"loadScale": {
"type": "array",
"items": {
"$ref": "/schemas/channelPathCalibration"
"properties": {
"channel": {
"type": "array",
"items": {
"type": "integer"
}
},
"rateScale": {
"type" : "array",
"items": {
"$ref": "/schemas/adcRateScales"
}
}
}
},
"pgaLoadScales":{
"branchGain": {
"type": "array",
"items": {
"$ref": "/schemas/pgaLoadScale"
"properties": {
"channel": {
"type": "array",
"items": {
"type": "integer"
}
},
"rateGain": {
"type" : "array",
"items": {
"$ref": "/schemas/adcRateGain"
}
}
}
}
}
},
"channel4": {
"type": "object",
"properties": {
"attenuatorScale": {
"type": "number"
},
"paths": {
"type": "array",
"items": {
"$ref": "/schemas/channelPathCalibration"
}
},
"pgaLoadScales":{
"type": "array",
"items": {
"$ref": "/schemas/pgaLoadScale"
}
}
}
},
"adc":{
"type": "object",
"properties": {
"fineGainBranch1": {
"type": "number"
},
"fineGainBranch2": {
"type": "number"
},
"fineGainBranch3": {
"type": "number"
},
"fineGainBranch4": {
"type": "number"
},
"fineGainBranch5": {
"type": "number"
},
"fineGainBranch6": {
"type": "number"
},
"fineGainBranch7": {
"type": "number"
},
"fineGainBranch8": {
"type": "number"
}
}
}
},
"required": [
"version",
"serial",
"channel1",
"channel2",
"channel3",
"channel4",
"frontend",
"adc"
],
"$defs": {
Expand All @@ -143,16 +88,19 @@
"pgaPreampGain": {
"enum": ["high", "low"]
},
"pgaLadderAttenuator": {
"type": "number"
"pgaLadder": {
"type": "integer"
},
"trimDPot": {
"type": "integer"
},
"trimScaleDac": {
"trimDacScale": {
"type": "number"
},
"trimOffsetDacScale": {
"trimDacZeroM": {
"type": "number"
},
"trimOffsetDacZero": {
"trimDacZeroC": {
"type": "number"
},
"bufferInputVpp": {
Expand All @@ -161,33 +109,55 @@
},
"required": [
"pgaPreampGain",
"pgaLadderAttenuator",
"trimScaleDac",
"trimOffsetDacScale",
"trimOffsetDacZero",
"pgaLadder",
"trimDPot",
"trimDacScale",
"trimDacZeroM",
"trimDacZeroC",
"bufferInputVpp"
]
},
"pgaLoadScale": {
"$id": "https://example.com/schemas/pgaLoadScale",
"adcRateScale": {
"$id": "https://example.com/schemas/adcRateScale",
"title": "PGA Load Scale",
"type": "object",
"properties": {
"sampleRate": {
"type": "number"
},
"channelCount": {
"type": "number"
"rate": {
"type": "integer"
},
"scale": {
"type": "number"
"type": "array",
"Items": {
"type": "number"
}
}
},
"required": [
"sampleRate",
"channelCount",
"rate",
"scale"
]
},
"adcRateGain": {
"$id": "https://example.com/schemas/adcRateGain",
"title": "ADC Rate Gain",
"type": "object",
"properties": {
"rate": {
"type": "integer"
},
"gain": {
"type": "array",
"minItems": 8,
"maxItems": 8,
"items": {
"type": "integer"
}
}
},
"required": [
"rate",
"gain"
]
}
}
}
Loading
Loading