Index: AD5941_interface09302025/Impedance.c =================================================================== diff -u -r00e9a3fe8b32dd4867784af1134f7cc2904d579f -r449f6936bd3fd84d8c4da61448702ca24015d778 --- AD5941_interface09302025/Impedance.c (.../Impedance.c) (revision 00e9a3fe8b32dd4867784af1134f7cc2904d579f) +++ AD5941_interface09302025/Impedance.c (.../Impedance.c) (revision 449f6936bd3fd84d8c4da61448702ca24015d778) @@ -1,10 +1,10 @@ /*! - This Code has been modifed by MK, Aly Development, 09/11/2025 + This Code has been modifed by MK, Aly Development, 09/11/2025 * Changes: function AppIMPSeqMeasureGen() modified with additional wait times for settling as marked via additional usage of AD5940_SEQGenInsert() to update the impedance measurement sequence * Fixed start up behavior - * In future, can consider implementing RTD measurement as a sequence as well. - * Settling time may warrant further investigation, but is outside of current scope. - * Settling time reduced as configuration change to references seems to have fixed underlying issue. + * In future, can consider implementing RTD measurement as a sequence as well. + * Settling time may warrant further investigation, but is outside of current scope. + * Settling time reduced as configuration change to references seems to have fixed underlying issue. ***************************************************************************** @file: Impedance.c @@ -17,7 +17,7 @@ This software is proprietary to Analog Devices, Inc. and its licensors. By using this software you agree to the terms of the associated Analog Devices Software License Agreement. - + *****************************************************************************/ #include "ad5940.h" #include @@ -26,160 +26,166 @@ #include "Impedance.h" /* Default LPDAC resolution(2.5V internal reference). */ -#define DAC12BITVOLT_1LSB (2200.0f / 4095) //mV -#define DAC6BITVOLT_1LSB (DAC12BITVOLT_1LSB * 64) //mV +#define DAC12BITVOLT_1LSB (2200.0f / 4095) // mV +#define DAC6BITVOLT_1LSB (DAC12BITVOLT_1LSB * 64) // mV -//MK addition +// MK addition #define additionalSettingTimeMK 10 // in microseconds; (multiplied by 16, so 1.6M clocks on the 16MHz clock) -/* +/* Application configuration structure. Specified by user from template. The variables are usable in this whole application. It includes basic configuration for sequencer generator and application related parameters */ AppIMPCfg_Type AppIMPCfg = { - .bParaChanged = bFALSE, - .SeqStartAddr = 0, - .MaxSeqLen = 4, + .bParaChanged = bFALSE, + .SeqStartAddr = 0, + .MaxSeqLen = 4, - .SeqStartAddrCal = 0, - .MaxSeqLenCal = 0, + .SeqStartAddrCal = 0, + .MaxSeqLenCal = 0, - .ImpODR = 20.0, /* 20.0 Hz*/ - .NumOfData = 10, - .SysClkFreq = 16000000.0, - .WuptClkFreq = 32000.0, - .AdcClkFreq = 16000000.0, - .RcalVal = 10000.0, + .ImpODR = 20.0, /* 20.0 Hz*/ + .NumOfData = 10, + .SysClkFreq = 16000000.0, + .WuptClkFreq = 32000.0, + .AdcClkFreq = 16000000.0, + .RcalVal = 10000.0, - .DswitchSel = SWD_CE0, - .PswitchSel = SWP_CE0, - .NswitchSel = SWN_AIN1, - .TswitchSel = SWT_AIN1, + .DswitchSel = SWD_CE0, + .PswitchSel = SWP_CE0, + .NswitchSel = SWN_AIN1, + .TswitchSel = SWT_AIN1, - .PwrMod = AFEPWR_HP, + .PwrMod = AFEPWR_HP, - .HstiaRtiaSel = HSTIARTIA_5K, - .ExcitBufGain = EXCITBUFGAIN_2, - .HsDacGain = HSDACGAIN_1, - .HsDacUpdateRate = 7, - .DacVoltPP = 300.0, - .BiasVolt = 100.0, + .HstiaRtiaSel = HSTIARTIA_5K, + .ExcitBufGain = EXCITBUFGAIN_2, + .HsDacGain = HSDACGAIN_1, + .HsDacUpdateRate = 7, + .DacVoltPP = 300.0, + .BiasVolt = 100.0, - .SinFreq = 10000.0, /* 10kHz */ + .SinFreq = 10000.0, /* 10kHz */ - .DftNum = DFTNUM_16384, - .DftSrc = DFTSRC_SINC3, - .HanWinEn = bTRUE, + .DftNum = DFTNUM_16384, + .DftSrc = DFTSRC_SINC3, + .HanWinEn = bTRUE, - .AdcPgaGain = ADCPGA_1, - .ADCSinc3Osr = ADCSINC3OSR_2, - .ADCSinc2Osr = ADCSINC2OSR_22, + .AdcPgaGain = ADCPGA_1, + .ADCSinc3Osr = ADCSINC3OSR_2, + .ADCSinc2Osr = ADCSINC2OSR_22, - .ADCAvgNum = ADCAVGNUM_16, + .ADCAvgNum = ADCAVGNUM_16, - .SweepCfg.SweepEn = bTRUE, - .SweepCfg.SweepStart = 1000, - .SweepCfg.SweepStop = 100000.0, - .SweepCfg.SweepPoints = 101, - .SweepCfg.SweepLog = bFALSE, - .SweepCfg.SweepIndex = 0, + .SweepCfg.SweepEn = bTRUE, + .SweepCfg.SweepStart = 1000, + .SweepCfg.SweepStop = 100000.0, + .SweepCfg.SweepPoints = 101, + .SweepCfg.SweepLog = bFALSE, + .SweepCfg.SweepIndex = 0, - .FifoThresh = 4, - .IMPInited = bFALSE, - .StopRequired = bFALSE, + .FifoThresh = 4, + .IMPInited = bFALSE, + .StopRequired = bFALSE, }; /** - This function is provided for upper controllers that want to change + This function is provided for upper controllers that want to change application parameters specially for user defined parameters. */ -int32_t AppIMPGetCfg(void *pCfg) { - if (pCfg) { +int32_t AppIMPGetCfg(void *pCfg) +{ + if (pCfg) + { *(AppIMPCfg_Type **)pCfg = &AppIMPCfg; return AD5940ERR_OK; } return AD5940ERR_PARA; } -int32_t AppIMPCtrl(uint32_t Command, void *pPara) { +int32_t AppIMPCtrl(uint32_t Command, void *pPara) +{ - switch (Command) { - case IMPCTRL_START: - { - WUPTCfg_Type wupt_cfg; + switch (Command) + { + case IMPCTRL_START: + { + WUPTCfg_Type wupt_cfg; - if (AD5940_WakeUp(10) > 10) /* Wakeup AFE by read register, read 10 times at most */ - return AD5940ERR_WAKEUP; /* Wakeup Failed */ - if (AppIMPCfg.IMPInited == bFALSE) - return AD5940ERR_APPERROR; - /* Start it */ - wupt_cfg.WuptEn = bTRUE; - wupt_cfg.WuptEndSeq = WUPTENDSEQ_A; - wupt_cfg.WuptOrder[0] = SEQID_0; - wupt_cfg.SeqxSleepTime[SEQID_0] = 4; - wupt_cfg.SeqxWakeupTime[SEQID_0] = (uint32_t)(AppIMPCfg.WuptClkFreq / AppIMPCfg.ImpODR) - 4; - AD5940_WUPTCfg(&wupt_cfg); - AD5940_Delay10us(5000); // 50ms settling + if (AD5940_WakeUp(10) > 10) /* Wakeup AFE by read register, read 10 times at most */ + return AD5940ERR_WAKEUP; /* Wakeup Failed */ + if (AppIMPCfg.IMPInited == bFALSE) + return AD5940ERR_APPERROR; + /* Start it */ + wupt_cfg.WuptEn = bTRUE; + wupt_cfg.WuptEndSeq = WUPTENDSEQ_A; + wupt_cfg.WuptOrder[0] = SEQID_0; + wupt_cfg.SeqxSleepTime[SEQID_0] = 4; + wupt_cfg.SeqxWakeupTime[SEQID_0] = (uint32_t)(AppIMPCfg.WuptClkFreq / AppIMPCfg.ImpODR) - 4; + AD5940_WUPTCfg(&wupt_cfg); + AD5940_Delay10us(5000); // 50ms settling - AppIMPCfg.FifoDataCount = 0; /* restart */ - break; - } - case IMPCTRL_STOPNOW: - { - if (AD5940_WakeUp(10) > 10) /* Wakeup AFE by read register, read 10 times at most */ - return AD5940ERR_WAKEUP; /* Wakeup Failed */ - /* Start Wupt right now */ - AD5940_WUPTCtrl(bFALSE); - /* There is chance this operation will fail because sequencer could put AFE back - to hibernate mode just after waking up. Use STOPSYNC is better. */ - AD5940_WUPTCtrl(bFALSE); - break; - } - case IMPCTRL_STOPSYNC: - { - AppIMPCfg.StopRequired = bTRUE; - break; - } - case IMPCTRL_GETFREQ: - { - if (pPara == 0) - return AD5940ERR_PARA; - if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) - *(float *)pPara = AppIMPCfg.FreqofData; - else - *(float *)pPara = AppIMPCfg.SinFreq; - } - break; - case IMPCTRL_SHUTDOWN: - { - AppIMPCtrl(IMPCTRL_STOPNOW, 0); /* Stop the measurement if it's running. */ - /* Turn off LPloop related blocks which are not controlled automatically by hibernate operation */ - AFERefCfg_Type aferef_cfg; - LPLoopCfg_Type lp_loop; - memset(&aferef_cfg, 0, sizeof(aferef_cfg)); - AD5940_REFCfgS(&aferef_cfg); - memset(&lp_loop, 0, sizeof(lp_loop)); - AD5940_LPLoopCfgS(&lp_loop); - AD5940_EnterSleepS(); /* Enter Hibernate */ - } - break; - default: - break; + AppIMPCfg.FifoDataCount = 0; /* restart */ + break; } + case IMPCTRL_STOPNOW: + { + if (AD5940_WakeUp(10) > 10) /* Wakeup AFE by read register, read 10 times at most */ + return AD5940ERR_WAKEUP; /* Wakeup Failed */ + /* Start Wupt right now */ + AD5940_WUPTCtrl(bFALSE); + /* There is chance this operation will fail because sequencer could put AFE back + to hibernate mode just after waking up. Use STOPSYNC is better. */ + AD5940_WUPTCtrl(bFALSE); + break; + } + case IMPCTRL_STOPSYNC: + { + AppIMPCfg.StopRequired = bTRUE; + break; + } + case IMPCTRL_GETFREQ: + { + if (pPara == 0) + return AD5940ERR_PARA; + if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) + *(float *)pPara = AppIMPCfg.FreqofData; + else + *(float *)pPara = AppIMPCfg.SinFreq; + } + break; + case IMPCTRL_SHUTDOWN: + { + AppIMPCtrl(IMPCTRL_STOPNOW, 0); /* Stop the measurement if it's running. */ + /* Turn off LPloop related blocks which are not controlled automatically by hibernate operation */ + AFERefCfg_Type aferef_cfg; + LPLoopCfg_Type lp_loop; + memset(&aferef_cfg, 0, sizeof(aferef_cfg)); + AD5940_REFCfgS(&aferef_cfg); + memset(&lp_loop, 0, sizeof(lp_loop)); + AD5940_LPLoopCfgS(&lp_loop); + AD5940_EnterSleepS(); /* Enter Hibernate */ + } + break; + default: + break; + } return AD5940ERR_OK; } /* generated code snnipet */ -float AppIMPGetCurrFreq(void) { +float AppIMPGetCurrFreq(void) +{ if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) return AppIMPCfg.FreqofData; else return AppIMPCfg.SinFreq; } /* Application initialization */ -static AD5940Err AppIMPSeqCfgGen(void) { +static AD5940Err AppIMPSeqCfgGen(void) +{ AD5940Err error = AD5940ERR_OK; const uint32_t *pSeqCmd; uint32_t SeqLen; @@ -202,12 +208,14 @@ aferef_cfg.Hp1V8Ilimit = bFALSE; aferef_cfg.Lp1V1BuffEn = bFALSE; aferef_cfg.Lp1V8BuffEn = bFALSE; - /* LP reference control - turn off them to save power*/ + /* LP reference control - turn off them to save power*/ if (AppIMPCfg.BiasVolt != 0.0f) /* With bias voltage */ { aferef_cfg.LpBandgapEn = bTRUE; aferef_cfg.LpRefBufEn = bTRUE; - } else { + } + else + { aferef_cfg.LpBandgapEn = bFALSE; aferef_cfg.LpRefBufEn = bFALSE; } @@ -231,7 +239,7 @@ // HsLoopCfg.SWMatCfg.Pswitch = AppIMPCfg.PswitchSel; // HsLoopCfg.SWMatCfg.Nswitch = AppIMPCfg.NswitchSel; // HsLoopCfg.SWMatCfg.Tswitch = SWT_TRTIA | AppIMPCfg.TswitchSel; - //blanking switch matrix during config -MK, 09/08/2025 + // blanking switch matrix during config -MK, 09/08/2025 HsLoopCfg.SWMatCfg.Dswitch = 0; HsLoopCfg.SWMatCfg.Pswitch = 0; HsLoopCfg.SWMatCfg.Nswitch = 0; @@ -241,12 +249,15 @@ HsLoopCfg.WgCfg.WgType = WGTYPE_SIN; HsLoopCfg.WgCfg.GainCalEn = bTRUE; HsLoopCfg.WgCfg.OffsetCalEn = bTRUE; - if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) { + if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) + { AppIMPCfg.FreqofData = AppIMPCfg.SweepCfg.SweepStart; AppIMPCfg.SweepCurrFreq = AppIMPCfg.SweepCfg.SweepStart; AD5940_SweepNext(&AppIMPCfg.SweepCfg, &AppIMPCfg.SweepNextFreq); sin_freq = AppIMPCfg.SweepCurrFreq; - } else { + } + else + { sin_freq = AppIMPCfg.SinFreq; AppIMPCfg.FreqofData = sin_freq; } @@ -263,8 +274,10 @@ lpdac_cfg.LpDacVbiasMux = LPDACVBIAS_12BIT; /* Use Vbias to tuning BiasVolt. */ lpdac_cfg.LpDacVzeroMux = LPDACVZERO_6BIT; /* Vbias-Vzero = BiasVolt */ lpdac_cfg.DacData6Bit = 0x40 >> 1; /* Set Vzero to middle scale. */ - if (AppIMPCfg.BiasVolt < -1100.0f) AppIMPCfg.BiasVolt = -1100.0f + DAC12BITVOLT_1LSB; - if (AppIMPCfg.BiasVolt > 1100.0f) AppIMPCfg.BiasVolt = 1100.0f - DAC12BITVOLT_1LSB; + if (AppIMPCfg.BiasVolt < -1100.0f) + AppIMPCfg.BiasVolt = -1100.0f + DAC12BITVOLT_1LSB; + if (AppIMPCfg.BiasVolt > 1100.0f) + AppIMPCfg.BiasVolt = 1100.0f - DAC12BITVOLT_1LSB; lpdac_cfg.DacData12Bit = (uint32_t)((AppIMPCfg.BiasVolt + 1100.0f) / DAC12BITVOLT_1LSB); lpdac_cfg.DataRst = bFALSE; /* Do not reset data register */ lpdac_cfg.LpDacSW = LPDACSW_VBIAS2LPPA | LPDACSW_VBIAS2PIN | LPDACSW_VZERO2LPTIA | LPDACSW_VZERO2PIN | LPDACSW_VZERO2HSTIA; @@ -304,20 +317,22 @@ /* Stop here */ error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen); AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */ - if (error == AD5940ERR_OK) { + if (error == AD5940ERR_OK) + { AppIMPCfg.InitSeqInfo.SeqId = SEQID_1; AppIMPCfg.InitSeqInfo.SeqRamAddr = AppIMPCfg.SeqStartAddr; AppIMPCfg.InitSeqInfo.pSeqCmd = pSeqCmd; AppIMPCfg.InitSeqInfo.SeqLen = SeqLen; /* Write command to SRAM */ AD5940_SEQCmdWrite(AppIMPCfg.InitSeqInfo.SeqRamAddr, pSeqCmd, SeqLen); - } else + } + else return error; /* Error */ return AD5940ERR_OK; } - -static AD5940Err AppIMPSeqMeasureGen(void) { +static AD5940Err AppIMPSeqMeasureGen(void) +{ AD5940Err error = AD5940ERR_OK; const uint32_t *pSeqCmd; uint32_t SeqLen; @@ -343,19 +358,19 @@ sw_cfg.Nswitch = SWN_RCAL1; sw_cfg.Tswitch = SWT_RCAL1 | SWT_TRTIA; AD5940_SWMatrixCfgS(&sw_cfg); - + AD5940_AFECtrlS(AFECTRL_HSTIAPWR | AFECTRL_INAMPPWR | AFECTRL_EXTBUFPWR | AFECTRL_WG | AFECTRL_DACREFPWR | AFECTRL_HSDACPWR | AFECTRL_SINC2NOTCH, bTRUE); AD5940_AFECtrlS(AFECTRL_WG | AFECTRL_ADCPWR, bTRUE); /* Enable Waveform generator */ - //delay for signal settling DFT_WAIT + // delay for signal settling DFT_WAIT AD5940_SEQGenInsert(SEQ_WAIT(16 * 10)); - //mk extra wait time - AD5940_SEQGenInsert(SEQ_WAIT(16 * additionalSettingTimeMK)); // this is 100ms; 1600000 clock cycles at 16MHz + // mk extra wait time + AD5940_SEQGenInsert(SEQ_WAIT(16 * additionalSettingTimeMK)); // this is 100ms; 1600000 clock cycles at 16MHz AD5940_AFECtrlS(AFECTRL_ADCCNV | AFECTRL_DFT, bTRUE); /* Start ADC convert and DFT */ AD5940_SEQGenInsert(SEQ_WAIT(WaitClks)); - //wait for first data ready + // wait for first data ready AD5940_AFECtrlS(AFECTRL_ADCPWR | AFECTRL_ADCCNV | AFECTRL_DFT | AFECTRL_WG, bFALSE); /* Stop ADC convert and DFT */ /* Configure matrix for external Rz */ @@ -364,14 +379,14 @@ sw_cfg.Nswitch = AppIMPCfg.NswitchSel; sw_cfg.Tswitch = SWT_TRTIA | AppIMPCfg.TswitchSel; AD5940_SWMatrixCfgS(&sw_cfg); - AD5940_AFECtrlS(AFECTRL_ADCPWR | AFECTRL_WG, bTRUE); /* Enable Waveform generator */ - AD5940_SEQGenInsert(SEQ_WAIT(16 * 10)); //delay for signal settling DFT_WAIT + AD5940_AFECtrlS(AFECTRL_ADCPWR | AFECTRL_WG, bTRUE); /* Enable Waveform generator */ + AD5940_SEQGenInsert(SEQ_WAIT(16 * 10)); // delay for signal settling DFT_WAIT - //MK EXTRA WAIT TIME - AD5940_SEQGenInsert(SEQ_WAIT(16 * additionalSettingTimeMK)); // this is 100ms; 1600000 clock cycles at 16MHz + // MK EXTRA WAIT TIME + AD5940_SEQGenInsert(SEQ_WAIT(16 * additionalSettingTimeMK)); // this is 100ms; 1600000 clock cycles at 16MHz AD5940_AFECtrlS(AFECTRL_ADCCNV | AFECTRL_DFT, bTRUE); /* Start ADC convert and DFT */ - AD5940_SEQGenInsert(SEQ_WAIT(WaitClks)); /* wait for first data ready */ + AD5940_SEQGenInsert(SEQ_WAIT(WaitClks)); /* wait for first data ready */ AD5940_AFECtrlS(AFECTRL_ADCCNV | AFECTRL_DFT | AFECTRL_WG | AFECTRL_ADCPWR, bFALSE); /* Stop ADC convert and DFT */ sw_cfg.Dswitch = 0; sw_cfg.Pswitch = 0; @@ -387,21 +402,23 @@ error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen); AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */ - if (error == AD5940ERR_OK) { + if (error == AD5940ERR_OK) + { AppIMPCfg.MeasureSeqInfo.SeqId = SEQID_0; AppIMPCfg.MeasureSeqInfo.SeqRamAddr = AppIMPCfg.InitSeqInfo.SeqRamAddr + AppIMPCfg.InitSeqInfo.SeqLen; AppIMPCfg.MeasureSeqInfo.pSeqCmd = pSeqCmd; AppIMPCfg.MeasureSeqInfo.SeqLen = SeqLen; /* Write command to SRAM */ AD5940_SEQCmdWrite(AppIMPCfg.MeasureSeqInfo.SeqRamAddr, pSeqCmd, SeqLen); - } else + } + else return error; /* Error */ return AD5940ERR_OK; } - /* This function provide application initialize. It can also enable Wupt that will automatically trigger sequence. Or it can configure */ -int32_t AppIMPInit(uint32_t *pBuffer, uint32_t BufferSize) { +int32_t AppIMPInit(uint32_t *pBuffer, uint32_t BufferSize) +{ AD5940Err error = AD5940ERR_OK; SEQCfg_Type seq_cfg; FIFOCfg_Type fifo_cfg; @@ -430,18 +447,23 @@ /* Start sequence generator */ /* Initialize sequencer generator */ - if ((AppIMPCfg.IMPInited == bFALSE) || (AppIMPCfg.bParaChanged == bTRUE)) { - if (pBuffer == 0) return AD5940ERR_PARA; - if (BufferSize == 0) return AD5940ERR_PARA; + if ((AppIMPCfg.IMPInited == bFALSE) || (AppIMPCfg.bParaChanged == bTRUE)) + { + if (pBuffer == 0) + return AD5940ERR_PARA; + if (BufferSize == 0) + return AD5940ERR_PARA; AD5940_SEQGenInit(pBuffer, BufferSize); /* Generate initialize sequence */ error = AppIMPSeqCfgGen(); /* Application initialization sequence using either MCU or sequencer */ - if (error != AD5940ERR_OK) return error; + if (error != AD5940ERR_OK) + return error; /* Generate measurement sequence */ error = AppIMPSeqMeasureGen(); - if (error != AD5940ERR_OK) return error; + if (error != AD5940ERR_OK) + return error; AppIMPCfg.bParaChanged = bFALSE; /* Clear this flag as we already implemented the new configuration */ } @@ -456,7 +478,7 @@ // while (AD5940_INTCTestFlag(AFEINTC_1, AFEINTSRC_ENDSEQ) == bFALSE) //commented out, we're using intc1 for adc max check now // ; - AD5940_AFECtrlS(AFECTRL_WG, bFALSE); //added to avoid sine output when unwanted + AD5940_AFECtrlS(AFECTRL_WG, bFALSE); // added to avoid sine output when unwanted /* Measurement sequence */ AppIMPCfg.MeasureSeqInfo.WriteSRAM = bFALSE; AD5940_SEQInfoCfg(&AppIMPCfg.MeasureSeqInfo); @@ -472,15 +494,19 @@ } /* Modify registers when AFE wakeup */ -int32_t AppIMPRegModify(int32_t *const pData, uint32_t *pDataCount) { - if (AppIMPCfg.NumOfData > 0) { +int32_t AppIMPRegModify(int32_t *const pData, uint32_t *pDataCount) +{ + if (AppIMPCfg.NumOfData > 0) + { AppIMPCfg.FifoDataCount += *pDataCount / 4; - if (AppIMPCfg.FifoDataCount >= AppIMPCfg.NumOfData) { + if (AppIMPCfg.FifoDataCount >= AppIMPCfg.NumOfData) + { AD5940_WUPTCtrl(bFALSE); return AD5940ERR_OK; } } - if (AppIMPCfg.StopRequired == bTRUE) { + if (AppIMPCfg.StopRequired == bTRUE) + { AD5940_WUPTCtrl(bFALSE); return AD5940ERR_OK; } @@ -492,7 +518,8 @@ } /* Depending on the data type, do appropriate data pre-process before return back to controller */ -int32_t AppIMPDataProcess(int32_t *const pData, uint32_t *pDataCount) { +int32_t AppIMPDataProcess(int32_t *const pData, uint32_t *pDataCount) +{ uint32_t DataCount = *pDataCount; uint32_t ImpResCount = DataCount / 4; @@ -504,50 +531,53 @@ DataCount = (DataCount / 4) * 4; /* We expect RCAL data together with Rz data. One DFT result has two data in FIFO, real part and imaginary part. */ /* Convert DFT result to int32_t type */ - for (uint32_t i = 0; i < DataCount; i++) { + for (uint32_t i = 0; i < DataCount; i++) + { pData[i] &= 0x3ffff; /* @todo option to check ECC */ if (pData[i] & (1L << 17)) /* Bit17 is sign bit */ { pData[i] |= 0xfffc0000; /* Data is 18bit in two's complement, bit17 is the sign bit */ } } - for (uint32_t i = 0; i < ImpResCount; i++) { + for (uint32_t i = 0; i < ImpResCount; i++) + { iImpCar_Type *pDftRcal, *pDftRz; pDftRcal = pSrcData++; pDftRz = pSrcData++; float RzMag, RzPhase; float RcalMag, RcalPhase; - float outputValue=pDftRcal->Real; - float outputValue2=pDftRcal->Image; - float outputValue3=pDftRz->Real; - float outputValue4=pDftRz->Image; + float outputValue = pDftRcal->Real; + float outputValue2 = pDftRcal->Image; + float outputValue3 = pDftRz->Real; + float outputValue4 = pDftRz->Image; RcalMag = sqrt((float)pDftRcal->Real * pDftRcal->Real + (float)pDftRcal->Image * pDftRcal->Image); RcalPhase = atan2(-pDftRcal->Image, pDftRcal->Real); RzMag = sqrt((float)pDftRz->Real * pDftRz->Real + (float)pDftRz->Image * pDftRz->Image); RzPhase = atan2(-pDftRz->Image, pDftRz->Real); - #ifdef ADI_DEBUG - // ADI_Print(" pDftRcal->Real: %f", outputValue); - // ADI_Print(" pDftRcal->Image: %f", outputValue2); - // ADI_Print(" pDftRz->Real: %f", outputValue3); - // ADI_Print(" pDftRz->Image: %f", outputValue4); - ADI_Print(" RzMag: %f", RzMag); - ADI_Print(" RcalMag: %f", RcalMag); - ADI_Print(" RzPhase: %f", RzPhase); - ADI_Print(" RcalPhase: %f", RcalPhase); - #endif +#ifdef ADI_DEBUG + // ADI_Print(" pDftRcal->Real: %f", outputValue); + // ADI_Print(" pDftRcal->Image: %f", outputValue2); + // ADI_Print(" pDftRz->Real: %f", outputValue3); + // ADI_Print(" pDftRz->Image: %f", outputValue4); + ADI_Print(" RzMag: %f", RzMag); + ADI_Print(" RcalMag: %f", RcalMag); + ADI_Print(" RzPhase: %f", RzPhase); + ADI_Print(" RcalPhase: %f", RcalPhase); +#endif RzMag = RcalMag / RzMag * AppIMPCfg.RcalVal; RzPhase = RcalPhase - RzPhase; - //printf("V:%d,%d,I:%d,%d ",pDftRcal->Real,pDftRcal->Image, pDftRz->Real, pDftRz->Image); + // printf("V:%d,%d,I:%d,%d ",pDftRcal->Real,pDftRcal->Image, pDftRz->Real, pDftRz->Image); pOut[i].Magnitude = RzMag; pOut[i].Phase = RzPhase; } *pDataCount = ImpResCount; AppIMPCfg.FreqofData = AppIMPCfg.SweepCurrFreq; /* Calculate next frequency point */ - if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) { + if (AppIMPCfg.SweepCfg.SweepEn == bTRUE) + { AppIMPCfg.FreqofData = AppIMPCfg.SweepCurrFreq; AppIMPCfg.SweepCurrFreq = AppIMPCfg.SweepNextFreq; AD5940_SweepNext(&AppIMPCfg.SweepCfg, &AppIMPCfg.SweepNextFreq); @@ -559,7 +589,8 @@ /** */ -int32_t AppIMPISR(void *pBuff, uint32_t *pCount) { +int32_t AppIMPISR(void *pBuff, uint32_t *pCount) +{ uint32_t BuffCount; uint32_t FifoCnt; BuffCount = *pCount; @@ -570,17 +601,19 @@ return AD5940ERR_WAKEUP; /* Wakeup Failed */ AD5940_SleepKeyCtrlS(SLPKEY_LOCK); /* Prohibit AFE to enter sleep mode. */ - if (AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE) { + if (AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE) + { /* Now there should be 4 data in FIFO */ FifoCnt = (AD5940_FIFOGetCnt() / 4) * 4; - if (FifoCnt > BuffCount) { + if (FifoCnt > BuffCount) + { ///@todo buffer is limited. } AD5940_FIFORd((uint32_t *)pBuff, FifoCnt); AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH); AppIMPRegModify(pBuff, &FifoCnt); /* If there is need to do AFE re-configure, do it here when AFE is in active state */ - //AD5940_EnterSleepS(); /* Manually put AFE back to hibernate mode. This operation only takes effect when register value is ACTIVE previously */ + // AD5940_EnterSleepS(); /* Manually put AFE back to hibernate mode. This operation only takes effect when register value is ACTIVE previously */ AD5940_SleepKeyCtrlS(SLPKEY_UNLOCK); /* Allow AFE to enter sleep mode. */ /* Process data */ AppIMPDataProcess((int32_t *)pBuff, &FifoCnt); @@ -590,4 +623,3 @@ return 0; } -