Skip to main content
Associate III
June 26, 2026
Question

How To Change PWM Frequency With Only The Prescaler

  • June 26, 2026
  • 3 replies
  • 14 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.

 

 

3 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.
Richard Li
Senior
June 26, 2026

Which chip you used?

Is the code use DMA?

waclawek.jan
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