Post Go back to editing

Need to generate sine wave using AD5941?

Product Number: I want to generate sine wave using the AD5941?
Software Version: STM32 MCU + https://github.com/analogdevicesinc/ad5940-examples/tree/master/examples/AD5940_WG example code

Hi folks,

I want to generate sine wave using AD5941, and need to project that on digital analyzer. 

I am running following code to generate the sine wave: 

void AD5940_Wg_Test(void)
{
	AFERefCfg_Type aferef_cfg;
	HSLoopCfg_Type HsloopCfg;
	CLKCfg_Type clk_cfg;

	clk_cfg.ADCClkDiv = ADCCLKDIV_1;
	clk_cfg.ADCCLkSrc = ADCCLKSRC_HFOSC;
	clk_cfg.SysClkDiv = SYSCLKDIV_1;
	clk_cfg.SysClkSrc = SYSCLKSRC_HFOSC;
	clk_cfg.HfOSC32MHzMode = bFALSE;
	clk_cfg.HFOSCEn = bTRUE;
	clk_cfg.HFXTALEn = bFALSE;
	clk_cfg.LFOSCEn = bTRUE;
	AD5940_CLKCfg(&clk_cfg);

	aferef_cfg.HpBandgapEn = bTRUE;
	aferef_cfg.Hp1V1BuffEn = bTRUE;
	aferef_cfg.Hp1V8BuffEn = bTRUE;
	aferef_cfg.Disc1V1Cap = bFALSE;
	aferef_cfg.Disc1V8Cap = bFALSE;
	aferef_cfg.Hp1V8ThemBuff = bFALSE;
	aferef_cfg.Hp1V8Ilimit = bFALSE;
	aferef_cfg.Lp1V1BuffEn = bFALSE;
	aferef_cfg.Lp1V8BuffEn = bFALSE;
	/* LP reference control */
	aferef_cfg.LpBandgapEn = bTRUE;
	aferef_cfg.LpRefBufEn = bTRUE;
	aferef_cfg.LpRefBoostEn = bFALSE;
	AD5940_REFCfgS(&aferef_cfg);

	HsloopCfg.HsDacCfg.ExcitBufGain = EXCITBUFGAIN_2;
	HsloopCfg.HsDacCfg.HsDacGain = HSDACGAIN_1;
	HsloopCfg.HsDacCfg.HsDacUpdateRate = 7;

	HsloopCfg.HsTiaCfg.DiodeClose = bFALSE;
	HsloopCfg.HsTiaCfg.HstiaBias = HSTIABIAS_1P1;
	HsloopCfg.HsTiaCfg.HstiaCtia = 16; /* 16pF */
	HsloopCfg.HsTiaCfg.HstiaDeRload = HSTIADERLOAD_OPEN;
	HsloopCfg.HsTiaCfg.HstiaDeRtia = HSTIADERTIA_TODE;
	HsloopCfg.HsTiaCfg.HstiaRtiaSel = HSTIARTIA_160K;

	HsloopCfg.SWMatCfg.Dswitch = SWD_CE0;
	HsloopCfg.SWMatCfg.Pswitch = SWP_CE0;
	HsloopCfg.SWMatCfg.Nswitch = SWN_SE0LOAD;
	HsloopCfg.SWMatCfg.Tswitch = SWT_TRTIA|SWT_SE0LOAD;

	HsloopCfg.WgCfg.WgType = WGTYPE_TRAPZ;
	HsloopCfg.WgCfg.GainCalEn = bFALSE;
	HsloopCfg.WgCfg.OffsetCalEn = bFALSE;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzDCLevel1 = 0x200;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzDCLevel2 = 0xa00;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzDelay1 = 50;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzDelay2 = 100;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzSlope1 = 200;
	HsloopCfg.WgCfg.TrapzCfg.WGTrapzSlope2 = 300;
	AD5940_HSLoopCfgS(&HsloopCfg);

	AD5940_AFECtrlS(AFECTRL_DACREFPWR, bTRUE);
	AD5940_AFECtrlS(AFECTRL_EXTBUFPWR|AFECTRL_INAMPPWR|AFECTRL_HSTIAPWR|AFECTRL_HSDACPWR, bTRUE);
	AD5940_AFECtrlS(AFECTRL_WG, bTRUE);

	AD5940_AFEPwrBW(AFEPWR_LP, AFEBW_250KHZ);
}

which pin is the target pin to see the sinewave using this code? I am not able to get sine wave using this code, when I am trying to get output from CE0 pin ? 

Any suggestion or rectification would be helpful. 

which pin to project on digital analyzer, whether the code I am running is correct or not? 

Parents
  • Hi Team, 

    I am able to generate the sine wave using the wave generator. The reference example I have taken is AD5940_WG example. I am able to generate the sine wave and the o/p of sine wave I have taken from CE0 pin.  

     The subsequent task that I am trying: Give the sine wave as an input to ADC and record the ADC's data. And the plot of ADC's data should be equivalent to the sine wave. 

    But it looks like I am missing something  while configuring the ADC, I have given the CE0's output to AINx using the jumper wire. Please take following code :

         uint32_t ADCBuff[5000];
    	  ADCBaseCfg_Type adc_base;
    	  ADCFilterCfg_Type adc_filter;
    	  StatCfg_Type stat_cfg;
    	  FIFOCfg_Type fifo_cfg;
    
    	  /* Initialize ADC basic function */
    	  adc_base.ADCMuxP = ADCMUXN_AIN1;
    	  adc_base.ADCMuxN = ADCMUXN_VBIAS1;
    	  adc_base.ADCPga = ADCPGA_1;
    	  AD5940_ADCBaseCfgS(&adc_base);
    
    
    //	  AD5940_WriteReg(REG_AFE_TSWFULLCON,0x0820);
    //	  AD5940_WriteReg(REG_AFE_PSWFULLCON,0x2400);
    //	  AD5940_WriteReg(REG_AFE_NSWFULLCON,0x0200);
    //	  AD5940_WriteReg(REG_AFE_TSWFULLCON,0x0502);
    
    	  /* Initialize ADC filters ADCRawData-->SINC3-->SINC2+NOTCH-->StatisticBlock */
    	  adc_filter.ADCSinc3Osr = ADCSINC3OSR_4;
    	  adc_filter.ADCSinc2Osr = ADCSINC2OSR_1333;
    	  adc_filter.ADCAvgNum = ADCAVGNUM_8;         /* Don't care about it. Average function is only used for DFT */
    	  adc_filter.ADCRate = ADCRATE_800KHZ;        /* If ADC clock is 32MHz, then set it to ADCRATE_1P6MHZ. Default is 16MHz, use ADCRATE_800KHZ. */
    	  adc_filter.BpNotch = bTRUE;                 /* SINC2+Notch is one block, when bypass notch filter, we can get fresh data from SINC2 filter. */
    	  adc_filter.BpSinc3 = bTRUE;                /* We use SINC3 filter. */
    	  adc_filter.Sinc2NotchEnable = bTRUE;        /* Enable the SINC2+Notch block. You can also use function AD5940_AFECtrlS */
    	  AD5940_ADCFilterCfgS(&adc_filter);
    
    	  /**
    	   * 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_64;       /* Sample 128 points and calculate mean. */
    	  AD5940_StatisticCfgS(&stat_cfg);
    	  fifo_cfg.FIFOEn = bTRUE;
    	  fifo_cfg.FIFOMode = FIFOMODE_FIFO;
    	  fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    	  fifo_cfg.FIFOSrc = FIFOSRC_MEAN;
    	  fifo_cfg.FIFOThresh = 2;
    	  AD5940_FIFOCfg(&fifo_cfg);
    
    
    	  /* Enable all interrupt at Interrupt Controller 1. So we can check the interrupt flag */
    	  AD5940_INTCCfg(AFEINTC_1, AFEINTSRC_ALLINT, bTRUE);
    	  AD5940_INTCCfg(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH, bTRUE);   /* Enable FIFO threshold interrupt. */
    	  AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
    	  //AD5940_ClrMCUIntFlag(); /* Clear the MCU interrupt flag which will be set in ISR. */
    
    	  AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE);
    	  AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE);
    	  int count = -2000;
    	  while(1)
    	  {
    		count++;
    	    uint32_t FifoCnt;
    	    if(AD5940_GetMCUIntFlag())
    	    {
    	      //AD5940_ClrMCUIntFlag(); /* Clear this flag */
    	      if(AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE)
    	      {
    	        FifoCnt = AD5940_FIFOGetCnt();
    	        AD5940_FIFORd((uint32_t *)ADCBuff, FifoCnt);
    	        AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
    	        printf("Get %d data, ADC Code[0]:%d\n",FifoCnt, ADCBuff[0]&0xffff);
    	        /*!!!!!NOTE!!!!!*/
    	        /* The mean result already removed 32768. So to calculate the voltage, assume mean result is n, use below equation.
    	          Voltage = n/32768*Vref
    	         */
    	      }
    	    }
    	      if(count == 4500)
    	      {
    	    	  count = 0;
    	      }
    	  }
    }

    Please add your expertise in this issue I am facing? 

    MCU: STM32WB55xx, I am using for the SPI communication of AD5941. 

Reply
  • Hi Team, 

    I am able to generate the sine wave using the wave generator. The reference example I have taken is AD5940_WG example. I am able to generate the sine wave and the o/p of sine wave I have taken from CE0 pin.  

     The subsequent task that I am trying: Give the sine wave as an input to ADC and record the ADC's data. And the plot of ADC's data should be equivalent to the sine wave. 

    But it looks like I am missing something  while configuring the ADC, I have given the CE0's output to AINx using the jumper wire. Please take following code :

         uint32_t ADCBuff[5000];
    	  ADCBaseCfg_Type adc_base;
    	  ADCFilterCfg_Type adc_filter;
    	  StatCfg_Type stat_cfg;
    	  FIFOCfg_Type fifo_cfg;
    
    	  /* Initialize ADC basic function */
    	  adc_base.ADCMuxP = ADCMUXN_AIN1;
    	  adc_base.ADCMuxN = ADCMUXN_VBIAS1;
    	  adc_base.ADCPga = ADCPGA_1;
    	  AD5940_ADCBaseCfgS(&adc_base);
    
    
    //	  AD5940_WriteReg(REG_AFE_TSWFULLCON,0x0820);
    //	  AD5940_WriteReg(REG_AFE_PSWFULLCON,0x2400);
    //	  AD5940_WriteReg(REG_AFE_NSWFULLCON,0x0200);
    //	  AD5940_WriteReg(REG_AFE_TSWFULLCON,0x0502);
    
    	  /* Initialize ADC filters ADCRawData-->SINC3-->SINC2+NOTCH-->StatisticBlock */
    	  adc_filter.ADCSinc3Osr = ADCSINC3OSR_4;
    	  adc_filter.ADCSinc2Osr = ADCSINC2OSR_1333;
    	  adc_filter.ADCAvgNum = ADCAVGNUM_8;         /* Don't care about it. Average function is only used for DFT */
    	  adc_filter.ADCRate = ADCRATE_800KHZ;        /* If ADC clock is 32MHz, then set it to ADCRATE_1P6MHZ. Default is 16MHz, use ADCRATE_800KHZ. */
    	  adc_filter.BpNotch = bTRUE;                 /* SINC2+Notch is one block, when bypass notch filter, we can get fresh data from SINC2 filter. */
    	  adc_filter.BpSinc3 = bTRUE;                /* We use SINC3 filter. */
    	  adc_filter.Sinc2NotchEnable = bTRUE;        /* Enable the SINC2+Notch block. You can also use function AD5940_AFECtrlS */
    	  AD5940_ADCFilterCfgS(&adc_filter);
    
    	  /**
    	   * 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_64;       /* Sample 128 points and calculate mean. */
    	  AD5940_StatisticCfgS(&stat_cfg);
    	  fifo_cfg.FIFOEn = bTRUE;
    	  fifo_cfg.FIFOMode = FIFOMODE_FIFO;
    	  fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    	  fifo_cfg.FIFOSrc = FIFOSRC_MEAN;
    	  fifo_cfg.FIFOThresh = 2;
    	  AD5940_FIFOCfg(&fifo_cfg);
    
    
    	  /* Enable all interrupt at Interrupt Controller 1. So we can check the interrupt flag */
    	  AD5940_INTCCfg(AFEINTC_1, AFEINTSRC_ALLINT, bTRUE);
    	  AD5940_INTCCfg(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH, bTRUE);   /* Enable FIFO threshold interrupt. */
    	  AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
    	  //AD5940_ClrMCUIntFlag(); /* Clear the MCU interrupt flag which will be set in ISR. */
    
    	  AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE);
    	  AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE);
    	  int count = -2000;
    	  while(1)
    	  {
    		count++;
    	    uint32_t FifoCnt;
    	    if(AD5940_GetMCUIntFlag())
    	    {
    	      //AD5940_ClrMCUIntFlag(); /* Clear this flag */
    	      if(AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE)
    	      {
    	        FifoCnt = AD5940_FIFOGetCnt();
    	        AD5940_FIFORd((uint32_t *)ADCBuff, FifoCnt);
    	        AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
    	        printf("Get %d data, ADC Code[0]:%d\n",FifoCnt, ADCBuff[0]&0xffff);
    	        /*!!!!!NOTE!!!!!*/
    	        /* The mean result already removed 32768. So to calculate the voltage, assume mean result is n, use below equation.
    	          Voltage = n/32768*Vref
    	         */
    	      }
    	    }
    	      if(count == 4500)
    	      {
    	    	  count = 0;
    	      }
    	  }
    }

    Please add your expertise in this issue I am facing? 

    MCU: STM32WB55xx, I am using for the SPI communication of AD5941. 

Children
  • Hi,

    May I know what output you are getting?

    1) If no output is obtained,

    could you check if AFEINTSRC_DATAFIFOTHRESH interrupt is asserted at all?

    2) If it is almost a constant,

     Could you check the switch settings to see if AIN1 signal is connected to TIA too.

    For measuring voltage at AIN1, AIN1 must not to connected to any TIA. 

  • I have closed the switch D5 so that I can get the output of the excitation buffer on the CE0 pin. 

    I am generating the 30Hz frequency of sine wave and able to observe that on digital analyzer.

    Then I am trying to read the adc data by giving the sine wave as input positive and GND as negative input. 

    How to set up the ADC to do that, and how to fatch/export the adc data to some file so that I can check or verify the sine wave on the python matplot using the adc data. 

    I am trying with the following code but not able to get the desired results: 

    void AD5940_Test_Adc(void)
    {
         uint32_t ADCBuff[5000] = { 0 };
         uint32_t AdcBuf[15000] = { 0 };
         uint32_t cou = 0;
    	  ADCBaseCfg_Type adc_base;
    	  ADCFilterCfg_Type adc_filter;
    	  StatCfg_Type stat_cfg;
    	  FIFOCfg_Type fifo_cfg;
    
    	  /* Initialize ADC basic function */
    	  adc_base.ADCMuxP = ADCMUXP_AIN0; /* Using jumper  wire connecting the ce0 to input pin0*/
    	  adc_base.ADCMuxN = ADCMUXN_AIN1; /* using jumper wire connecting the GND to input pin1*/
    	  adc_base.ADCPga = ADCPGA_1;
    	  AD5940_ADCBaseCfgS(&adc_base);
    
    	  /* Initialize ADC filters ADCRawData-->SINC3-->SINC2+NOTCH-->StatisticBlock */
    	  adc_filter.ADCSinc3Osr = ADCSINC3OSR_4;
    	  adc_filter.ADCSinc2Osr = ADCSINC2OSR_267;
    	  adc_filter.ADCAvgNum = ADCAVGNUM_2;         /* Don't care about it. Average function is only used for DFT */
    	  adc_filter.ADCRate = ADCRATE_800KHZ;        /* If ADC clock is 32MHz, then set it to ADCRATE_1P6MHZ. Default is 16MHz, use ADCRATE_800KHZ. */
    	  adc_filter.BpNotch = bFALSE;                 /* SINC2+Notch is one block, when bypass notch filter, we can get fresh data from SINC2 filter. */
    	  adc_filter.BpSinc3 = bTRUE;                /* We use SINC3 filter. */
    	  adc_filter.Sinc2NotchEnable = bFALSE;        /* Enable the SINC2+Notch block. You can also use function AD5940_AFECtrlS */
    	  AD5940_ADCFilterCfgS(&adc_filter);
    
    	  /**
    	   * 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_128;       /* Sample 128 points and calculate mean. */
    	  AD5940_StatisticCfgS(&stat_cfg);
    
    	  AD5940_FIFOCtrlS(FIFOSRC_SINC3, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_DFT, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_SINC2NOTCH, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_VAR, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_MEAN, bFALSE);
    
    	  fifo_cfg.FIFOEn = bTRUE;
    	  fifo_cfg.FIFOMode = FIFOMODE_STREAM;
    	  fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    	  fifo_cfg.FIFOSrc = FIFOSRC_SINC3;
    	  fifo_cfg.FIFOThresh = 2;
    	  AD5940_FIFOCfg(&fifo_cfg);
    
    
    	  /* Enable all interrupt at Interrupt Controller 1. So we can check the interrupt flag */
    	  AD5940_INTCCfg(AFEINTC_1, AFEINTSRC_ALLINT, bTRUE);
    	  AD5940_INTCCfg(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH, bTRUE);   /* Enable FIFO threshold interrupt. */
    	  AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
    	  //AD5940_ClrMCUIntFlag(); /* Clear the MCU interrupt flag which will be set in ISR. */
    
    	  AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE);
    	  AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE);
    	  int count = 0;
    	  while(1)
    	  {
    
    		AdcBuf[count] = AD5940_ReadAfeResult(AFERESULT_SINC3);
    
    		count++;
         	cou++;
    	    uint32_t FifoCnt;
    	    if(AD5940_GetMCUIntFlag())
    	    {
    	      //AD5940_ClrMCUIntFlag(); /* Clear this flag */
    	      if(AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE)
    	      {
    	        FifoCnt = AD5940_FIFOGetCnt();
    	        AD5940_FIFORd((uint32_t *)ADCBuff, FifoCnt);
    	        AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
    	        printf("Get %d data, ADC Code[0]:%d\n",FifoCnt, ADCBuff[0]&0xffff);
    	        /*!!!!!NOTE!!!!!*/
    	        /* The mean result already removed 32768. So to calculate the voltage, assume mean result is n, use below equation.
    	          Voltage = n/32768*Vref
    	         */
    	      }
    	    }
    	    if(count == 14999)
    	    {
    	    	count = 0;
    	    	 FifoCnt = AD5940_FIFOGetCnt();
    	    	 AD5940_FIFORd((uint32_t *)ADCBuff, FifoCnt);
    	    }
    	  }
    }
    
     

    I am plotting the graph using the "AdcBuf[count] = AD5940_ReadAfeResult(AFERESULT_SINC3)";  {looks like  something is not incorrect}. 

    How to get the correct ADC data result and how to push the data into the fifo memory, and using the FIFO read the data or export data into some file. ? 

  • Hi  , 

    I am able to record the ADC data and get the similar wave form on the python charts. 

    One thing I am not clear is the adc data rate. According to the data sheet if default sampling rate is 800ksps and then sinc2 and sinc3 values are 4 and 178, then ADC sample rate = (800000/ (4*178)) =  1123.56 samples per second. 

    But I am observing the sample rate of 3500-4000 sample per second. 

    I am running following code: 

    void AD5940_Test_Adc(void)
    {
         uint32_t AdcBuf[15000] = { 0 };
    	  ADCBaseCfg_Type adc_base;
    	  ADCFilterCfg_Type adc_filter;
    	  StatCfg_Type stat_cfg;
    	  FIFOCfg_Type fifo_cfg;
    
    	  /* Initialize ADC basic function */
    	  adc_base.ADCMuxP = ADCMUXP_AIN0; /* Using jumper  wire connecting the ce0 to input pin0*/
    	  adc_base.ADCMuxN = ADCMUXN_AIN1; /* using jumper wire connecting the GND to input pin1*/
    	  adc_base.ADCPga = ADCPGA_1;
    	  AD5940_ADCBaseCfgS(&adc_base);
    
    	  /* Initialize ADC filters ADCRawData-->SINC3-->SINC2+NOTCH-->StatisticBlock */
    	  adc_filter.ADCSinc3Osr = ADCSINC3OSR_4;
    	  adc_filter.ADCSinc2Osr = ADCSINC2OSR_178;
    	  adc_filter.ADCAvgNum = ADCAVGNUM_2;         /* Don't care about it. Average function is only used for DFT */
    	  adc_filter.ADCRate = ADCRATE_800KHZ;        /* If ADC clock is 32MHz, then set it to ADCRATE_1P6MHZ. Default is 16MHz, use ADCRATE_800KHZ. */
    	  adc_filter.BpNotch = bTRUE;                 /* SINC2+Notch is one block, when bypass notch filter, we can get fresh data from SINC2 filter. */
    	  adc_filter.BpSinc3 = bTRUE;                /* We use SINC3 filter. */
    	  adc_filter.Sinc2NotchEnable = bTRUE;        /* Enable the SINC2+Notch block. You can also use function AD5940_AFECtrlS */
    	  AD5940_ADCFilterCfgS(&adc_filter);
    
    	  /**
    	   * 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_128;       /* Sample 128 points and calculate mean. */
    	  AD5940_StatisticCfgS(&stat_cfg);
    
    	  AD5940_FIFOCtrlS(FIFOSRC_SINC3, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_DFT, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_SINC2NOTCH, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_VAR, bFALSE);
    	  AD5940_FIFOCtrlS(FIFOSRC_MEAN, bFALSE);
    
    	  fifo_cfg.FIFOEn = bTRUE;
    	  fifo_cfg.FIFOMode = FIFOMODE_STREAM;
    	  fifo_cfg.FIFOSize = FIFOSIZE_4KB;
    	  fifo_cfg.FIFOSrc = FIFOSRC_SINC3;
    	  fifo_cfg.FIFOThresh = 2;
    	  AD5940_FIFOCfg(&fifo_cfg);
    
    
    	  /* Enable all interrupt at Interrupt Controller 1. So we can check the interrupt flag */
    	  AD5940_INTCCfg(AFEINTC_1, AFEINTSRC_ALLINT, bTRUE);
    	  AD5940_INTCCfg(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH, bTRUE);   /* Enable FIFO threshold interrupt. */
    	  AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
    	  //AD5940_ClrMCUIntFlag(); /* Clear the MCU interrupt flag which will be set in ISR. */
    
    	  AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_SINC2NOTCH, bTRUE);
    	  AD5940_AFECtrlS(AFECTRL_ADCCNV, bTRUE);
    	  int count = 0;
    	  while(1)
    	  {
    
    		  AdcBuf[count] = AD5940_ReadAfeResult(AFERESULT_SINC2);
    		  if(AdcBuf[count] == AdcBuf[count-1])
    		  {
    			  count--;
    		  }
    		  count++;
    		  if(count == 15000)
    		  {
    			  int min = AdcBuf[0];
    			  int max = AdcBuf[0];
    			  uint32_t sum = 0;
    			  for(int j = 0; j<15000; ++j)
    			  {
    				  sum += AdcBuf[j];
    				  if(AdcBuf[j] < min)
    				  {
    					  min = AdcBuf[j];
    				  }
    				  if(AdcBuf[j] > max)
    				  {
    					  max = AdcBuf[j];
    				  }
    
    			  }
    			  count = 0;
    		  }
    	  }

    In the bottom of the function, I am trying to stop the program by using breakpoint. And by doing that I am observing the adc sampling rate. 

    Any mistake I am doing in identifying the adc sampling rate here. 

    I am reading adc data using "AdcBuf[count] = AD5940_ReadAfeResult(AFERESULT_SINC2);". 

    Issue can be identified by reading the ADC filter configuration register: val = AD5940_ReadReg(REG_AFE_ADCFILTERCON);

    I am getting return value as: 1001101010001

    that means, 

    --------------------------------------------------------------------------------------------------------------------

    SINC3OCR = 1 /*i.e. oversampling rate is 4*/

    SIN2OCR = 0011 /* 178 samples for the osr setting */

    AVRGEN = 0 

    SINC3BYPS = 1

    RESERVED 1 BIT

    LPFBYPENB = 1

    RESERVED 3 BIT

    ADC SAMPLE RATE = 1 /* 800ksps */

    ------------------------------------------------------------------------------------------------------------------------

    Looks like due to some bypass is enables and that might lead to the different sampling rate that I am anticipating. But I am not clear how to calculate the ADC sampling rate using this data? 

      , please add your inputs into this? 

  • Hi,

      The formula used for calculating exact sample rate with Sinc filters enabled is not straight forward. 

    But to get an idea, you may refer to the table below:

    Sinc2 setting

    (ADC SINC2 Filter Oversampling rate)

    Sinc3 setting

    (ADC SINC3 Filter Oversampling rate)

    DFT points

    Avg Num setting

    (No. of inputs taken to do average)

    Max ODR

    (max allowed Output data rate in Hz)

    22

    2

    16384

    16

    1.21643219E+1

    22

    4

    16384

    16

    6.0924482344

    22

    5

    16384

    16

    4.87560796

    22

    2

    8192

    16

    2.42438202E+1

    22

    2

    4096

    16

    4.8151870722E+1

    22

    2

    2048

    16

    9.4988182E+1

    22

    2

    1024

    16

    1.8492407222E+2

    22

    2

    512

    16

    3.5116983033E+2

    22

    2

    256

    16

    6.37907653E+2

    22

    2

    128

    16

    1.07802185E+3

    22

    2

    64

    16

    1.6457519533E+3

    22

    2

    32

    16

    2.23401294E+3

    22

    2

    16

    16

    2.72016333E+3

    22

    2

    8

    16

    3.05227002E+3

    22

    2

    4

    16

    3.2507111811E+3

    44

    2

    4

    16

    3.2507111811E+3

    89

    2

    4

    16

    3.2507111811E+3

    178

    2

    4

    16

    3.2507111811E+3

    267

    2

    4

    16

    3.2507111811E+3

    533

    2

    4

    16

    3.2507111811E+3

    640

    2

    4

    16

    3.2507111811E+3

    667

    2

    4

    16

    3.2507111811E+3

    800

    2

    4

    16

    3.2507111811E+3

    889

    2

    4

    16

    3.2507111811E+3

    1067

    2

    4

    16

    3.2507111811E+3

    1333

    2

    4

    16

    3.2507111811E+3

    22

    2

    4

    8

    3.2507111811E+3

    22

    2

    4

    4

    3.2507111811E+3

    22

    2

    4

    2

    3.2507111811E+3