Reading PWM output pin while PWM is running

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading PWM output pin while PWM is running

698 Views
zorrotz
Contributor III

Hi,

 

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.

Labels (1)
0 Kudos
4 Replies

370 Views
bigmac
Specialist III

Hello,

 

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.

 

Regards,

Mac

 

0 Kudos

371 Views
zorrotz
Contributor III

Hello,

 

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.

0 Kudos

371 Views
bigmac
Specialist III

Hello,

 

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.

 

Regards,

Mac

 

0 Kudos

371 Views
zorrotz
Contributor III

Hello,

 

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.

 

 

0 Kudos