yeeps
This commit is contained in:
parent
3e78b4eb75
commit
2945835eeb
|
|
@ -29,24 +29,24 @@ protected:
|
|||
bool event(QEvent *event) override;
|
||||
|
||||
private slots:
|
||||
// Serial Slots (MainWindow_Serial.cpp)
|
||||
// Serial Slots
|
||||
void handleSerialData();
|
||||
void connectToPort();
|
||||
void refreshPorts();
|
||||
void onPortError(QSerialPort::SerialPortError error);
|
||||
|
||||
// UI Slots (MainWindow_UI.cpp / MainWindow.cpp)
|
||||
// UI Slots
|
||||
void onBlinkTimer();
|
||||
void onLPFChanged(int index);
|
||||
|
||||
// Action Slots (MainWindow_Actions.cpp)
|
||||
// Action Slots
|
||||
void checkDeviceId();
|
||||
void runCalibration();
|
||||
void startSweep();
|
||||
void toggleMeasurement();
|
||||
void toggleAmperometry();
|
||||
|
||||
// LSV Slots (MainWindow_Actions.cpp)
|
||||
// LSV Slots
|
||||
void startLSVBlank();
|
||||
void startLSVSample();
|
||||
void stopLSV();
|
||||
|
|
@ -54,18 +54,16 @@ private slots:
|
|||
void calibrateCellConstant();
|
||||
|
||||
private:
|
||||
// Initialization Methods
|
||||
void setupUi(); // In MainWindow_UI.cpp
|
||||
void loadSettings(); // In MainWindow.cpp
|
||||
void saveSettings(); // In MainWindow.cpp
|
||||
|
||||
// Logic Helpers
|
||||
void parseData(const QString &data); // In MainWindow_Serial.cpp
|
||||
void handleSwipe(QSwipeGesture *gesture); // In MainWindow.cpp
|
||||
void computeHilbert(); // In MainWindow_Actions.cpp
|
||||
void performCircleFit(); // In MainWindow_Actions.cpp
|
||||
void calculateLSVDiff(); // In MainWindow_Actions.cpp
|
||||
void setButtonBlinking(QPushButton *btn, bool blinking); // In MainWindow_UI.cpp
|
||||
// Split Implementation Methods
|
||||
void setupUi();
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
void parseData(const QString &data);
|
||||
void handleSwipe(QSwipeGesture *gesture);
|
||||
void computeHilbert();
|
||||
void performCircleFit();
|
||||
void calculateLSVDiff();
|
||||
void setButtonBlinking(QPushButton *btn, bool blinking);
|
||||
|
||||
QSerialPort *serial;
|
||||
QSettings *settings;
|
||||
|
|
@ -80,7 +78,7 @@ private:
|
|||
GraphWidget *lsvGraph;
|
||||
QTextEdit *logWidget;
|
||||
|
||||
// Layout Elements
|
||||
// Layout
|
||||
QTabWidget *tabWidget;
|
||||
QComboBox *portSelector;
|
||||
QPushButton *connectBtn;
|
||||
|
|
@ -94,7 +92,8 @@ private:
|
|||
QDoubleSpinBox *spinSweepStart;
|
||||
QDoubleSpinBox *spinSweepStop;
|
||||
QSpinBox *spinSweepPPD;
|
||||
QComboBox *comboRange;
|
||||
QComboBox *comboRangeLP; // New LP Range
|
||||
QComboBox *comboRangeHP; // New HP Range
|
||||
|
||||
// Shunt / De-embedding Configuration
|
||||
QCheckBox *checkShunt;
|
||||
|
|
@ -121,11 +120,11 @@ private:
|
|||
|
||||
double cellConstant = 1.0;
|
||||
|
||||
// State Flags
|
||||
bool isMeasuringImp = false;
|
||||
bool isMeasuringAmp = false;
|
||||
bool isSweeping = false;
|
||||
|
||||
// LSV State
|
||||
enum LSVState { LSV_IDLE, LSV_RUNNING_BLANK, LSV_RUNNING_SAMPLE };
|
||||
LSVState lsvState = LSV_IDLE;
|
||||
|
||||
|
|
@ -134,7 +133,7 @@ private:
|
|||
QVector<double> sweepReals;
|
||||
QVector<double> sweepImags;
|
||||
|
||||
// LSV Data Storage
|
||||
// LSV Data Storage for Diff Calculation
|
||||
struct LSVPoint { double voltage; double current; };
|
||||
QVector<LSVPoint> lsvBlankData;
|
||||
QVector<LSVPoint> lsvSampleData;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ void MainWindow::checkDeviceId() {
|
|||
|
||||
void MainWindow::runCalibration() {
|
||||
if (serial->isOpen()) {
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
serial->write("c\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -47,11 +48,14 @@ void MainWindow::startSweep() {
|
|||
double start = spinSweepStart->value();
|
||||
double stop = spinSweepStop->value();
|
||||
int ppd = spinSweepPPD->value();
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
|
||||
logWidget->append(QString(">> Starting Sweep (Range: %1, s %2 %3 %4)...").arg(rangeVal).arg(start).arg(stop).arg(ppd));
|
||||
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
// Ensure firmware has correct ranges before starting
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
|
||||
logWidget->append(QString(">> Starting Sweep (HP Range: %1, s %2 %3 %4)...").arg(hpVal).arg(start).arg(stop).arg(ppd));
|
||||
|
||||
serial->write(QString("s %1 %2 %3\n").arg(start).arg(stop).arg(ppd).toUtf8());
|
||||
|
||||
isSweeping = true;
|
||||
|
|
@ -73,9 +77,10 @@ void MainWindow::toggleMeasurement() {
|
|||
isMeasuringImp = false;
|
||||
} else {
|
||||
double freq = spinFreq->value();
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
serial->write(QString("m %1\n").arg(freq).toUtf8());
|
||||
|
||||
measureBtn->setText("Stop");
|
||||
|
|
@ -98,9 +103,10 @@ void MainWindow::toggleAmperometry() {
|
|||
isMeasuringAmp = false;
|
||||
} else {
|
||||
double bias = spinAmpBias->value();
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
serial->write(QString("a %1\n").arg(bias).toUtf8());
|
||||
|
||||
ampBtn->setText("Stop Amp");
|
||||
|
|
@ -122,11 +128,12 @@ void MainWindow::startLSVBlank() {
|
|||
double stop = spinLsvStop->value();
|
||||
int steps = spinLsvSteps->value();
|
||||
int duration = spinLsvDuration->value();
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
|
||||
logWidget->append(QString(">> Starting LSV Blank (Range: %1, %.1f to %.1f mV)...").arg(rangeVal).arg(start).arg(stop));
|
||||
logWidget->append(QString(">> Starting LSV Blank (LP Range: %1, %.1f to %.1f mV)...").arg(lpVal).arg(start).arg(stop));
|
||||
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
serial->write(QString("l %1 %2 %3 %4\n").arg(start).arg(stop).arg(steps).arg(duration).toUtf8());
|
||||
|
||||
lsvBlankBtn->setText("Stop Blank");
|
||||
|
|
@ -151,11 +158,12 @@ void MainWindow::startLSVSample() {
|
|||
double stop = spinLsvStop->value();
|
||||
int steps = spinLsvSteps->value();
|
||||
int duration = spinLsvDuration->value();
|
||||
int rangeVal = comboRange->currentData().toInt();
|
||||
int lpVal = comboRangeLP->currentData().toInt();
|
||||
int hpVal = comboRangeHP->currentData().toInt();
|
||||
|
||||
logWidget->append(QString(">> Starting LSV Sample (Range: %1, %.1f to %.1f mV)...").arg(rangeVal).arg(start).arg(stop));
|
||||
logWidget->append(QString(">> Starting LSV Sample (LP Range: %1, %.1f to %.1f mV)...").arg(lpVal).arg(start).arg(stop));
|
||||
|
||||
serial->write(QString("r %1\n").arg(rangeVal).toUtf8());
|
||||
serial->write(QString("r %1 %2\n").arg(lpVal).arg(hpVal).toUtf8());
|
||||
serial->write(QString("l %1 %2 %3 %4\n").arg(start).arg(stop).arg(steps).arg(duration).toUtf8());
|
||||
|
||||
lsvSampleBtn->setText("Stop Sample");
|
||||
|
|
|
|||
|
|
@ -40,7 +40,11 @@ void MainWindow::connectToPort() {
|
|||
ampBtn->setEnabled(false);
|
||||
spinAmpBias->setEnabled(false);
|
||||
btnCalCond->setEnabled(false);
|
||||
comboRange->setEnabled(false);
|
||||
|
||||
// Updated Range Controls
|
||||
comboRangeLP->setEnabled(false);
|
||||
comboRangeHP->setEnabled(false);
|
||||
|
||||
comboLPF->setEnabled(false);
|
||||
lsvBlankBtn->setEnabled(false);
|
||||
lsvSampleBtn->setEnabled(false);
|
||||
|
|
@ -80,7 +84,11 @@ void MainWindow::connectToPort() {
|
|||
ampBtn->setEnabled(true);
|
||||
spinAmpBias->setEnabled(true);
|
||||
btnCalCond->setEnabled(true);
|
||||
comboRange->setEnabled(true);
|
||||
|
||||
// Updated Range Controls
|
||||
comboRangeLP->setEnabled(true);
|
||||
comboRangeHP->setEnabled(true);
|
||||
|
||||
comboLPF->setEnabled(true);
|
||||
lsvBlankBtn->setEnabled(true);
|
||||
lsvSampleBtn->setEnabled(true);
|
||||
|
|
@ -111,7 +119,11 @@ void MainWindow::onPortError(QSerialPort::SerialPortError error) {
|
|||
ampBtn->setEnabled(false);
|
||||
spinAmpBias->setEnabled(false);
|
||||
btnCalCond->setEnabled(false);
|
||||
comboRange->setEnabled(false);
|
||||
|
||||
// Updated Range Controls
|
||||
comboRangeLP->setEnabled(false);
|
||||
comboRangeHP->setEnabled(false);
|
||||
|
||||
comboLPF->setEnabled(false);
|
||||
lsvBlankBtn->setEnabled(false);
|
||||
lsvSampleBtn->setEnabled(false);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ void MainWindow::setupUi() {
|
|||
portSelector->setMinimumWidth(120);
|
||||
|
||||
connectBtn = new QPushButton("Connect", this);
|
||||
// Disconnect color (Red 50%) will be set when connected, default is Connect
|
||||
connectBtn->setStyleSheet("background-color: rgba(255, 0, 0, 128); color: white; font-weight: bold;");
|
||||
// Default Connect Color (Greenish)
|
||||
connectBtn->setStyleSheet("background-color: rgba(0, 128, 0, 128); color: white; font-weight: bold;");
|
||||
|
||||
QPushButton *refreshBtn = new QPushButton("Refresh", this);
|
||||
refreshBtn->setStyleSheet("background-color: rgba(255, 255, 255, 178); color: black; font-weight: bold;");
|
||||
|
|
@ -44,11 +44,7 @@ void MainWindow::setupUi() {
|
|||
checkIdBtn = new QPushButton("Check ID", this);
|
||||
checkIdBtn->setStyleSheet("background-color: rgba(255, 255, 255, 166); color: black; font-weight: bold;");
|
||||
|
||||
calibrateBtn = new QPushButton("Calibrate HW", this);
|
||||
calibrateBtn->setStyleSheet("background-color: rgba(255, 255, 0, 102); color: white; font-weight: bold;");
|
||||
|
||||
row1->addWidget(checkIdBtn);
|
||||
row1->addWidget(calibrateBtn);
|
||||
|
||||
QFrame *sep2 = new QFrame(); sep2->setFrameShape(QFrame::VLine); sep2->setFrameShadow(QFrame::Sunken);
|
||||
row1->addWidget(sep2);
|
||||
|
|
@ -105,37 +101,55 @@ void MainWindow::setupUi() {
|
|||
QHBoxLayout *row2 = new QHBoxLayout();
|
||||
row2->setSpacing(8);
|
||||
|
||||
row2->addWidget(new QLabel("Range:"));
|
||||
comboRange = new QComboBox(this);
|
||||
// Full 26 Resistor List
|
||||
comboRange->addItem("200 Ω", 200);
|
||||
comboRange->addItem("1 kΩ", 1000);
|
||||
comboRange->addItem("2 kΩ", 2000);
|
||||
comboRange->addItem("3 kΩ", 3000);
|
||||
comboRange->addItem("4 kΩ", 4000);
|
||||
comboRange->addItem("6 kΩ", 6000);
|
||||
comboRange->addItem("8 kΩ", 8000);
|
||||
comboRange->addItem("10 kΩ", 10000);
|
||||
comboRange->addItem("12 kΩ", 12000);
|
||||
comboRange->addItem("16 kΩ", 16000);
|
||||
comboRange->addItem("20 kΩ", 20000);
|
||||
comboRange->addItem("24 kΩ", 24000);
|
||||
comboRange->addItem("30 kΩ", 30000);
|
||||
comboRange->addItem("32 kΩ", 32000);
|
||||
comboRange->addItem("40 kΩ", 40000);
|
||||
comboRange->addItem("48 kΩ", 48000);
|
||||
comboRange->addItem("64 kΩ", 64000);
|
||||
comboRange->addItem("85 kΩ", 85000);
|
||||
comboRange->addItem("96 kΩ", 96000);
|
||||
comboRange->addItem("100 kΩ", 100000);
|
||||
comboRange->addItem("120 kΩ", 120000);
|
||||
comboRange->addItem("128 kΩ", 128000);
|
||||
comboRange->addItem("160 kΩ", 160000);
|
||||
comboRange->addItem("196 kΩ", 196000);
|
||||
comboRange->addItem("256 kΩ", 256000);
|
||||
comboRange->addItem("512 kΩ", 512000);
|
||||
comboRange->setCurrentIndex(1); // Default 1k
|
||||
row2->addWidget(comboRange);
|
||||
// LP Range (Full List)
|
||||
row2->addWidget(new QLabel("LP Range:"));
|
||||
comboRangeLP = new QComboBox(this);
|
||||
comboRangeLP->addItem("200 Ω", 200);
|
||||
comboRangeLP->addItem("1 kΩ", 1000);
|
||||
comboRangeLP->addItem("2 kΩ", 2000);
|
||||
comboRangeLP->addItem("3 kΩ", 3000);
|
||||
comboRangeLP->addItem("4 kΩ", 4000);
|
||||
comboRangeLP->addItem("6 kΩ", 6000);
|
||||
comboRangeLP->addItem("8 kΩ", 8000);
|
||||
comboRangeLP->addItem("10 kΩ", 10000);
|
||||
comboRangeLP->addItem("12 kΩ", 12000);
|
||||
comboRangeLP->addItem("16 kΩ", 16000);
|
||||
comboRangeLP->addItem("20 kΩ", 20000);
|
||||
comboRangeLP->addItem("24 kΩ", 24000);
|
||||
comboRangeLP->addItem("30 kΩ", 30000);
|
||||
comboRangeLP->addItem("32 kΩ", 32000);
|
||||
comboRangeLP->addItem("40 kΩ", 40000);
|
||||
comboRangeLP->addItem("48 kΩ", 48000);
|
||||
comboRangeLP->addItem("64 kΩ", 64000);
|
||||
comboRangeLP->addItem("85 kΩ", 85000);
|
||||
comboRangeLP->addItem("96 kΩ", 96000);
|
||||
comboRangeLP->addItem("100 kΩ", 100000);
|
||||
comboRangeLP->addItem("120 kΩ", 120000);
|
||||
comboRangeLP->addItem("128 kΩ", 128000);
|
||||
comboRangeLP->addItem("160 kΩ", 160000);
|
||||
comboRangeLP->addItem("196 kΩ", 196000);
|
||||
comboRangeLP->addItem("256 kΩ", 256000);
|
||||
comboRangeLP->addItem("512 kΩ", 512000);
|
||||
comboRangeLP->setCurrentIndex(1); // Default 1k
|
||||
row2->addWidget(comboRangeLP);
|
||||
|
||||
// HP Range (Limited List)
|
||||
row2->addWidget(new QLabel("HP Range:"));
|
||||
comboRangeHP = new QComboBox(this);
|
||||
comboRangeHP->addItem("200 Ω", 200);
|
||||
comboRangeHP->addItem("1 kΩ", 1000);
|
||||
comboRangeHP->addItem("5 kΩ", 5000);
|
||||
comboRangeHP->addItem("10 kΩ", 10000);
|
||||
comboRangeHP->addItem("20 kΩ", 20000);
|
||||
comboRangeHP->addItem("40 kΩ", 40000);
|
||||
comboRangeHP->addItem("80 kΩ", 80000);
|
||||
comboRangeHP->addItem("160 kΩ", 160000);
|
||||
comboRangeHP->setCurrentIndex(1); // Default 1k
|
||||
row2->addWidget(comboRangeHP);
|
||||
|
||||
calibrateBtn = new QPushButton("Calibrate HW", this);
|
||||
calibrateBtn->setStyleSheet("background-color: rgba(255, 255, 0, 102); color: white; font-weight: bold;");
|
||||
row2->addWidget(calibrateBtn);
|
||||
|
||||
QFrame *sepRange = new QFrame(); sepRange->setFrameShape(QFrame::VLine); sepRange->setFrameShadow(QFrame::Sunken);
|
||||
row2->addWidget(sepRange);
|
||||
|
|
@ -258,7 +272,8 @@ void MainWindow::setupUi() {
|
|||
ampBtn->setEnabled(false);
|
||||
spinAmpBias->setEnabled(false);
|
||||
btnCalCond->setEnabled(false);
|
||||
comboRange->setEnabled(false);
|
||||
comboRangeLP->setEnabled(false);
|
||||
comboRangeHP->setEnabled(false);
|
||||
comboLPF->setEnabled(false);
|
||||
lsvBlankBtn->setEnabled(false);
|
||||
lsvSampleBtn->setEnabled(false);
|
||||
|
|
|
|||
122
main.c
122
main.c
|
|
@ -47,27 +47,16 @@ float LFOSCFreq = 32000.0;
|
|||
// Range / RTIA Management
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Full list of 26 supported ranges
|
||||
float RtiaCalibrationTable[26] = {
|
||||
200.0, 1000.0, 2000.0, 3000.0, 4000.0, 6000.0, 8000.0,
|
||||
10000.0, 12000.0, 16000.0, 20000.0, 24000.0, 30000.0, 32000.0,
|
||||
40000.0, 48000.0, 64000.0, 85000.0, 96000.0, 100000.0,
|
||||
120000.0, 128000.0, 160000.0, 196000.0, 256000.0, 512000.0
|
||||
};
|
||||
|
||||
uint32_t CurrentRtiaIndex = 1; // Default 1k
|
||||
uint32_t ConfigRtiaVal = 1000;
|
||||
// Current Configuration
|
||||
uint32_t ConfigLptiaVal = 1000; // Default LP: 1k
|
||||
uint32_t ConfigHstiaVal = 1000; // Default HP: 1k
|
||||
uint32_t CurrentLpTiaRf = LPTIARF_20K;
|
||||
|
||||
// Helper to find index for calibration table
|
||||
int GetRtiaIndex(uint32_t val) {
|
||||
for(int i=0; i<26; i++) {
|
||||
if((uint32_t)RtiaCalibrationTable[i] == val) return i;
|
||||
}
|
||||
return 1; // Default 1k
|
||||
}
|
||||
// Calibrated Values
|
||||
float CalibratedLptiaVal = 1000.0f;
|
||||
float CalibratedHstiaVal = 1000.0f;
|
||||
|
||||
// Map integer value to HSTIA Enum (Impedance)
|
||||
// Map integer value to HSTIA Enum (Impedance) - Limited Selection
|
||||
uint32_t GetHSTIARtia(uint32_t val) {
|
||||
switch(val) {
|
||||
case 200: return HSTIARTIA_200;
|
||||
|
|
@ -78,12 +67,11 @@ uint32_t GetHSTIARtia(uint32_t val) {
|
|||
case 40000: return HSTIARTIA_40K;
|
||||
case 80000: return HSTIARTIA_80K;
|
||||
case 160000: return HSTIARTIA_160K;
|
||||
// Note: HSTIA has fewer options than LPTIA. Map closest or default.
|
||||
default: return HSTIARTIA_1K;
|
||||
}
|
||||
}
|
||||
|
||||
// Map integer value to LPTIA Enum (Amperometric/Ramp)
|
||||
// Map integer value to LPTIA Enum (Amperometric/Ramp) - Massive Selection
|
||||
uint32_t GetLPTIARtia(uint32_t val) {
|
||||
switch(val) {
|
||||
case 200: return LPTIARTIA_200R;
|
||||
|
|
@ -175,7 +163,7 @@ void AD5940ImpedanceStructInit(void)
|
|||
pImpedanceCfg->SeqStartAddr = 0;
|
||||
pImpedanceCfg->MaxSeqLen = 512;
|
||||
pImpedanceCfg->RcalVal = 100.0;
|
||||
pImpedanceCfg->RtiaVal = RtiaCalibrationTable[CurrentRtiaIndex];
|
||||
pImpedanceCfg->RtiaVal = CalibratedHstiaVal; // Use Calibrated HP Value
|
||||
pImpedanceCfg->SinFreq = 1000.0;
|
||||
pImpedanceCfg->FifoThresh = 6;
|
||||
pImpedanceCfg->DacVoltPP = 600.0;
|
||||
|
|
@ -185,7 +173,7 @@ void AD5940ImpedanceStructInit(void)
|
|||
pImpedanceCfg->PswitchSel = SWP_CE0;
|
||||
pImpedanceCfg->NswitchSel = SWN_SE0;
|
||||
pImpedanceCfg->TswitchSel = SWT_SE0LOAD;
|
||||
pImpedanceCfg->HstiaRtiaSel = GetHSTIARtia(ConfigRtiaVal);
|
||||
pImpedanceCfg->HstiaRtiaSel = GetHSTIARtia(ConfigHstiaVal); // Use HP Selection
|
||||
pImpedanceCfg->BiasVolt = 0.0;
|
||||
pImpedanceCfg->SweepCfg.SweepEn = bFALSE;
|
||||
pImpedanceCfg->SweepCfg.SweepStart = 100.0f;
|
||||
|
|
@ -210,11 +198,12 @@ void AD5940AMPStructInit(void)
|
|||
pAMPCfg->AmpODR = 1.0;
|
||||
pAMPCfg->FifoThresh = 4;
|
||||
pAMPCfg->SensorBias = 0;
|
||||
pAMPCfg->LptiaRtiaSel = GetLPTIARtia(ConfigRtiaVal);
|
||||
pAMPCfg->LptiaRtiaSel = GetLPTIARtia(ConfigLptiaVal); // Use LP Selection
|
||||
pAMPCfg->LpTiaRl = LPTIARLOAD_10R;
|
||||
pAMPCfg->LpTiaRf = CurrentLpTiaRf;
|
||||
pAMPCfg->Vzero = 1100;
|
||||
pAMPCfg->ADCRefVolt = 1.82;
|
||||
pAMPCfg->RtiaCalValue.Magnitude = CalibratedLptiaVal; // Use Calibrated LP Value
|
||||
}
|
||||
|
||||
void AD5940RampStructInit(void)
|
||||
|
|
@ -238,10 +227,11 @@ void AD5940RampStructInit(void)
|
|||
pRampCfg->RampDuration = 10000;
|
||||
pRampCfg->SampleDelay = 1.0f;
|
||||
|
||||
pRampCfg->LPTIARtiaSel = GetLPTIARtia(ConfigRtiaVal);
|
||||
pRampCfg->LPTIARtiaSel = GetLPTIARtia(ConfigLptiaVal); // Use LP Selection
|
||||
pRampCfg->LPTIARloadSel = LPTIARLOAD_10R;
|
||||
pRampCfg->LpTiaRf = CurrentLpTiaRf;
|
||||
pRampCfg->AdcPgaGain = ADCPGA_1P5;
|
||||
pRampCfg->RtiaValue.Magnitude = CalibratedLptiaVal; // Use Calibrated LP Value
|
||||
}
|
||||
|
||||
static int32_t AD5940PlatformCfg(void)
|
||||
|
|
@ -354,9 +344,10 @@ void Routine_Measure(float freq) {
|
|||
AppIMPCfg_Type *pCfg;
|
||||
AppIMPGetCfg(&pCfg);
|
||||
AppIMPCleanup();
|
||||
|
||||
AD5940ImpedanceStructInit(); // Reload config with current HP settings
|
||||
|
||||
pCfg->WuptClkFreq = LFOSCFreq;
|
||||
pCfg->HstiaRtiaSel = GetHSTIARtia(ConfigRtiaVal);
|
||||
pCfg->RtiaVal = RtiaCalibrationTable[CurrentRtiaIndex];
|
||||
pCfg->SweepCfg.SweepEn = bFALSE;
|
||||
pCfg->SinFreq = freq;
|
||||
pCfg->NumOfData = -1;
|
||||
|
|
@ -378,9 +369,10 @@ void Routine_Sweep(float start, float end, int steps) {
|
|||
AppIMPCfg_Type *pCfg;
|
||||
AppIMPGetCfg(&pCfg);
|
||||
AppIMPCleanup();
|
||||
|
||||
AD5940ImpedanceStructInit(); // Reload config with current HP settings
|
||||
|
||||
pCfg->WuptClkFreq = LFOSCFreq;
|
||||
pCfg->HstiaRtiaSel = GetHSTIARtia(ConfigRtiaVal);
|
||||
pCfg->RtiaVal = RtiaCalibrationTable[CurrentRtiaIndex];
|
||||
pCfg->SweepCfg.SweepEn = bTRUE;
|
||||
pCfg->SweepCfg.SweepStart = start;
|
||||
pCfg->SweepCfg.SweepStop = end;
|
||||
|
|
@ -402,15 +394,13 @@ void Routine_Amperometric(float bias_mv) {
|
|||
else if (CurrentMode == MODE_RAMP) AppRAMPCtrl(APPCTRL_SHUTDOWN, 0);
|
||||
CurrentMode = MODE_AMPEROMETRIC;
|
||||
|
||||
printf(">> Starting Amperometry (Bias: %.1f mV, Range: %d)...\n", bias_mv, ConfigRtiaVal);
|
||||
printf(">> Starting Amperometry (Bias: %.1f mV, LP Range: %d)...\n", bias_mv, ConfigLptiaVal);
|
||||
|
||||
AppAMPCfg_Type *pCfg;
|
||||
AppAMPGetCfg(&pCfg);
|
||||
AD5940AMPStructInit();
|
||||
AD5940AMPStructInit(); // Reload config with current LP settings
|
||||
pCfg->SensorBias = bias_mv;
|
||||
pCfg->WuptClkFreq = LFOSCFreq;
|
||||
pCfg->LptiaRtiaSel = GetLPTIARtia(ConfigRtiaVal);
|
||||
pCfg->ReDoRtiaCal = bTRUE;
|
||||
pCfg->ReDoRtiaCal = bFALSE; // Use pre-calibrated value
|
||||
|
||||
if(AppAMPInit(AppBuff, APPBUFF_SIZE) == AD5940ERR_OK) {
|
||||
AppAMPCtrl(AMPCTRL_START, 0);
|
||||
|
|
@ -424,24 +414,17 @@ void Routine_LSV(float start_mv, float end_mv, int steps, int duration_ms) {
|
|||
else if (CurrentMode == MODE_AMPEROMETRIC) AppAMPCtrl(AMPCTRL_SHUTDOWN, 0);
|
||||
CurrentMode = MODE_RAMP;
|
||||
|
||||
printf(">> Starting LSV (%.1f to %.1f mV, %d steps, %d ms)...\n", start_mv, end_mv, steps, duration_ms);
|
||||
printf(">> Starting LSV (%.1f to %.1f mV, %d steps, %d ms, LP Range: %d)...\n", start_mv, end_mv, steps, duration_ms, ConfigLptiaVal);
|
||||
|
||||
AppRAMPCfg_Type *pCfg;
|
||||
AppRAMPGetCfg(&pCfg);
|
||||
AD5940RampStructInit();
|
||||
AD5940RampStructInit(); // Reload config with current LP settings
|
||||
|
||||
pCfg->RampStartVolt = start_mv;
|
||||
pCfg->RampPeakVolt = end_mv;
|
||||
pCfg->StepNumber = steps;
|
||||
pCfg->RampDuration = duration_ms;
|
||||
pCfg->LFOSCClkFreq = LFOSCFreq;
|
||||
pCfg->LPTIARtiaSel = GetLPTIARtia(ConfigRtiaVal);
|
||||
|
||||
// Use global calibration value
|
||||
pCfg->RtiaValue.Magnitude = RtiaCalibrationTable[CurrentRtiaIndex];
|
||||
pCfg->RtiaValue.Phase = 0;
|
||||
|
||||
pCfg->bRampOneDir = bTRUE; // Linear Sweep (not Cyclic)
|
||||
pCfg->bRampOneDir = bTRUE;
|
||||
pCfg->bParaChanged = bTRUE;
|
||||
|
||||
if(AppRAMPInit(AppBuff, APPBUFF_SIZE) == AD5940ERR_OK) {
|
||||
|
|
@ -473,6 +456,34 @@ void Routine_CalibrateSystem(void) {
|
|||
printf(">> Calibrating ADC Offset...\n");
|
||||
AD5940_ADCPGACal(&adcpga_cal);
|
||||
|
||||
// --- 1. Calibrate LPTIA (Low Power Loop) ---
|
||||
LPRTIACal_Type lprtia_cal;
|
||||
fImpPol_Type LpRes;
|
||||
memset(&lprtia_cal, 0, sizeof(lprtia_cal));
|
||||
lprtia_cal.AdcClkFreq = 16000000.0;
|
||||
lprtia_cal.SysClkFreq = 16000000.0;
|
||||
lprtia_cal.ADCSinc3Osr = ADCSINC3OSR_4;
|
||||
lprtia_cal.ADCSinc2Osr = ADCSINC2OSR_22;
|
||||
lprtia_cal.bPolarResult = bTRUE;
|
||||
lprtia_cal.fRcal = 100.0;
|
||||
lprtia_cal.LpTiaRtia = GetLPTIARtia(ConfigLptiaVal);
|
||||
lprtia_cal.LpAmpPwrMod = LPAMPPWR_NORM;
|
||||
lprtia_cal.bWithCtia = bFALSE;
|
||||
// Use a low frequency for LPTIA calibration
|
||||
lprtia_cal.fFreq = 100.0f;
|
||||
lprtia_cal.DftCfg.DftNum = DFTNUM_2048;
|
||||
lprtia_cal.DftCfg.DftSrc = DFTSRC_SINC3;
|
||||
lprtia_cal.DftCfg.HanWinEn = bTRUE;
|
||||
|
||||
printf(">> Calibrating LPTIA %d Ohm...\n", ConfigLptiaVal);
|
||||
if (AD5940_LPRtiaCal(&lprtia_cal, &LpRes) == AD5940ERR_OK) {
|
||||
printf("Calibrated LPTIA: Mag = %f Ohm, Phase = %f\n", LpRes.Magnitude, LpRes.Phase);
|
||||
CalibratedLptiaVal = LpRes.Magnitude;
|
||||
} else {
|
||||
printf("LPTIA Calibration Failed\n");
|
||||
}
|
||||
|
||||
// --- 2. Calibrate HSTIA (High Speed Loop) ---
|
||||
HSDACCfg_Type hsdac_cfg;
|
||||
hsdac_cfg.ExcitBufGain = EXCITBUFGAIN_0P25;
|
||||
hsdac_cfg.HsDacGain = HSDACGAIN_0P2;
|
||||
|
|
@ -480,7 +491,7 @@ void Routine_CalibrateSystem(void) {
|
|||
AD5940_HSDacCfgS(&hsdac_cfg);
|
||||
|
||||
HSRTIACal_Type hsrtia_cal;
|
||||
fImpPol_Type Res;
|
||||
fImpPol_Type HsRes;
|
||||
memset(&hsrtia_cal, 0, sizeof(hsrtia_cal));
|
||||
hsrtia_cal.fFreq = 1000.0f;
|
||||
hsrtia_cal.AdcClkFreq = 16000000.0;
|
||||
|
|
@ -492,19 +503,18 @@ void Routine_CalibrateSystem(void) {
|
|||
hsrtia_cal.HsTiaCfg.DiodeClose = bFALSE;
|
||||
hsrtia_cal.HsTiaCfg.HstiaBias = HSTIABIAS_1P1;
|
||||
hsrtia_cal.HsTiaCfg.HstiaCtia = 31;
|
||||
hsrtia_cal.HsTiaCfg.HstiaRtiaSel = GetHSTIARtia(ConfigRtiaVal);
|
||||
hsrtia_cal.HsTiaCfg.HstiaRtiaSel = GetHSTIARtia(ConfigHstiaVal);
|
||||
hsrtia_cal.HsTiaCfg.HstiaDeRtia = HSTIADERTIA_OPEN;
|
||||
hsrtia_cal.HsTiaCfg.HstiaDeRload = HSTIADERLOAD_OPEN;
|
||||
hsrtia_cal.DftCfg.DftNum = DFTNUM_16384;
|
||||
hsrtia_cal.DftCfg.DftSrc = DFTSRC_SINC3;
|
||||
|
||||
printf(">> Calibrating RTIA %d Ohm...\n", ConfigRtiaVal);
|
||||
if (AD5940_HSRtiaCal(&hsrtia_cal, &Res) == AD5940ERR_OK) {
|
||||
printf("Calibrated Rtia: Mag = %f Ohm, Phase = %f\n", Res.Magnitude, Res.Phase);
|
||||
RtiaCalibrationTable[CurrentRtiaIndex] = Res.Magnitude;
|
||||
pCfg->RtiaVal = Res.Magnitude;
|
||||
printf(">> Calibrating HSTIA %d Ohm...\n", ConfigHstiaVal);
|
||||
if (AD5940_HSRtiaCal(&hsrtia_cal, &HsRes) == AD5940ERR_OK) {
|
||||
printf("Calibrated HSTIA: Mag = %f Ohm, Phase = %f\n", HsRes.Magnitude, HsRes.Phase);
|
||||
CalibratedHstiaVal = HsRes.Magnitude;
|
||||
} else {
|
||||
printf("Calibration Failed\n");
|
||||
printf("HSTIA Calibration Failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -524,11 +534,13 @@ void process_command() {
|
|||
printf("CHIP_ID:0x%04X\n", id);
|
||||
}
|
||||
else if (cmd == 'r') {
|
||||
// r <lp_val> <hp_val>
|
||||
if (strlen(input_buffer) > 2) {
|
||||
uint32_t val = atoi(input_buffer + 2);
|
||||
ConfigRtiaVal = val;
|
||||
CurrentRtiaIndex = GetRtiaIndex(val);
|
||||
printf("RANGE_SET:%d\n", ConfigRtiaVal);
|
||||
int lp = 0, hp = 0;
|
||||
int count = sscanf(input_buffer + 2, "%d %d", &lp, &hp);
|
||||
if (count >= 1) ConfigLptiaVal = lp;
|
||||
if (count >= 2) ConfigHstiaVal = hp;
|
||||
printf("RANGE_SET LP:%d HP:%d\n", ConfigLptiaVal, ConfigHstiaVal);
|
||||
}
|
||||
}
|
||||
else if (cmd == 'f') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue