This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Configured sampling time does not match with real sampling time

I'm working in a Project. We have bought the MCBstm32F400 Dev. Board.

I haved configured the ADC sampling time equal to 1MSPS as follows:

System clock =30MHz(HSI)
SPB preescaler = 1-> PCLK = 30MHz.

-I'm using ADC3
-ADC_preescaler= Div2 -> ADC_clock= 15MHz.
-ADC sampletime= 3 cycles
-ADC channel= 4

conversion time=( 3+12)/15MHz= 1us = 1MHz. I use the Excel file to configure the clock.

next is the code to configure the ADC:

/* Private typedef -----------------------------------------------------------*/

# define N_samples      100



/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/









ADC_InitTypeDef         ADC_InitStructure;
ADC_CommonInitTypeDef   ADC_CommonInitStructure;
GPIO_InitTypeDef GPIOADC_InitStructure;
/* Private function prototypes -----------------------------------------------*/

        uint32_t index=0;
        float32_t array2[N_samples];


/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{







                //1.  Enable the ADC interface
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);





//3. Configure the ADC Prescaler, conversion resolution and data
  //  alignment using the ADC_Init() function.

        /* ADC Common Init(Configure the ADC Prescaler) **********************************************************/
   ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
   ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; //ADCclock= PCLK2/2= 36Mhz/2=18MHz
   ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
   ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
   ADC_CommonInit(&ADC_CommonInitStructure);


        //conversion resolution and data alignment
ADC_InitStructure.ADC_Resolution        =       ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode      =       DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode        =       DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge      =       ADC_ExternalTrigConvEdge_None;
//ADC_InitStructure.ADC_ExternalTrigConv        =       ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign =       ADC_DataAlign_Right ;
ADC_InitStructure.ADC_NbrOfConversion   = 1;

ADC_Init(ADC3, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 1, ADC_SampleTime_3Cycles);//sampletime= ADC_clock/(3+12)=  18MHz/15=1.2MHz

//2. ADC pins configuration
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);

GPIOADC_InitStructure.GPIO_Pin = GPIO_Pin_6;//PF9
GPIOADC_InitStructure.GPIO_Mode = GPIO_Mode_AN ;// PIN 9 IN ANALOGUE MODE
GPIOADC_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIOADC_InitStructure);


//4. Activate the ADC peripheral using ADC_Cmd() function.
ADC_Cmd(ADC3, ENABLE);


                /* Get the N ADC samples */
for (index=0; index<N_samples; index++)
{
/* ADC start conv */
ADC_SoftwareStartConv(ADC3);

/* Wait end of conversion */
while(ADC_GetFlagStatus(ADC3,ADC_FLAG_EOC) == RESET);
/* Store ADC samples*/


array2[index]= ADC_GetConversionValue(ADC3)-2048;



problem: Configured sampling time does not match with real sampling time.

I put a square signal of 15KHz to get more or less 66 samples(1MHz/15KHz). I see the results in
the Watch window:

. . .

-2045 , -2034 , -2032 , -2037 , -2040 , -2036 , -2036 , -2041 , -2038 , -2041 , 2039 , 2036 , 2033 , 2031 , 2034 , 2039 , 2037 , 2031 , 2036 , 2038 , -2048 , -2042 , -2039 , -2040 , -2041 , -2041 , -2038 , -2042 , -2041 , -2036 . . . repeats itself

The input signal freq is 15KHz, and there are 20 points per cycle therefore , the real
sampling time is: (x/15KHz)= 20 -> x= 300KHz.

what did I do wrong???

Thank you very much.

0