cancel
Showing results for 
Search instead for 
Did you mean: 

How to start PWM without using HAL

SKUND.11
Associate III

I have initialise the code in Low layer(No HAL).So now i have config the timer channel as PWM generation output and set clock, ARR,duty cycle as per the requirement.

Earlier when I was using HAL, after initialising i can just wrote HAL_TIM_PWM_Start function and it will automatically start the timer as pwm. But now when I'm using Low layer, there is not function for that. So how can i Start the timer in pwm or any mode(output,input compare mode etc.) using the register or any low layer functions.

For ref.- There is a register (TIM1->CR1 |= TIM_CR_CEN ) this will start the timer.

1 ACCEPTED SOLUTION

Accepted Solutions

Generally, the procedure is:

  • enable GPIOx and TIMx clock in RCC
  • set the appropriate pin's GPIOx_MODER to AF, and GPIOx_AFR to appropriate value; set also GPIOx_OSPEEDR if there's a need for higher slew rates
  • set TIMx_CCMRx to set given channel to Output Compare, and one of the PWM modes
  • set TIMx_CCRx to set duty cycle
  • enable given channel in TIMx_CCER
  • in Advanced timers, set TIMx_BDTR.MOE
  • set TIMx_PSC/TIMx_ARR to set period
  • set TIMx_CR1.CEN to start timer's counter

If there's any problem, read out and check/post GPIO and TIM registers content.

JW

View solution in original post

4 REPLIES 4

Which STM32? Which timer?

> There is a register (TIM1->CR1 |= TIM_CR_CEN ) this will start the timer.

OK, so if you know how to start the timer, what exactly is your problem?

Cube/LL is open source, so if you for some reason must use LL functions/macros, just look up which one does what you need.

JW

PS. If still no PWM output, read out and check/post the timer and relevant GPIO registers content. Note, that Advanced timers need to have TIMx_BDTR.MOE set to enable outputs.

Thank you for replying.

Sorry there was a mistake..that register will start the counter value of the timer.

Generally, the procedure is:

  • enable GPIOx and TIMx clock in RCC
  • set the appropriate pin's GPIOx_MODER to AF, and GPIOx_AFR to appropriate value; set also GPIOx_OSPEEDR if there's a need for higher slew rates
  • set TIMx_CCMRx to set given channel to Output Compare, and one of the PWM modes
  • set TIMx_CCRx to set duty cycle
  • enable given channel in TIMx_CCER
  • in Advanced timers, set TIMx_BDTR.MOE
  • set TIMx_PSC/TIMx_ARR to set period
  • set TIMx_CR1.CEN to start timer's counter

If there's any problem, read out and check/post GPIO and TIM registers content.

JW

Thank you sir.