2024-06-06 02:18 PM
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:
To get a 4MHz frequency I have PSC = 0 and the ARR/Counter period 49:
Here are the rest of the settings for break and dead time (not used) and PWM Generation Channel 1:
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?
Solved! Go to Solution.
2024-06-06 04:58 PM
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.
2024-06-06 02:50 PM
>> 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
2024-06-06 02:56 PM - edited 2024-06-06 03:01 PM
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.
2024-06-06 04:58 PM
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.