AnsweredAssumed Answered

Calculation of ADC sampling rate

Question asked by Manish on Nov 19, 2013
Latest reply on Nov 19, 2013 by Clive One
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 */
#include "stm32f4xx.h"
#include "/home/manish/Product_codes/Verified-Codes/my-usb-with-adc-24-sept/STM32F4_USB_CDC/libs/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_adc.h"
#include "/home/manish/Product_codes/Verified-Codes/my-usb-with-adc-24-sept/STM32F4_USB_CDC/libs/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h"
#include <math.h>
#include <stdio.h>
#include <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);


}

  


Outcomes