Output compare questions

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

Output compare questions

1,068 Views
JohnBarber
Contributor II
Hi,
I'm using a HCS08 controller.
I use the TPM1C0 to generate a tick at 1ms.
 
Now I want to implement a timer that gives a time out if two SCI RX interrupts are separated more than 500 us.
 
Is it possible to use another channel of TPM1, say TPM1C1, and in the RX ISR after reading the received data, read the TPM1 counter value, calculate the value that corresponds to +500us, set this value as the TPM1C1 compare value, and then enable output compare interrupt?
 
In pseudo-code:
Code:
Code:ISR{  read received data  disable output compare interupt  read TPM1 counter value  calculate counter value + 500us  enable output compare for TPM1C1  set TPM1C1 compare value}

 
 Will this work?
/John
Labels (1)
0 Kudos
1 Reply

289 Views
bigmac
Specialist III
Hello John,
 
The method that you propose should be workable.  If the channel 1 output compare value is updated each time within the SCI receive ISR, the channel interrupt should never occur with normal SCI data spacing.  It can be likened to a COP timer reset process.
 
Once the TPM channel is initialised, you probably don't need all the steps that you have outlined.  Simply calculate the new output compare value required, and write it to TPM1C1V.  There should usually be no need to re-configure TPM1C1SC each time.
 
Regards,
Mac
 
0 Kudos