Some confusion about the configuration of output compare
Some confusion about the configuration of output compare
Hello, I am a beginner in STM32 MCUs. The MCU I am using is STM32F103ZET6.
I'm trying to use the output compare function of the timer.
But I came across something that confused me.
I use STM32CubeMX to configure my MCU.
I configured TIM3's output cmpare function with the Channel1 enabled.
I configured the parameters as follows:
PSC=0,
ARR=39,
Output Compare Channel1: Mode = Toogle on match, Pulse=19
The frequency of TIM3 is 40MHZ.
As I understand it, when I configure the output compare function of TIM3 according to the above parameters, the output pin of channel 1 should generate a square wave with a period of 1us. Because Pulse/40MHZ = 20/40MHZ = 0.5us.
But actually, I get a square wave with a period of 2us. After my troubleshooting, I realized that this value is calculated based on the value of ARR. Because ARR/40MHZ = (39+1)/40MHZ = 1us.
In fact, I found that the parameter Pulse didn't do anything at all, and even if I set the Pulse parameter to 0, the Channel1 pins would still generate a square wave based on the value of the ARR, as well as generating an interrupt.
Can anyone explain this? Why doesn't the parameter Pulse play any role, instead ARR determines the period of the output square wave? As I understand it, it should be that ARR plays no role and Pulse determines the period of the output square wave.
My clock configuration, and part of the code is shown below:








Following the configuration above, the waveform I got from the oscilloscope is shown below. Where the yellow waveform is representing Cnannel1 of TIM3 and the blue waveform is representing GPIO PB5 which is flipped in the ISR of TIM3.
