Understanding Input capture and Output Compare.

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

Understanding Input capture and Output Compare.

10,988 Views
rayhall
Contributor V

I am trying to understand input capture and output compare. Is the following statement correct.

 

The S12XE 144 pin has eight pins (PT0-PT7) that can be used for either input capture or output compare. There is eight 24 bit timers. These timers can be used for input capture or output compare, but not both at the same time. Timers when used as output compare can be setup to have no output pin, and have a interrupt on compare instead.

 

Ray.

Labels (1)
0 Kudos
6 Replies

1,893 Views
kef
Specialist I

No, these are not correct. There are eight 24 bit periodic interrupt timers (PIT), which have nothing in common with input capture and output compare.

On S12XE you have one ECT timer and one TIM timer. ECT has more features than TIM, but both ECT and TIM have single 16bit counter and eight IC/OC channels. Each channel can be setup to operate in input capture (IC) or output compare (OC) mode. When voltage level at IC pinX toggles to right direction (falling/rising/any), contents of timer counter TCNT  is transferred to TCx register and TFLG1x bit is set. Interrupt is generated in case TIEx bit is set.

Output compare function compares TCNT register with value stored in TCx register. When counter matches TCx TFLG1x bit is set. Interrupt occurs in case TIEx bit is set. Optionally you can set up output compare pin to automatically set/clear/toggle when TCNT==TCx.


0 Kudos

1,893 Views
rayhall
Contributor V

Edward thank you for that. I still have questions.

I am desining the schematic for a automotive ECU. I am unsure how to assign pins for these.

4 x Crankshaft and camshaft trigger signal (input capture).

6 x Injectors (output compare).

6 x Ignition (output compare).

Ray.

0 Kudos

1,893 Views
rayhall
Contributor V

This is how I have it now.

IOC0  = Ignition 1

IOC1  = Ignition 2

IOC2  = Ignition 3

IOC3  = Ignition 4

IOC4  = Ignition 5

IOC5  = Ignition 6

IOC6 = Crankshaft signal

IOC7 = Camshaft signal 1

TIMIOC0 = Injector 1

TIMIOC1 = Injector 2

TIMIOC2 = Injector 3

TIMIOC3 = Injector 4

TIMIOC4 = Injector 5

TIMIOC5 = Injector 6

TIMIOC6 = Camshaft signal 2

TIMIOC7 = Camshaft signal 3

Correct ?

Ray.

0 Kudos

1,893 Views
kef
Specialist I

I have no experience with ECU's, but your plan should work.

I would try to not use all available IC/OC channels. It is nice to have at least one spare channel for precise software timing control. Since IgnitionN (and InjectorN) need to be pulsed not simultaneously but sequentially, it is possible to have just one OC pin for all IgnitionN. 3 to 6 simple I/O pins could be used to select which cylinder should be pulsed next. Maybe it's more difficult to code, but would allow to dedicate more channels for other timing purposes.

Using two timers (ECT and TIM) you may need to either synchronize timers or determine TCNT difference between ECT and TIM and take that difference into account. The problem is you can't enable TIC and ECT simultaneously. Enabling them in two adjacent code lines will make them ticking similar, but not the same. One of timers will increment TCNT N CPU cycles later, where N is how much CPU cycles does it take to enable one timer (provided interrupts are disabled while you are enabling timers).

0 Kudos

1,893 Views
rayhall
Contributor V

If I could use two ECT output compare channels, one for injectors and the other for ignition this would be ideal. If these can be made to internally interrupt rather then toggle the channel pins, I could then create a scheduler in each interrupt to toggle other GP pins that control the injector and ignition.

I cannot find in the documentation were you can set output compare to interrupt rather then toggle a pin. I know the Atmel I used in the past had this option.

Ray.

0 Kudos

1,893 Views
kef
Specialist I

TIOS bits allows to choose IC or OC.

TCTL1/TCTL2 registers determine toggle mode for each channel. One of 4 available modes is OMx=OLx=0, which is 'no output compare action on the timer output signal'. It means TFLG1 flag still is set on interrupt is generated when TIE bit is set, but pin is not toggled (toggle/set/clear) automatically. You also should set corresponding channel bit in OCPD register, else you won't be able to toggle pin writing to PTT, PTR or PTP registers. TIM pins are routable either to PTR or PTP, see PTRRR register.

To enable OC interrupt: enable timer (TEN bit), set up required TIOS bit, set up TCTL1/TCTL2 bits for your channel, set OCPD bit in case you don't want automatic toggle, set up TCx compare value, clear bit in TFLG1, set interrupt enable bit in TIE.

Automatic pin toggle/set/clear also generate interrupts. If you wish you may use OC pin action with OC interrupt disabled, just clear bit in TIE register.

0 Kudos