USING INPUT CAPTURE ON THE HC12

Input Capture: Connect a digital signal to a pin of Port T. Can capture the time of an edge (rising, falling or either) - the edge will latch the value of TCNT into TCx register. This is used to measure the difference between two times.

To use Port T Pin x as an input capture pin:

1.
Turn on timer subsystem (1 -> Bit 7 of TSCR reg)
2.
Set prescaler (TMSK2 reg). To get most accuracy set overflow rate as small as possible, but larger than the maximum time difference possible.
3.
Set up PTx as IC (0 -> bit x of TIOS reg)
4.
Set edge to capture (EDGxB EDGxA of TCTL 3-4 regs)

EDGxB EDGxA  
0 0 Disabled
0 1 Rising Edge
1 0 Falling Edge
1 1 Either Edge

5.
Clear flag (1 -> bit x of TFLG1 reg, 0 -> all other bits of TFLG1)
6.
If using interrupts
(a)
Enable interrupt (1 -> bit x of TMSK1 reg)
(b)
Clear I bit of CCR (cli or enable())
(c)
In interrupt service routine,
i.
read time of edge from TCx
ii.
Clear flag (1 -> bit x of TFLG1 reg, 0 -> all other bits of TFLG1)
7.
If polling in main program
(a)
Wait for Bit x of TFLG1 to become set
(b)
Read time of edge from TCx
(c)
Clear flag (1 -> bit x of TFLG1 reg, 0 -> all other bits of TFLG1)



Bill Rison
2000-02-25