Using a TPM timer as PWM in MC9S08SH32, is it posible to read the output pin of the PWM while the PWM is running?
Thanks in advance.
You can surmise the current PWM output state by comparing the TPMCNT value withTPMCnV. However, you would need to employ a separate GP input pin to directly determine the current state. Whilst the PWM signal is output, my understanding is that the GPIO register is disconnected from the pin.
I have done a test and I think it works.
I have configured the TPM as PWM and the output pin as input.
Using one ISR for TPM overflow and other for TPM channel, I read the output pin and copy the value to another pin. And in the oscilloscope I can see the pin changing correctly.
With an interrupt occurring after each output transition, you really don't need to directly read the pin state, as you already know the current PWM state by virtue of the specific interrupt type generated. Of course, the ISR execution will be delayed by the latency of each interrupt, so the replica waveform will lag the original waveform.
Yes, I know. I was just testing if the output pin can be read.
It seems it works (the pin can be read), but I don't know if it is reliable, because reading the datasheet I don't see what is read in a pin for which the alternate function is enabled.
Retrieving data ...