stm32f4discovery A/D set up

296 views Asked by At

I want to setup the AD converter at 8KHz rate (for voice sampling). I know how to do it with timer interrupt. However I want to set it up directly using DMA.. Operation clock is at 144Mhz (and should be there)--> ADC clock is APB2/2=36Mhz Now using ADC_SMPR1 I can add 12+480 cycles which is not enough. Is there any clever way to set the ADC clock down to 8Khz?

1

There are 1 answers

0
denis krasutski On

In order to use DMA and ADC, you don't reduce the speed of Core or DMA. Mentioned clocks don't affect to sample rate. Sample rate must be set up by timer! But you shouldn't use timer interrupt! Use the following scheme:

  1. Setup timer on 8KHZ, I suppose you have it but don't enable interrypt!
  2. Set the event to start ADC conversion, for example: hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
  3. Confiture timer to master mode by HAL_TIMEx_MasterConfigSynchronization function, example:

    TIM_MasterConfigTypeDef master_config = {
        .MasterOutputTrigger = TIM_TRGO_UPDATE,
        .MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE
    };
    
    HAL_TIMEx_MasterConfigSynchronization(&hAudioInTim3, &master_config);
    
  4. Run ADC: HAL_ADC_Start_DMA(&hadc, buffer, size);

  5. Wait for HAL_ADC_ConvCpltCallback event and then process your data.