cancel
Showing results for 
Search instead for 
Did you mean: 

Change CCR1 value with HAL

uc2013135191
Associate II
Posted on December 03, 2014 at 01:01

Hi everyone,

I'm starting with STM32 so i am running through some examples.

I am using HAL since it helps porting codes between different MCUs

I am now trying using PWM with the timer. 

I can't seem to find any function to change the duty of the PWM. What i am doing now is directly accessing the register.

Is there any function that changes the comparator value that i am missing?

Is the method of using TIMx->CCR1= 100 portable between other boards? This is what i care the most. If i have to sometimes use registers i can live with that.
3 REPLIES 3
patrickbrataas9
Associate II
Posted on December 03, 2014 at 11:55

You can do:

htim4.Instance->CCR1

for timer 4 CC1 register.

It's basically the same, but a more ''HALish'' syntax.

Posted on December 04, 2014 at 11:46

Hi,

The STM32Cube HAL TIM driver offers the following Macros, that can be used to:
  • Set/modify the duty cycles of the PWM signals

__HAL_TIM_SetCompare(__HANDLE__, __CHANNEL__, __COMPARE__)

  • Set/modify the period of the PWM signals

__HAL_TIM_SetAutoreload(__HANDLE__, __AUTORELOAD__)

Regards, Heisenberg.
uc2013135191
Associate II
Posted on December 06, 2014 at 00:23

Thank you. I only searched the .c source file, didn't know i should be searching the .h files.