Skip to main content
Graduate II
May 2, 2024
Solved

DMA trigger by TIM1 Conifguration -PWM generation not getting correct PWM

  • May 2, 2024
  • 11 replies
  • 3629 views

I am generating PWM signals for 4 channels using TIM1, with 2 complimentary outputs. The CCR values should come from an array lookup table via DMA.

 

Screenshot 2024-05-02 at 10.43.06 AM.pngis this means The DMA trigger by TM1 ?

 

Screenshot 2024-05-02 at 10.45.16 AM.png

 

 

 

I am trying to generate a sinewave from the following array 

uint16_t sin_table[160]={0, 5, 10, 15, 20, 25, 29, 34, 39, 44, 49, 54, 58, 63, 68,

73, 77, 82, 87, 91, 96, 100, 105, 109, 113, 118, 122, 126, 131, 135, 139,

143, 147, 151, 155, 159, 162, 166, 170, 173, 177, 180, 184, 187, 190, 193,

196, 199, 202, 205, 208, 211, 213, 216, 218, 220, 223, 225, 227, 229, 231,

233, 235, 236, 238, 239, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249,

249, 250, 250, 250, 250, 250, 250, 250, 249, 249, 248, 248, 247, 246, 245,

244, 243, 242, 241, 239, 238, 236, 235, 233, 231, 229, 227, 225, 223, 220,

218, 216, 213, 211, 208, 205, 202, 199, 196, 193, 190, 187, 184, 180, 177,

173, 170, 166, 162, 159, 155, 151, 147, 143, 139, 135, 131, 126, 122, 118,

113, 109, 105, 100, 96, 91, 87, 82, 77, 73, 68, 63, 58, 54, 49, 44, 39, 34, 29, 25, 20, 15, 10, 5};

 

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);

I am not getting the 160 values as per the array value 

FPWM is 16KHZ

Screenshot 2024-05-02 at 10.56.11 AM.pngWhat wrong with me ?

please help me

@AScha.3 

    This topic has been closed for replies.
    Best answer by AScha.3

    Aaaaa, come on:  set ARR to max. used value in ccr loading -> 255 . Try.

     

    11 replies

    Super User
    May 2, 2024

    What wrong with me ?

    I dont know, maybe need a doctor .... :)

    +

    about your program:

    - set DMA in Cube to half-word / half-word transfer data size .

    - leave away (for test , now at first )  the //HAL_TIMEx_PWMN_Start_IT(..);   lines .

    Graduate II
    May 2, 2024

    Thanks

    Now i can get only 12 ON pulses, am giving 160 varying valuse from Lookup table  for duty cycle .

    62.5μs×160=10000μs =10ms

    But not showing 160 pulse ,is it due to small variation in the duty cycle ?

    Screenshot 2024-05-02 at 1.25.44 PM.pngScreenshot 2024-05-02 at 1.26.13 PM.png

    sorry for my bad english

     

    AScha.3Answer
    Super User
    May 2, 2024

    Aaaaa, come on:  set ARR to max. used value in ccr loading -> 255 . Try.

     

    Super User
    May 2, 2024

    Which STM32?

    Read out and check/post content if TIM and relevant DMA registers. 

    JW

    PS. Don't @-invoke users unnecessarily.

    Graduate II
    May 2, 2024

    Stm32f070RB Nucleo Board

    Super User
    May 2, 2024

    Nice catch, @AScha.3 

    JW

    Graduate II
    May 2, 2024

    Thanks

     

    When I select Centere Aligined mode1 ,which is not giving output ,when i select Centre Aligned Mode 2 it is working 

    why ?

    Super User
    May 2, 2024

    Well, i need to read the rm , to know the difference - so i recommend read it in rm of your cpu. :)

    from F303 rm :

    AScha3_0-1714656084640.png

     

    Graduate II
    May 2, 2024

    I got expetced pwm But the PWM period is expected is 62.2micro second (Fpwm is 16khz)

    but the output shows 124  micro second please see the image

    why ?

    Screenshot 2024-05-02 at 7.03.44 PM.png 

     

    Super User
    May 2, 2024

    Center aligned mode counts up and down - so double time (62 -> 124 us ) , as "normal" pwm mode.

     

    AScha3_0-1714657555576.png

     

    Graduate II
    May 3, 2024

    Thanks

    If I require an FPWM frequency of 16 kHz, I need to set the ARR value to generate 8 kHz, isn't it?"

    Super User
    May 3, 2024

    If PWM frequency of 16 kHz should come out, with center al.mode , ARR <- value for 32 kHz .

    Just try it, nothing will explode...if you set something wrong. :)

    Graduate II
    May 4, 2024

    Also when I select center align Mode 1 ,there is no output is getting.

    it works if i select Centre algin mode 2 

    why so ?

    Super User
    May 4, 2024

    I am not sure (i never tried) - see description , as i posted.

    But i would try mode 3 - tell, what comes out. Because mode 3 (as i understand description) is true center mode, ccr compare on rising + falling counter. Mode 2 only on rising...

    Super User
    May 4, 2024

    @thannara123,

    Why do you insist on using center-aligned mode?

    JW