2018-12-06 08:49 AM
I'm using an STM32F030K6 and I need to measure the time between the rising edge of 2 signals.
The 2 signals (square wave) are not in phase and intended to use TIM1 to:
* rising edge of signal 1, make timer start (internaly clocked);
* rising edge of signal 2, capture the timer and trigger the DMA;
* automatically stop at the timer to wait for the rising edge of signal 1 again.
I find some information in sections 13.3.17 and 13.3.18, but not enough to understand the process and how I can prepare the setup using CubeMX.
Could you please explain the process and recommend some specific reading on this example?
Thank you
2018-12-06 09:36 AM
I would have TIMx free running , connect the two signals to 2 TIMx_CHx, set up capture on on both TIMx_CHx and an interrupt on the latter channel. Calculate the difference of the captured valuesand you are done. If time difference is larger than one rollover of TIMx, take rollover in account.
2018-12-06 09:40 AM
Or you could free-run the TIM, and have the two inputs trigger each to sample the timestamp into the CCRx for each, and simply delta the measurement. If you interrupt you could use a long-term time measurement so as to avoid the overflow/wrap issues with a 16-bit TIM
Sorry don't CubeMX
2018-12-06 09:56 AM
OK.
That was my first thought of how to resolve the situation.
But I thought if it was possible to get even more out of the hardware and use XOR just like they do with the hall sensor.
Thanks for the answers!
2018-12-06 03:02 PM
This is very similar to what ST calls "PWM input mode", read the RM; only that here the signal is not "split" from one input to two channels, and the other channel uses rising edge. So, you can reset the timer on the first channel using the slave-mode-controller, so you wouldn't need to perform the calculation the the second channel's capture register would contain the time difference; but there's a delay between the first edge and the reset, I don't remember 2 or 3 cycles, ST does not specify it. We've discussed it here some time ago.
JW