diff --git a/Impedance.c b/Impedance.c index 1e93d52..5d3d7bd 100644 --- a/Impedance.c +++ b/Impedance.c @@ -20,6 +20,7 @@ AppIMPCfg_Type AppIMPCfg = .ImpODR = 20.0, /* 20.0 Hz = 50ms period */ .NumOfData = -1, + .RealDataCount = -1, /* Default to no filtering */ .SysClkFreq = 16000000.0, .WuptClkFreq = 32000.0, .AdcClkFreq = 16000000.0, @@ -341,7 +342,10 @@ static AD5940Err AppIMPSeqMeasureGen(void) AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); - AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG, bFALSE); + // Stop ADC/DFT first, wait 10us, then stop WG + AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bFALSE); + AD5940_SEQGenInsert(SEQ_WAIT(16*10)); + AD5940_AFECtrlS(AFECTRL_WG, bFALSE); /* ----------------------------------------------------------------------- */ /* Measurement 2: Sensor Current (I) */ @@ -363,7 +367,10 @@ static AD5940Err AppIMPSeqMeasureGen(void) AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); - AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG, bFALSE); + // Stop ADC/DFT first, wait 10us, then stop WG + AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bFALSE); + AD5940_SEQGenInsert(SEQ_WAIT(16*10)); + AD5940_AFECtrlS(AFECTRL_WG, bFALSE); /* ----------------------------------------------------------------------- */ /* Measurement 3: Sensor Voltage (V) */ @@ -381,7 +388,11 @@ static AD5940Err AppIMPSeqMeasureGen(void) AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2)); - AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG|AFECTRL_ADCPWR, bFALSE); + // Stop ADC/DFT first, wait 10us, then stop WG and ADC Power + AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bFALSE); + AD5940_SEQGenInsert(SEQ_WAIT(16*10)); + AD5940_AFECtrlS(AFECTRL_WG|AFECTRL_ADCPWR, bFALSE); + AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\ AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\ AFECTRL_SINC2NOTCH, bFALSE); @@ -693,7 +704,19 @@ int32_t AppIMPISR(void *pBuff, uint32_t *pCount) AD5940_SleepKeyCtrlS(SLPKEY_UNLOCK); AppIMPDataProcess((int32_t*)pBuff, &FifoCnt); - *pCount = FifoCnt; + + // DUMMY POINT FILTERING + // If we are in sweep mode and have exceeded the user's requested count, + // discard this data packet so the host doesn't see the artifact. + if (AppIMPCfg.SweepCfg.SweepEn && AppIMPCfg.RealDataCount > 0) { + if (AppIMPCfg.FifoDataCount > AppIMPCfg.RealDataCount) { + *pCount = 0; // Discard + } else { + *pCount = FifoCnt; + } + } else { + *pCount = FifoCnt; + } } else { diff --git a/Impedance.h b/Impedance.h index 0b77ce7..4b9a662 100644 --- a/Impedance.h +++ b/Impedance.h @@ -21,6 +21,7 @@ typedef struct /* Application related parameters */ float ImpODR; /* */ int32_t NumOfData; /* By default it's '-1'. If you want the engine stops after get NumofData, then set the value here. Otherwise, set it to '-1' which means never stop. */ + int32_t RealDataCount; /* Actual number of valid points to report to host (used for dummy point filtering) */ float WuptClkFreq; /* The clock frequency of Wakeup Timer in Hz. Typically it's 32kHz. Leave it here in case we calibrate clock in software method */ float SysClkFreq; /* The real frequency of system clock */ float AdcClkFreq; /* The real frequency of ADC clock */ diff --git a/main.c b/main.c index 6cd43d0..a70b824 100644 --- a/main.c +++ b/main.c @@ -203,6 +203,7 @@ void Routine_Measure(float freq) { pCfg->SweepCfg.SweepEn = bFALSE; pCfg->SinFreq = freq; pCfg->NumOfData = -1; + pCfg->RealDataCount = -1; // Disable filtering pCfg->bParaChanged = bTRUE; if(AppIMPInit(AppBuff, APPBUFF_SIZE) == AD5940ERR_OK) { @@ -222,9 +223,15 @@ void Routine_Sweep(float start, float end, int steps) { pCfg->SweepCfg.SweepEn = bTRUE; pCfg->SweepCfg.SweepStart = start; pCfg->SweepCfg.SweepStop = end; - pCfg->SweepCfg.SweepPoints = steps; + + // DUMMY POINT STRATEGY: + // Request steps + 1 from the engine, but tell the ISR to only report 'steps'. + // The artifact will happen on the +1 point, which is discarded. + pCfg->SweepCfg.SweepPoints = steps + 1; + pCfg->NumOfData = steps + 1; + pCfg->RealDataCount = steps; // Stop reporting after this count + pCfg->SweepCfg.SweepLog = bTRUE; - pCfg->NumOfData = steps; pCfg->bParaChanged = bTRUE; if(AppIMPInit(AppBuff, APPBUFF_SIZE) == AD5940ERR_OK) {