okay, we are seriously close to a first beta. almost everything works now, and works WELL
This commit is contained in:
parent
b0b0feb7b2
commit
e3ef13ecc3
58
Impedance.c
58
Impedance.c
|
|
@ -81,22 +81,30 @@ int32_t AppIMPCtrl(uint32_t Command, void *pPara)
|
||||||
{
|
{
|
||||||
case IMPCTRL_START:
|
case IMPCTRL_START:
|
||||||
{
|
{
|
||||||
WUPTCfg_Type wupt_cfg;
|
// CRITICAL CHANGE: Use Manual Triggering for Sweep to avoid timing hazards
|
||||||
if(AD5940_WakeUp(10) > 10) return AD5940ERR_WAKEUP;
|
if(AppIMPCfg.SweepCfg.SweepEn)
|
||||||
if(AppIMPCfg.IMPInited == bFALSE) return AD5940ERR_APPERROR;
|
{
|
||||||
|
// Trigger first sequence manually
|
||||||
wupt_cfg.WuptEn = bTRUE;
|
AD5940_SEQMmrTrig(SEQID_0);
|
||||||
wupt_cfg.WuptEndSeq = WUPTENDSEQ_A;
|
}
|
||||||
wupt_cfg.WuptOrder[0] = SEQID_0;
|
else
|
||||||
wupt_cfg.SeqxSleepTime[SEQID_0] = 4;
|
{
|
||||||
|
// Use WUPT for Continuous Measure (fixed frequency)
|
||||||
// Calculate Wakeup Time based on ODR
|
WUPTCfg_Type wupt_cfg;
|
||||||
// 32kHz clock. For 20Hz: 32000/20 = 1600 ticks.
|
if(AD5940_WakeUp(10) > 10) return AD5940ERR_WAKEUP;
|
||||||
uint32_t wait_cycles = (uint32_t)(AppIMPCfg.WuptClkFreq/AppIMPCfg.ImpODR);
|
if(AppIMPCfg.IMPInited == bFALSE) return AD5940ERR_APPERROR;
|
||||||
if(wait_cycles < 20) wait_cycles = 20; // Minimum safety guard
|
|
||||||
wupt_cfg.SeqxWakeupTime[SEQID_0] = wait_cycles - 4;
|
wupt_cfg.WuptEn = bTRUE;
|
||||||
|
wupt_cfg.WuptEndSeq = WUPTENDSEQ_A;
|
||||||
AD5940_WUPTCfg(&wupt_cfg);
|
wupt_cfg.WuptOrder[0] = SEQID_0;
|
||||||
|
wupt_cfg.SeqxSleepTime[SEQID_0] = 4;
|
||||||
|
|
||||||
|
uint32_t wait_cycles = (uint32_t)(AppIMPCfg.WuptClkFreq/AppIMPCfg.ImpODR);
|
||||||
|
if(wait_cycles < 20) wait_cycles = 20;
|
||||||
|
wupt_cfg.SeqxWakeupTime[SEQID_0] = wait_cycles - 4;
|
||||||
|
|
||||||
|
AD5940_WUPTCfg(&wupt_cfg);
|
||||||
|
}
|
||||||
|
|
||||||
AppIMPCfg.FifoDataCount = 0;
|
AppIMPCfg.FifoDataCount = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -424,6 +432,9 @@ AD5940Err AppIMPCheckFreq(float freq)
|
||||||
|
|
||||||
// Update Wait Times for all 3 measurements
|
// Update Wait Times for all 3 measurements
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
// Safety check: Ensure address is valid
|
||||||
|
if (AppIMPCfg.SeqWaitAddr[i] == 0) continue;
|
||||||
|
|
||||||
SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr + AppIMPCfg.SeqWaitAddr[i];
|
SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr + AppIMPCfg.SeqWaitAddr[i];
|
||||||
|
|
||||||
// CRITICAL FIX: Double the wait time for High Power Mode (>=80kHz)
|
// CRITICAL FIX: Double the wait time for High Power Mode (>=80kHz)
|
||||||
|
|
@ -633,9 +644,18 @@ int32_t AppIMPISR(void *pBuff, uint32_t *pCount)
|
||||||
AD5940_FIFORd((uint32_t *)pBuff, FifoCnt);
|
AD5940_FIFORd((uint32_t *)pBuff, FifoCnt);
|
||||||
AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
|
AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
|
||||||
|
|
||||||
// Check if sweep is done
|
// Update Frequency
|
||||||
if (AppIMPRegModify(pBuff, &FifoCnt) != AD5940ERR_OK) {
|
if (AppIMPRegModify(pBuff, &FifoCnt) == AD5940ERR_OK)
|
||||||
// If sweep is done, we might want to signal main loop
|
{
|
||||||
|
// CRITICAL: Manual Trigger Chain for Sweep
|
||||||
|
if(AppIMPCfg.SweepCfg.SweepEn)
|
||||||
|
{
|
||||||
|
// Only trigger next if we haven't reached the count
|
||||||
|
if(AppIMPCfg.FifoDataCount < AppIMPCfg.NumOfData)
|
||||||
|
{
|
||||||
|
AD5940_SEQMmrTrig(SEQID_0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AD5940_SleepKeyCtrlS(SLPKEY_UNLOCK);
|
AD5940_SleepKeyCtrlS(SLPKEY_UNLOCK);
|
||||||
|
|
|
||||||
27
main.c
27
main.c
|
|
@ -165,12 +165,19 @@ void ImpedanceShowResult(uint32_t *pData, uint32_t DataCount)
|
||||||
|
|
||||||
for(int i=0;i<DataCount;i++)
|
for(int i=0;i<DataCount;i++)
|
||||||
{
|
{
|
||||||
|
// Convert Polar (Mag, Phase) back to Cartesian (Real, Imag) for display
|
||||||
|
float mag = pImp[i].Magnitude;
|
||||||
|
float phase = pImp[i].Phase;
|
||||||
|
|
||||||
|
float real = mag * cosf(phase);
|
||||||
|
float imag = mag * sinf(phase);
|
||||||
|
|
||||||
printf("DATA,%.2f,%.4f,%.4f,%.4f,%.4f\n",
|
printf("DATA,%.2f,%.4f,%.4f,%.4f,%.4f\n",
|
||||||
freq,
|
freq,
|
||||||
pImp[i].Magnitude,
|
mag,
|
||||||
pImp[i].Phase*180/MATH_PI,
|
phase * 180.0f / MATH_PI,
|
||||||
pImp[i].Magnitude,
|
real,
|
||||||
pImp[i].Phase
|
imag
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,8 +284,8 @@ void process_command() {
|
||||||
printf(">> Calibrating HSTIARTIA_200...\n");
|
printf(">> Calibrating HSTIARTIA_200...\n");
|
||||||
if (AD5940_HSRtiaCal(&hsrtia_cal, &Res) == AD5940ERR_OK) {
|
if (AD5940_HSRtiaCal(&hsrtia_cal, &Res) == AD5940ERR_OK) {
|
||||||
printf("Calibrated Rtia: Mag = %f Ohm, Phase = %f\n", Res.Magnitude, Res.Phase);
|
printf("Calibrated Rtia: Mag = %f Ohm, Phase = %f\n", Res.Magnitude, Res.Phase);
|
||||||
// Optional: Update global config
|
// Update global config with actual calibrated value to fix scaling error
|
||||||
// pCfg->RtiaVal = Res.Magnitude;
|
pCfg->RtiaVal = Res.Magnitude;
|
||||||
} else {
|
} else {
|
||||||
printf("Calibration Failed\n");
|
printf("Calibration Failed\n");
|
||||||
}
|
}
|
||||||
|
|
@ -363,14 +370,6 @@ int main() {
|
||||||
AppIMPISR(AppBuff, &temp);
|
AppIMPISR(AppBuff, &temp);
|
||||||
if(temp > 0) {
|
if(temp > 0) {
|
||||||
ImpedanceShowResult(AppBuff, temp);
|
ImpedanceShowResult(AppBuff, temp);
|
||||||
|
|
||||||
// Check if sweep is done (simple check based on config)
|
|
||||||
AppIMPCfg_Type *pCfg;
|
|
||||||
AppIMPGetCfg(&pCfg);
|
|
||||||
if (pCfg->SweepCfg.SweepEn && pCfg->FifoDataCount >= pCfg->NumOfData) {
|
|
||||||
printf("DONE\n");
|
|
||||||
AD5940_Main_Cleanup(); // Ensure clean stop
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue