Skip to main content
Associate III
June 26, 2026
Solved

How To Change PWM Frequency With Only The Prescaler

  • June 26, 2026
  • 8 replies
  • 106 views

 

Hello,

I have inherited some code where a 5kHz 50% PWM is output in center aligned mode using TIM1. CK_PSC is 275MHz, CK_CNT is 137.5MHz (I think) because PSC = 1.

The pattern output matches the implementation:

 

 

The yellow trace is a GPIO pin that is toggled in the ISR HAL_TIM_PeriodElapsedCallback().

 

I want to to keep the same 50% duty but half the frequency to 2.5kHz using the prescaler.

From the TRM, it seems I just have to modify PSC from 1 to 2. However, when I do this by poking the SFR register using the debugger, I get the following output:

 

 

As you can see, the PWM ratio changes but the frequency does not. I’m at a loss to understand why. So would be grateful for any suggestions.

Thank you.

 

In case it helps, here’s my register dump. I have no idea what DMAR is that is my next step.

 

 

Best answer by waclawek.jan

Always start with stating, which STM32, and perhaps add, what harware and what software are you using.

TIMx_SMCR=0x200004 means, that some external source (possibly another timer) resets this timer. In debugger, set SMCR=0, you should see again 50% duty and 3/2 of the original period (see below).

Prescaler is (PSC+1), i.e. 1 is prescaler 2, and 2 is prescaler 3. If you want half the frequency, use PSC=3 (ie. prescaler 4).

JW

8 replies

ST Technical Moderator
June 26, 2026

Hello ​@Kier 
Is modifying only the PSC a condition in your case?
because with 137.5 MHZ frequency, configuring the PSC to 54, ARR to 999 and CCR to 500 should be just enough to create the wanted 2.5 KHZ signal
simple and easy way.
BR
Gyessine
 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
KierAuthor
Associate III
June 29, 2026

Hello ​@Gyessine 

Thank you for the suggested modifications.

Apologies, but the target 2.5kHz was really just an example. I only want understand how the TIM module PSC works. My aim first is to change (reduce) the frequency without changing the duty cycle using only PSC.

Richard Li
Senior
June 26, 2026

Which chip you used?

Is the code use DMA?

KierAuthor
Associate III
June 29, 2026

Thank you ​@Richard Li 

I’m using the NUCLEO-H723ZG. Sorry, I assumed (incorrectly) that the TIM1 module would be the same for all STM32.

The code is using DMA for UART. There’s no DMA set-up for the TIM1 module.

 

waclawek.jan
waclawek.janBest answer
Super User
June 26, 2026

Always start with stating, which STM32, and perhaps add, what harware and what software are you using.

TIMx_SMCR=0x200004 means, that some external source (possibly another timer) resets this timer. In debugger, set SMCR=0, you should see again 50% duty and 3/2 of the original period (see below).

Prescaler is (PSC+1), i.e. 1 is prescaler 2, and 2 is prescaler 3. If you want half the frequency, use PSC=3 (ie. prescaler 4).

JW

KierAuthor
Associate III
June 29, 2026

Yes, quite right, apologies. I’m using the STM32H7 on NUCLEO-H723ZG.

Thank you very much, great spot!

Setting TIMx_SMCR to 0 fixes the problem. I can now adjust PSC only and keep the duty cycle.

I found that some other part of the application was changing the Slave Mode after the MX initialization which was set to Disabled.

Thanks again.

 

ST Technical Moderator
June 29, 2026

Hello ​@Kier 
>Apologies, but the target 2.5kHz was really just an example. I only want understand how the TIM module PSC works. My aim first is to change (reduce) the frequency without changing the duty cycle using only PSC.

Based on the reference manual, the actual prescaler value is the value entered as input plus 1. Therefore, when a prescaler value of 1 is used, the actual value is 2. To halve the frequency, you should always apply this formula

For more details
you can check the timer section in the STM32H723 reference manual.
BR
Gyessine

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
KierAuthor
Associate III
June 29, 2026

Thank you for the information. Yes, I misunderstood the register mapping to real value. The main problem is solved now. I can change PSC and retain the duty cycle.