I'm working on a BLDC motor control project using an STM32F030C6 and I'm confused by a bug I found in the current limiting circuit.
I'm applying cycle-by-cycle current limiting. Externally I have a (sufficiently quick) opamp amplifier measuring the current in the ground path of the combined three phases. There is also a high speed comparator that compares the aplified value with a setpoint. The output of this comparator is fed into the TIM1_BKIN input on PB12. When the current rises too high, the comparator flips and the STM32 turns off the PWM.
Normally this works perfectly (see first cycle in the scope image). The comparator output (CH2) goes low and the measured current (CH1) instantly starts dropping.
By the way, you can see the H-bridge switching as the signal couples in into my probe, causing a spike.
The second time - and in practice this happens many times - the break input doesn't seem to react to the falling edge, since the current keeps rising and switches off 4.6us later.
To eliminate the possibility of the software disabling the BRK input, I activated lock level 1 on the TIM1_BDTR register. The code for doing this is generated using STM32CubeMX 4.14.0.
I do not understand why this can happen as the BRK input works asynchronously and doesn't require even an interrupt. Any ideas or requests for more information?
I didn't find why the break input doesn't work all the time.
Instead, I reworked my hardware to use the ETR (external trigger) input instead of the break input and to clear on that. This works perfectly.