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
    1. Enable interrupt (1 -> bit x of TMSK1 reg)
    2. Clear I bit of CCR (cli or enable())
    3. In interrupt service routine,
      1. read time of edge from TCx
      2. Clear flag (1 -> bit x of TFLG1 reg, 0 -> all other bits of TFLG1)
  7. If polling in main program
    1. Wait for Bit x of TFLG1 to become set
    2. Read time of edge from TCx
    3. Clear flag (1 -> bit x of TFLG1 reg, 0 -> all other bits of TFLG1)



Bill Rison
2001-02-26