Post Go back to editing

Mean filtering of SWV FIFO data

Category: Software
Product Number: AD5940
Software Version: NA

Using the ADCMeanFifo example: https://github.com/analogdevicesinc/ad5940-examples/blob/master/examples/AD5940_ADC/AD5940_ADCMeanFIFO.c

I tried modifying the SWV example in the SqrWaveVoltammetry.c AppSWVInit function with the following.

// Statistic block receive data from SINC2+Notch block. Note the diagram in datasheet page 51 PrM.
// The SINC3 can be bypassed optionally. SINC2 cannot be bypassed.
stat_cfg.StatDev = STATDEV_1; /* Not used. */
stat_cfg.StatEnable = bTRUE;
stat_cfg.StatSample = STATSAMPLE_8; /* Sample 64 points and calculate mean. */
AD5940_StatisticCfgS(&stat_cfg);

/* Reconfigure FIFO, The Rtia calibration function may generate data that stored to FIFO */
AD5940_FIFOCtrlS(FIFOSRC_SINC3, bFALSE); /* Disable FIFO firstly */
fifo_cfg.FIFOEn = bTRUE; /* We will enable FIFO after all parameters configured */
fifo_cfg.FIFOMode = FIFOMODE_FIFO;
fifo_cfg.FIFOSize = FIFOSIZE_4KB; /* 4kB for FIFO, The reset 4kB for sequencer */
// DEBUG: Try changing between SINC and MEAN
//fifo_cfg.FIFOSrc = FIFOSRC_SINC3;
fifo_cfg.FIFOSrc = FIFOSRC_MEAN;
fifo_cfg.FIFOThresh = AppSWVCfg.FifoThresh; /* Change FIFO paramters */
AD5940_FIFOCfg(&fifo_cfg);

If I leave the FIFOSrc set to FIFOSRC_SINC3, then I get normal data. If I change to FIFOSRC_MEAN then there is data (FIFO Count returns 0).  

What is the proper way to setup averaging/mean? 

Is it correct to assume that the mean calculation with take multiple samples back-to-back per the STATSAMPLE setting when triggered with SEQ2?  

Thanks!

Parents Reply
  • Hi,

    1) There is no change required inside AppSWVSeqADCCtrlGen() function for using MEAN feature of Statistics block other than increasing the waitclks value by rough estimation.

        Only change required is to define "AD5940_FIFOCfg(&fifo_cfg)" and "AD5940_StatisticCfgS(&stat_cfg)" functions inside AppSWVInit() with desired configuration parameters similar to example shown in AD5940_ADCMeanFIFO.c 

    3) I said FIFOThresh = 4 as an example to verify that FIFO count also gets updated to 4 (as it is quick to verify with small threshold number). It is not for the final SWV code.

Children
  • I tried the test with FIFOThresh=4. The AFEINTSRC_DATAFIFOTHRESH ISR never triggered. Please review the below code.

    This is my AppSWVInit() setup:

    /**
    * Statistic block receive data from SINC2+Notch block. Note the diagram in datasheet page 51.
    * The SINC3 can be bypassed optionally. SINC2 cannot be bypassed.
    * */
    stat_cfg.StatDev = STATDEV_1; // Not used.
    stat_cfg.StatEnable = bTRUE;
    stat_cfg.StatSample = STATSAMPLE_8; // Sample 8 points and calculate mean.
    AD5940_StatisticCfgS(&stat_cfg);

    /* Reconfigure FIFO, The Rtia calibration function may generate data that stored to FIFO */
    AD5940_FIFOCtrlS(FIFOSRC_MEAN, bFALSE); // Disable FIFO firstly
    fifo_cfg.FIFOEn = bTRUE;
    fifo_cfg.FIFOSrc = FIFOSRC_MEAN;
    //fifo_cfg.FIFOThresh = AppSWVCfg.FifoThresh; // Change FIFO parameters
    fifo_cfg.FIFOThresh = 4; // Change FIFO parameters
    fifo_cfg.FIFOMode = FIFOMODE_FIFO;
    fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    AD5940_FIFOCfg(&fifo_cfg);

    Here is my AppSWVSeqADCCtrlGen() sequence setup:

    clks_cal.DataCount = 1; /* Sample one point everytime */
    clks_cal.DataType = DATATYPE_SINC2; //DEBUG: Changed from SINC3
    clks_cal.ADCSinc3Osr = AppSWVCfg.ADCSinc3Osr;
    clks_cal.ADCSinc2Osr = ADCSINC2OSR_22;
    clks_cal.ADCAvgNum = ADCAVGNUM_16; /* Don't care */
    clks_cal.RatioSys2AdcClk = AppSWVCfg.SysClkFreq/AppSWVCfg.AdcClkFreq;
    AD5940_ClksCalculate(&clks_cal, &WaitClks);

    AD5940_SEQGenCtrl(bTRUE);
    //AD5940_SEQGpioCtrlS(AGPIO_Pin2); //Not being used
    AD5940_AFECtrlS(AFECTRL_ADCPWR, bTRUE); // AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE); // Only use for NOTCH filter
    AD5940_SEQGenInsert(SEQ_WAIT(16*100)); /* wait 100us for reference power up */
    AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE); /* Start ADC convert */
    AD5940_SEQGenInsert(SEQ_WAIT(8*WaitClks)); /* wait for first data ready */
    AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_ADCCNV, bFALSE); //AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_ADCCNV|AFECTRL_SINC2NOTCH, bFALSE); /* Stop ADC */
    //AD5940_SEQGpioCtrlS(0); //Not being used
    AD5940_EnterSleepS();/* Goto hibernate */

    /* Sequence end. */
    error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen);
    AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */

    Do these settings appear correct? 

  • If I modify this code with fifo_cfg.FIFOSrc = FIFOSRC_SINC2NOTCH, then I get the FIFOCNT incrementing by the stat sample count. The FIFO is filling with the ADC samples that should be feeding into the stats engine. In other words, the stats engine is taking the required number of samples (STATSAMPLE_8) but the MEAN is not going into the FIFO? 

  • Hi,

      To check the FIFOMEAN part, could you please first just run the AD5940_ADCMeanFIFO example to see the output.

    It would help understand how fifomean gets filled, and delay required for output.