In the STM32CubeF4 Firmware I have found an example of how to use a timer with OCActive. Unfortunately there is no example for my discovery board. So I have tried to port the following code.
Same result: TIM_OCMODE_TOGGLE works, TIM_OCMODE_ACTIVE does not.
Does anyone have a working example for the STM32F429I-DISCO with a timer using OCMode=TIM_OCMODE_ACTIVE?
This is the expected behaviour.
Read the description of OC1M in TIMx_CCMR1 in RM0090.
Actually, I have done that.
The manual says:
"OC1M: Output Compare 1 mode
These bits define the behavior of the output reference signal OC1REF from which OC1 and OC1N are derived. OC1REF is active high whereas OC1 and OC1N active level depends on CC1P and CC1NP bits.
000: Frozen - The comparison between the output compare register TIMx_CCR1 and the counter TIMx_CNT has no effect on the outputs.(this mode is used to generate a timing base).
001: Set channel 1 to active level on match. OC1REF signal is forced high when the counter TIMx_CNT matches the capture/compare register 1 (TIMx_CCR1).
010: Set channel 1 to inactive level on match. OC1REF signal is forced"
Having read that, I would expect a different behaviour than the described behaviour above. Additionally the readme of the example for STM324x9I_EVAL states the following:
" - Connect the following pins to an oscilloscope to monitor the different waveforms:
- Use LED1 connected to PG.06 (Reference)
- PC.06 (TIM3_CH1)
- PC.07 (TIM3_CH2)
- PC.08 (TIM3_CH3)
- PC.09 (TIM3_CH4)"
So there are supposed to be changes on the output pin.
Basically, I want the timer output to get high for one cycle when TIMx_CNT=TIMx_CCR1. It's probably very simple, but I am failing on that.
I understand the point, but while the description of the OCxM=0b001/0b010 modes may be confusing, they do not produce the one-clock-wide pulse you expected.
And I also don't know of any simple way to achieve that with the STM32 timers. You of course can set the compare register to just above 0 or just below ARR and with an appropriate PWM mode achieve a one-clock-wide pulse, but not at an arbitrary time within the ARR cycle.