Skip to main content
Visitor II
June 6, 2024
Solved

STM32H7 TIM1 PWM Issue

  • June 6, 2024
  • 3 replies
  • 2401 views

I am attempting to use TIM1 CH1 to produce a 4MHz PWM with 50% duty cycle, to be used as a clock input to a knock sensor.  TIM1 is on the APB2 Timer Clock with I have configured at 200 MHz:Screenshot from 2024-06-06 14-08-56.png

 

To get a 4MHz frequency I have PSC = 0 and the ARR/Counter period 49:

Screenshot from 2024-06-06 14-11-19.png

 

Here are the rest of the settings for break and dead time (not used) and PWM Generation Channel 1:

 

Screenshot from 2024-06-06 14-13-13.png

When I put a scope on this, I do see what roughly looks like a PWM, but with a frequency of 30Hz instead of 4MHz.  I have verified I am probing the right pin because if I have the clock to what I think is 10MHz (a factor of 2.5) I see the signal on my scope increase from 30Hz to 75 Hz (the same factor of 2.5).

I have several other PWMs on this board, on TIM3, TIM4, TIM5, and TIM23, all of which are working without issue and producing the exact frequency and duty cycle I expect. The only difference I can think is that TIM1 is an "advanced timer" but I have not been able to discern anything in the RM or otherwise that would indicate that I need to do something different to set this timer up for PWM.  Am I missing something?

    This topic has been closed for replies.
    Best answer by dsurrett

    Well, to close this out, the solution is "understand how to use your scope correctly". I didn't have good accuracy on the scope and it was not measuring the frequency correctly.  After some scope adjustments I verified I was producing both a 4MHz and 10MHz PWM as desired based on my configuration.  Tesla, thanks for the suggestions, after I eliminated all those I decided it had to be an equipment problem, and that was it.

    3 replies

    Graduate II
    June 6, 2024

    >> Am I missing something?

    Fixed gear ratios, so has to be clocking slower internally, for whatever reason.

    It's not because it's an Advanced TIM

    The HSE didn't start or is not 25 MHz? Check HSE and PLL via PA8 MCO pin

    Would use a UART check it outputs at correct baud rate.

    Print values for CPU, AHB, APB1, and APB2

    dsurrettAuthor
    Visitor II
    June 6, 2024

    I am using USART1, which is also on APB2, for a debug serial interface, and it is operating at the correct frequency, so I do not think it is an HSE issue, but I can check the values you suggest just to try and make sure. I also do not think it is a HSE or PLL issue because I have other timers running exactly as expected using this same math.

    dsurrettAuthorAnswer
    Visitor II
    June 6, 2024

    Well, to close this out, the solution is "understand how to use your scope correctly". I didn't have good accuracy on the scope and it was not measuring the frequency correctly.  After some scope adjustments I verified I was producing both a 4MHz and 10MHz PWM as desired based on my configuration.  Tesla, thanks for the suggestions, after I eliminated all those I decided it had to be an equipment problem, and that was it.