Skip to main content
Graduate II
April 26, 2024
Question

Configuration Request TIM1 based PWM generation with DMA ,the TIM1 will triger the ADC with DMA

  • April 26, 2024
  • 2 replies
  • 1246 views

Hello ,

 

I want to make 4 channel PWM signal using TIM1 (with complimentory also)  .While the TIM1 is used to triger the ADC to get sample .

I am getting the pwm wave , But  ADC is not triggering or not working . What configuration i require  

 

Please see more details below  

 

I am Trying to generate 2 Channel PWM Genertaion [ CH1 CHN and  PWD Generation CH2CH2N ] from  DMA  Buffer .

   HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table, 160);

    HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);

    HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 160);

    HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2);

Configuration as follows 

Screenshot 2024-04-26 at 2.44.46 PM.pngScreenshot 2024-04-26 at 2.45.24 PM.png

Screenshot 2024-04-26 at 2.47.09 PM.png

While PWM generation am trying to  TIM1 is  to triger the  ADC 

Screenshot 2024-04-26 at 2.52.27 PM.png

 

The ADC configured as follows 

HAL_ADCEx_Calibration_Start(&hadc);

HAL_ADC_Start_DMA(&hadc, (uint32_t *)ADC_RES, 200);

Screenshot 2024-04-26 at 2.56.13 PM.png

Screenshot 2024-04-26 at 2.56.59 PM.png

Screenshot 2024-04-26 at 3.02.40 PM.png

Am here attached the main.c file 

 

@AScha.3 

 

 

 

 

 

 

 

    This topic has been closed for replies.

    2 replies

    Super User
    April 26, 2024

    Hi,

    just what i see now : not enable continuous..

    adc...dma:

    AScha3_0-1714128886214.png

    +

    see my use case : tim8 -> trigger -> adc (with dma )

    tim8:

    AScha3_2-1714129104065.png

     

    adc:

    AScha3_1-1714129025120.png

     

    start in main.c : (but i use not circular dma here, doing just one 512 sample-shot.)

     

    retval = HAL_ADC_Start_DMA(&hadc1, (uint32_t *) &sampels[nu][0], 512);
    
    while(HAL_DMA_GetState(&hdma_adc1) > HAL_DMA_STATE_READY) {};	// wait for ready

     

    Graduate II
    April 26, 2024

    I tried DMA continuous. request turned off ?

    If circular mode turn off is it restart from zero after 512 ?

    Other configuration is correct in my case ?

     

    In the below code i didnt get the trigger in GPIOC Pin4  what is the wrong with me ?

    void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

    {      if (htim->Instance == TIM1) 

                { t occurs HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_4);

                 }

    }

     

    Super User
    April 26, 2024

    >I tried DMA continuous. request turned off ?

    Just try it. 

    >If circular mode turn off is it restart from zero after 512 ?

    Yes, without circular mode : just filling the array one time. (Same as "one shot" on a DSO .)

    Next dma start...same again.

    >Other configuration is correct in my case ?

    Hmmm...try. If you want continuous operation, then circular mode is correct; you have to use/copy data then in half/full callbacks - or just let it run. Only one dma-start needed here, it will loop always/endless and fill the array.