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
52
Impedance.c
52
Impedance.c
|
|
@ -81,22 +81,30 @@ int32_t AppIMPCtrl(uint32_t Command, void *pPara)
|
|||
{
|
||||
case IMPCTRL_START:
|
||||
{
|
||||
WUPTCfg_Type wupt_cfg;
|
||||
if(AD5940_WakeUp(10) > 10) return AD5940ERR_WAKEUP;
|
||||
if(AppIMPCfg.IMPInited == bFALSE) return AD5940ERR_APPERROR;
|
||||
// CRITICAL CHANGE: Use Manual Triggering for Sweep to avoid timing hazards
|
||||
if(AppIMPCfg.SweepCfg.SweepEn)
|
||||
{
|
||||
// Trigger first sequence manually
|
||||
AD5940_SEQMmrTrig(SEQID_0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use WUPT for Continuous Measure (fixed frequency)
|
||||
WUPTCfg_Type wupt_cfg;
|
||||
if(AD5940_WakeUp(10) > 10) return AD5940ERR_WAKEUP;
|
||||
if(AppIMPCfg.IMPInited == bFALSE) return AD5940ERR_APPERROR;
|
||||
|
||||
wupt_cfg.WuptEn = bTRUE;
|
||||
wupt_cfg.WuptEndSeq = WUPTENDSEQ_A;
|
||||
wupt_cfg.WuptOrder[0] = SEQID_0;
|
||||
wupt_cfg.SeqxSleepTime[SEQID_0] = 4;
|
||||
wupt_cfg.WuptEn = bTRUE;
|
||||
wupt_cfg.WuptEndSeq = WUPTENDSEQ_A;
|
||||
wupt_cfg.WuptOrder[0] = SEQID_0;
|
||||
wupt_cfg.SeqxSleepTime[SEQID_0] = 4;
|
||||
|
||||
// Calculate Wakeup Time based on ODR
|
||||
// 32kHz clock. For 20Hz: 32000/20 = 1600 ticks.
|
||||
uint32_t wait_cycles = (uint32_t)(AppIMPCfg.WuptClkFreq/AppIMPCfg.ImpODR);
|
||||
if(wait_cycles < 20) wait_cycles = 20; // Minimum safety guard
|
||||
wupt_cfg.SeqxWakeupTime[SEQID_0] = wait_cycles - 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);
|
||||
AD5940_WUPTCfg(&wupt_cfg);
|
||||
}
|
||||
|
||||
AppIMPCfg.FifoDataCount = 0;
|
||||
break;
|
||||
|
|
@ -424,6 +432,9 @@ AD5940Err AppIMPCheckFreq(float freq)
|
|||
|
||||
// Update Wait Times for all 3 measurements
|
||||
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];
|
||||
|
||||
// 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_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
|
||||
|
||||
// Check if sweep is done
|
||||
if (AppIMPRegModify(pBuff, &FifoCnt) != AD5940ERR_OK) {
|
||||
// If sweep is done, we might want to signal main loop
|
||||
// Update Frequency
|
||||
if (AppIMPRegModify(pBuff, &FifoCnt) == AD5940ERR_OK)
|
||||
{
|
||||
// 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);
|
||||
|
|
|
|||
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++)
|
||||
{
|
||||
// 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",
|
||||
freq,
|
||||
pImp[i].Magnitude,
|
||||
pImp[i].Phase*180/MATH_PI,
|
||||
pImp[i].Magnitude,
|
||||
pImp[i].Phase
|
||||
mag,
|
||||
phase * 180.0f / MATH_PI,
|
||||
real,
|
||||
imag
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -277,8 +284,8 @@ void process_command() {
|
|||
printf(">> Calibrating HSTIARTIA_200...\n");
|
||||
if (AD5940_HSRtiaCal(&hsrtia_cal, &Res) == AD5940ERR_OK) {
|
||||
printf("Calibrated Rtia: Mag = %f Ohm, Phase = %f\n", Res.Magnitude, Res.Phase);
|
||||
// Optional: Update global config
|
||||
// pCfg->RtiaVal = Res.Magnitude;
|
||||
// Update global config with actual calibrated value to fix scaling error
|
||||
pCfg->RtiaVal = Res.Magnitude;
|
||||
} else {
|
||||
printf("Calibration Failed\n");
|
||||
}
|
||||
|
|
@ -363,14 +370,6 @@ int main() {
|
|||
AppIMPISR(AppBuff, &temp);
|
||||
if(temp > 0) {
|
||||
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