Tool/software:
Hello,
I am producing a PWM signal with TIMG12 and using TIMG7 as input capture to measure the period and duty cycle, and it is set as an up-counter.
When a rising edge is detected, the timer value is captured and stored in a variable. The second time a rising edge is detected, the timer value is captured again and stored into another variable
For calculating the period:
- If the second value is greater than the first value , the period is simply the difference between them:
period = second_value - first_value
. - In case of counter overflow (when
second_value
is smaller thanfirst_value
), the period is calculated by accounting for the overflow:period = (MAX_COUNTER_VALUE + TIMER_UNIT) - first_value + second_value
.
Now I want every time the TIMG7 is detecting the first rising edge to reset it self so the TIMG7 is synchron to the PWM Signal and just by looking into the captured value of the second rising edge then you can know the period
I try to achieve that using a cross trigger. In the initialisation I did the following
And inside an interrupt service routine I did the following
I also tried to stop the counter, set the counter to zero and enable the counter but it did not work too
Could you please help me achieve synchronization?
Best regards,
Ali