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

Reply
  • 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);
    */

Children