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
  • Hi  ,

    I'll contact the product owner and get back to you.

    Regards,
    Jo

  • Hello, has the product owner had a chance to review this topic? Thank you!

  • Hi,

      Sequences can be used with statistics block.

      However the AD5940_ClksCalculate() function is not defined for the case when stat block is enabled.

     You may have to multiply "waitclks" obtained by AD5940_ClksCalculate() by " stat_cfg.StatSample" number to get the final no. of wait clks required.

  • Ok, thank you again.  I was able to get the SINC2_NOTCH to pipe data to the FIFO with the 8 samples requested by the statistics mean engine. But when I select the source to be MEAN the FIfoCnt is always 0. Any ideas on where and when to properly setup the FIFO source? 

  • Hi,

    When FIFOSrc = FIFOMEAN, Are you reading FIFO count value after DATAFIFOTHRESH flag is asserted?

    What is the .FifoThresh value you have set?

  • I set the FifoThresh to the buffer size for the SWV readings (1024 per the SWV example). I also read and display in the terminal the FIFO count at each call to AFEINTSRC_CUSTOMINT0. When things are working and with SINC2 filter this increments at each step of the square wave DAC load, but when the source for the FIFO is set to FIFOMEAN, then this reads only as 0 at each SWV DAC load. I suspect that the configuration to have the FIFO fill with the statistic engine is not correct or the FIFO can not be filled from the statistic engine with the sequencer?  Thanks again for the help!!!

  • Hi,

            FIFO count reads 1 or more only after data is getting filled in it. FIFOMEAN may not be loaded for each DAC load.

            You may set 

    fifo_cfg.FIFOThresh = 4

    fifo_cfg.FIFOSrc = FIFOSRC_MEAN;

            and check FIFO count inside interrupt ISR

     if(IntFlag&AFEINTSRC_DATAFIFOTHRESH)

    {

    ----Check FIFO count here

    }

    Expected value of FIFO count is 4.

  • AD5940_ClksCalculate() takes clks_cal.DataCount as a parameter and multiplier.  So for an stats mean of 8 is setting clks_cal.DataCount =8 the same as using clks_cal.DataCount=1 and multiplying the returned WaitClks by 8?

  • What would the proper ADC Sequence generation be for using the MEAN? This would be in the AppSWVSeqADCCtrlGen() method of the SWV example.  

  • Additionally, why set the FIFOThresh  = 4 or anything less than the buffer size?  I want the ADC and stats engine to keep filling the FIFO at the required SWV sample times. Until the entire square wave is run, I don't need to collect the ADC data. This is how the SWV example is implemented from Analog Devices. Is there a reason for this change required to get the stats engine to work and the MEANs to pipe into the FIFO?  Thanks for clarifying!!!

  • 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.

  • 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? 

Reply
  • 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? 

Children
No Data