Large amount of jitter when using ECT as OC to generate a pulse train

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

Large amount of jitter when using ECT as OC to generate a pulse train

2,153 Views
dwhite
Contributor I
I am performing a simple test to generate pulses from a ECT pin. I am measuring an unexpectedly large (4-8uS) amount of jitter with my o-scope. My system requires much tighter control of the timer outputs than this. Here are more details...
 
MC9S12XDT256 running with 16MHz xtal and PLL set for 40MHz.
The PTPSR is set to 19 which should result in a 500nS time base for TCNT.
 
The test simply reads the TCTL2_OL bit for that channel and calls a different function if the edge was just commanded to go high or low. Then both functions add a constant value (2000) to the TCx register in the OC isr and set or clear the TCLT2_OL bit for the next edge. So, this should result in a 1mS square wave. With my o-scope it measures between 9992uS and 9996uS. So, the center isn't even around 1mS (always short) and there is about 4uS of jitter.
 
I tried this with the TCTL2_Ox settings to toggle on output compare and the jitter went away. Does the changing of the TCTL2_OL bit in my ISR somehow mess up the output compare time?
 
In my application, I need to handle the high time and low time seperately and this seems like the best way to handle it. If I use PTIT to query the state of the pin, it could possibly be delayed due to line capacitance, etc. and execute the wrong function. Am I wrong about this? Is there a register bit that I can read that would represent the commanded pin state when TCTL2_Ox is set for toggle action?
 
Does anyone else have any ideas on what the best way to handle this is?
 
-Dan
 
 
Labels (1)
0 Kudos
Reply
2 Replies

624 Views
Steve
NXP Employee
NXP Employee
Dan,
  The only obvious source of jitter in your approach is the PLL but you say that the timer toggling on its own is fine so it can't be related to that.
   You say you modify the TCx register by adding to its previous value which is the correct thing to do. The pin settings don't have an effect on the timing. When you set the pin to toggle were you using exactly the same interrupt code (without the TCTLx change)?
  If you post the source code it may help someone here to spot the problem. You can also raise a service request and that may be quicker.
0 Kudos
Reply

624 Views
dwhite
Contributor I

I found my mistake. I forgot to set the OMx bit in TCTL2. So, when I thought I was changing from "clear" action to "set" with the OLx bit, I was actually changing from "disabled" to "toggle". So, the state was changing in the ISR and not at the OC time. Now that I have set the OMx bit, all is well.....thanks for your help.

-Dan

0 Kudos
Reply