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,

    There is a

    - statistics block to process mean and std deviation of ADC output and

    - an averaging filter after Sinc3 filter that feeds averaged Sinc3 output to DFT block.

    For enabling the statistics block,

    Set in code as you did:

    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);

    fifo_cfg.FIFOSrc = FIFOSRC_SINC3; //FIFOSRC_MEAN gives statistic mean of "statsample" number of ADC output data. This output is what appears before Sinc2/Sinc3 filters.

    AD5940_FIFOCfg(&fifo_cfg);

    For enabling this averaging filter,

    Set in the code:

    lprtia_cal.DftCfg.DftSrc = DFTSRC_AVG;

    dsp_cfg.ADCFilterCfg.ADCAvgNum = ADCAVGNUM_2;  //Choose from available options

    Both can be enabled as the same time.

  • Thank you for the feedback. Is the sequencer and statistic block capable of being used together?  If so, does the conversion time waitClks need to be increased to allow the MEAN samples to be collected?

    In the SWV AppSWVSeqADCCtrlGen function, does the WaitClks need to be adjusted?

    AD5940_ClksCalculate(&clks_cal, &WaitClks);

    AD5940_SEQGenCtrl(bTRUE);
    AD5940_SEQGpioCtrlS(AGPIO_Pin2);
    // DEBUG: Select SINC2NOTCH for mean stats
    AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE);
    //AD5940_AFECtrlS(AFECTRL_ADCPWR, bTRUE);
    AD5940_SEQGenInsert(SEQ_WAIT(16*100)); /* wait 100us for reference power up */
    AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE); /* Start ADC convert and DFT */
    AD5940_SEQGenInsert(SEQ_WAIT(WaitClks)); /* wait for first data ready */
    AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_ADCCNV, bFALSE); /* Stop ADC */
    AD5940_SEQGpioCtrlS(0);

    The code block below appears to match your code, the difference is the fifo_cfg.FIFOSrc = FIFOSRC_SINC3. Are you saying that this is using the statistics block even though the FIFOSrc is set to SINC3?  

    /**
    * 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 8 points and calculate mean.
    AD5940_StatisticCfgS(&stat_cfg);

    /* Reconfigure FIFO, The Rtia calibration function may generate data that stored to FIFO */

    // Below if for MEAN calculation into the FIFO (This does NOT work)
    fifo_cfg.FIFOEn = bTRUE;
    fifo_cfg.FIFOMode = FIFOMODE_FIFO;
    fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    fifo_cfg.FIFOSrc = FIFOSRC_MEAN;
    fifo_cfg.FIFOThresh = AppSWVCfg.FifoThresh;
    AD5940_FIFOCfg(&fifo_cfg);

    // Below is the single sample into the FIFO (This works)
    /*
    AD5940_FIFOCtrlS(FIFOSRC_SINC3, bFALSE); // Disable FIFO firstly
    fifo_cfg.FIFOEn = bTRUE;
    fifo_cfg.FIFOSrc = FIFOSRC_SINC3;
    fifo_cfg.FIFOThresh = AppSWVCfg.FifoThresh; // Change FIFO parameters
    fifo_cfg.FIFOMode = FIFOMODE_FIFO;
    fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    AD5940_FIFOCfg(&fifo_cfg);
    */

  • Hi,

    The statistics block can be defined inside AD5940PlatformCfg() function in AD5940.c 

    as it is part of initializing.

    Since Statistics bock is enabled, FIFOSRC_SINC3 takes the mean data output form ADC after it is passed through Sinc2 (if Sinc2 is enabled).

  • Thank you! Can the sequencer be used with the statistic block and does the wait clocks need to be increased to allow for the multiple conversions to occur?

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

Reply Children
No Data