cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation of ADC sampling rate

manishbaing2789
Associate II
Posted on November 19, 2013 at 09:11

Hello,

♯ I am working with STM32F4 Discovery  and summon arm tool chain.I am sending ADC  data over       serial Port using USB serial communication.

♯ I have write code to get ADC value in continuous conversion mode.Its working fine.

Now I have to ADC sampling rate by using ADC configuration parameters

 

 I have read stm32f4 reference manual but i didn't get any exact formula regarding that.

   

So how should I calculate it ..?

   is there any formula for calculation of sampling rate..? if  so then please mention link of referred      Document .

following is my ADC configuration code where I have set

ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;

.

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

...............................ADC Configuration......................

/*! ADC source File */

&sharpinclude ''stm32f4xx.h''

&sharpinclude ''/home/manish/Product_codes/Verified-Codes/my-usb-with-adc-24-sept/STM32F4_USB_CDC/libs/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_adc.h''

&sharpinclude ''/home/manish/Product_codes/Verified-Codes/my-usb-with-adc-24-sept/STM32F4_USB_CDC/libs/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h''

&sharpinclude <math.h>

&sharpinclude <stdio.h>

&sharpinclude <stdlib.h>

/*! ADC Initialazion function */

adcInit(){

     RCC_ClocksTypeDef RCC_Clocks;

    /*! Intialsizing structure to set ADC Configuration */

    ADC_InitTypeDef ADC_InitStructure;

   

/*! Intialsizing structure to set GPIO  Configuration */

GPIO_InitTypeDef GPIO_InitStructure;

    /*! Intialsizing structure to set ADC  Common Configuration */

ADC_CommonInitTypeDef ADC_CommonInitStructure;

        /*! Enable ADC1 Interface Clock */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

//..................................................

        RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN,ENABLE);

//...................................................

        RCC_GetClocksFreq(&RCC_Clocks);

/*! Enable the ADC1 GPIO Clock */

      //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 

/*! Initializing GPIO for ADC */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

/*! Configuring  ADC GPIO pins in analog mode */

GPIO_Init(GPIOC, &GPIO_InitStructure);

/*! ADC Common Init */

/*! Use Independent mode */

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

// ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

        ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;

ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

/*! 

*  Initializes the ADCx peripheral according 

*  to the specified ADC parameters in the ADC_CommonInitStruct

*/

ADC_CommonInit(&ADC_CommonInitStructure);

  /*! ADC1 Init */

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

        ADC_InitStructure.ADC_ExternalTrigConv = 0;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 1;

/*!

*  Initializes the ADCx peripheral according 

*   to the specified ADC parameters in the ADC_InitStruct. 

         */

      ADC_DeInit();

ADC_Init(ADC1, &ADC_InitStructure);

/*! Enabling Temperature sensor */

//ADC_TempSensorVrefintCmd(ENABLE);

/*! ADC1 regular channel16 configuration */

//ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);

        ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_144Cycles);

/*! Enable(Activate ) ADC1 Peripherals */

ADC_Cmd(ADC1, ENABLE);

       ADC_ContinuousModeCmd(ADC1, ENABLE);

    /*! Intialsizing structure For NVIC Configuration */

NVIC_InitTypeDef NVIC_InitStructure;

        

/*! set parameters of NVIC_InitTypeDef structure */

NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

/*!

* Initializes the NVIC peripheral according

*  to the specified parameters in the NVIC_InitStruct

*/

NVIC_Init(&NVIC_InitStructure);

}

  

#adc-sampling-rate
1 REPLY 1
Posted on November 19, 2013 at 10:41

I'm sure the manual describes the relationship between the ADC clock the sample time, conversion time (12-cycles?), etc.

If reading is not your thing, a more practical approach to confirm the calculation, or actual rate, then one could toggle a GPIO at the EOC and measure the time on a scope, or at the interrupt read the value of a free running timer or counter. The core's cycle counter being particularly good timebase in this regard.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..