This is [hopefully] the last question related to actuator signal capture. A short recap: we need to capture duty cycle, period and polarity of the bidirectional 24V ~20kHz signal from third party actuator controller with at least 1000 steps precision in the entire 0..100% range. The circuit is based on STM32G051 controller.
The problem of motor emulation kinda solved itself when we managed to disable open circuit detection in the actuator controller. I have solved the problem of capturing direction by adding D-trigger to one half of the signal and clocking it by positive edge of the PWM pulses. This works as expected, the last captured period and duty are available in the DMA buffers and the polarity of the last pulse is latched by the flip-flop.
The final problem is capturing the amplitude and the polarity of 0% and 100% input. When there are no pulses the last captured values getting stuck in the DMA buffers and D-trigger. Apparently I am not the first facing this problem, but the answers in questions like this are too generic to be useful.
Here is current circuit and corresponding signals:
The idea is to somehow detect "no pulses" condition and generate Capture signal on OR gate to latch the input polarity in the flip-flop (come to think about it, I can drop the OR gate and connect OUT1 signal to GPIO to figure out the polarity and level of the input voltage without latching it).
First I tried TIM3 in One-pulse mode with slave reset and trigger by ITR0 from TIM1. This did not work since TIM1 was generating update event on every capture.
Then I tried TIM3 in PWM mode with slave reset by ITR0. Did not work either, probably for the same reason.
Finally I programmed TIM1 capture IRQ to write 1 into TIM3 counter, and TIM3 update IRQ to write 0 into PWM capture buffers. This works, but has some glitches and TIM3 IRQ is getting called even when there are incoming pulses, don't know why.
So, I am looking for suggestions for simple and reliable capture of 0% and 100% duty, preferably pure hardware configuration solution without any IRQ involved.
PS
The terms 0% and 100% duty sound somewhat oksimoron-ish. What I really mean is one of the following three conditions: a) no current through A1 input, b) current flows from A1_1 to A1_2 and c) current flows from A1_2 to A1_1.




