Hello,
To capture a PWM signal, I assume that the frequency is constant, you must measure the pulse length of the incoming signal.
So set the TPMCnSC to interrupt to Capture on a rising edge. Set a RisingEdgeFlag. Enable the interrupt.
In the interrupt routine, you read the TPMCnV register and save it.
You change the TPMCnSC to Capture on falling edge. Clear the RisingEdge flag.
The next time you get an interrupt, read the TPMCnV register and subtract the last TPMCnV register.
There you have the pulse length.
Note that the subtraction must be a 16 bit subtraction.
Also the TPMMOD register should not be changed.
This will take automatically take care of when the the timer counter overlaps.
At last, you must adjust the frequency to the incoming pulses. This is done by adjusting the PS2
S1
S0 bits in the TPMSC register.
Adjust it so that the longest pulse lenght does not make the 16 bit counter to wrap.
Yes, I think that is about it.
Regards,
Ake