sebasira

Problem with Timer Count

Discussion created by sebasira on May 14, 2012
Latest reply on May 15, 2012 by sebasira

Hello everybody... I've got this strange problem. I'm working with CW4.6 and MC9S12A256.

 

I'm using two timer channels  (CH0 and CH7). CH0 for output compare; and CH7 for Input Capture that only interrupts when a falling edge occurs.

 

The Output Compare is ALWAYS running and interupting every 1mseg, When that occurs, I toggle a pin (an output).

 

With an oscilloscope I view the Input Capture pin and the pin that I toggle each time an output compare ocurrs.

Normally, I see this on the oscilloscope.

 

CH0 Output Compare
--+  +--+  +--+  +--+  +--+  +--+  +--+
  |  |  |  |  |  |  |  |  |  |  |  |
  |  |  |  |  |  |  |  |  |  |  |  |
  +--+  +--+  +--+  +--+  +--+  +--+


CH7 Input Capture
--+    +--+ +-+  +-+     +--+  +--+
  |    |  | | |  | |     |  |  |  |
  |    |  | | |  | |     |  |  |  |
  +----+  +-+ +--+ +-----+  +--+  +--+

 

The input capture channel is not important... The important thing is that the Output Compare has always the same high and low time, equal to 1mseg.

 

The problem is that sometimes, the following happens. (only when working with input capture, if I disable it the problem doesn't show)

 

 

CH0 Output Compare
--+  +--+  +-----------------+  +--+  
  |  |  |  |                 |  |  |  
  |  |  |  |                 |  |  |  
  +--+  +--+                 +--+  +--+


CH7 Input Capture
--+    +--+ +-+  +-+     +--+  +--+
  |    |  | | |  | |     |  |  |  |
  |    |  | | |  | |     |  |  |  |
  +----+  +-+ +--+ +-----+  +--+  +--+

 

 

It's difficult to me to explain what I think is happening with words, so I'll put it graphically

 

           +---------------------------------------> (1)

           |  +------------------------------------> (2)

           |  |           +------------------------> (3)

           |  |           |  +---------------------> (4)

           |  |           |  |

--+  +--+  +--|-----------|--+  +--+  
  |  |  |  |                 |  |  |  
  |  |  |  |                 |  |  |  
  +--+  +--+                 +--+  +--+

 

(1)  Let's assume that here the TCNT = 0x0000

(2)  Here the IRQ should happend but it didn't

(3)  Here ocurrs an OVF (TCNT from 0xFFFF to 0)

(4)  Here the TCNT reaches the ch0_REG value

 

Why's that happening??

 

The code in the Output Compare only does this:

TC0 += 12000;   // IRQ every 1msegtoggled_pin = ~toggled_pin; // Toggle pinTFLG1_C0F = 1;// Clear flag

 

And in the Input Capture, I only clear the IRQ flag

 

Thank you in advance!!!



Outcomes