Skip to main content
Graduate
March 21, 2024
Solved

PWM No Output for TIM1 on STM32L476

  • March 21, 2024
  • 5 replies
  • 3263 views

I use Cube to setup TIM1_CH4 on PE14 as PWM

Setup of ioc

PE14 -> TIM1_CH4 in pinout

TIM1:
Ch 4 PWM Generation Ch4
Conter Settings: Counter period 20
PQM Generation Cannel 4: Pulse 5

Modification of main:

/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);

 

It should be this simple, but no output on PE14...

(I tested PE14 as GPIO so its not wrong pin I look at...)

 

    This topic has been closed for replies.
    Best answer by PeterL

    I actually got it to work at 4 MHz now, but not 8 MHz as was my goal.

    Conter Period should be 9 and pulse should be 5 I guess. That worked for TIM2 but not for TIM1... It is too advanced to be fast?!?

    5 replies

    Super User
    March 21, 2024

    I don't use Cube but TIM1 is an Advanced Timer and needs TIMx_BDTR.MOE to be set.

    JW

    ST Employee
    March 21, 2024

    Hello @peter,

    This should work with HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4); your config/ code looks correct

    I see you're using a custom board, have you tried to output another signal on those pins? 

    PeterLAuthor
    Graduate
    March 21, 2024

    Just to verify that PE14 is operational i once more (typo PE15 in original post) verified my setup for measurement, and it seems fine.

    As far as I understand the MOE is set with the PWM project.

    PeterL_0-1711030182524.png

     

    Super User
    March 21, 2024

    Show all Timer and relevant GPIO registers content.

    JW

    Super User
    March 21, 2024

    @PeterL , you set timer to 80/20 -> 4MHz output, with 5 ticks pwm, 60ns pulse.

    But set pin to low speed, -> set high.

    And set debug not to disable, if you want to debug.

    try mod. ioc:

     

    PeterLAuthorAnswer
    Graduate
    March 21, 2024

    I actually got it to work at 4 MHz now, but not 8 MHz as was my goal.

    Conter Period should be 9 and pulse should be 5 I guess. That worked for TIM2 but not for TIM1... It is too advanced to be fast?!?

    Super User
    March 21, 2024

    So set period (arr) to 9 , not 20.   (80 / (9+1) = 8 MHz )