Nuckeo-F446REで出力PWMの周波数を変える方法 How to change freq. of PWM in using Nuckeo-F446RE

ちなみにkeil studioのディレクトリも見ましたが、予約タイマを設定しているプログラム等は見つかりませんでした。

I want to make a PWM wave with variable frequency by timer interrupt of Nuckeo-F446RE.
I tried to make those by comparing Look up data with timer counter. But even though I change register CR1 of TIM2(TIM2->CR1), timer counter keeps the up counter modeーI couldn’t change register in itself.
Is timer TIM2 is reserved by mbed(Can’t I change the timerTIM2)? And do I have to use another timer?
As a side note, I searched keil studio’s directories for TIM2 setting program, but I couldn’t find it.


Mbed used TIM5 for STM32F4 family

BR, Jan


Thank you for replying.

Mbed uses TIM5―We cannot change TIM5 register. OK.
Then, TIM2 can be changed, but I can’t (The output wave shows upcount movement).
I use this in source code: TIM2->CR1 |= 0b1100000;
CR1 is TIMx control register(Of course, TIM2 is included), and bit 5 and 6 are PWM mode changers:
“00” is only up or down counter.
“01”,"10 ",“11” are both up and down counters. Difference of those is as follows:
“01” loads the target number when counter counts 0(down).
"10 "loads the target number when counter counts TIM2->ARR(up).
“11” loads the target number when counter counts both 0 and TIM2->ARR(up and down).

Other registers are as follows:
RCC->APB1ENR |= 0x1;
TIM2->CR1 |= 0b0001010000;
TIM2->PSC = 100-1;
TIM2->ARR = 1000;
TIM2->CCMR1 = 0x6868;
TIM2->CCMR2 = 0x0068;
and TIM2->CCR1~3( for target of counter).

Do I have to set other registers?

For the correct workflow with registers you have to check reference manual for your MCU. Or you can do it with HALs.

BR, Jan