/////////////////////////////////////////////////////////////////////////////////////
//
//	FILE:           PCA_Capture_Demo.Txt
//	AUTHOR:         Neo (Hsin-Chih Lin)
//	COPYRIGHT:      (c) Megawin Technology Co., Ltd.
//	CREATED:        2008.2.20
//	PURPOSE:        Demo PCA Capture Document
//	Description:
//              Input:11MHz clock to 8051.
//              Input:
//                  MPC82G516
//                    PWM0 -> P1.2
//                    PWM1 -> P1.3
//                    PWM2 -> P1.4
//                    PWM3 -> P1.5
//                    PWM4 -> P1.6
//                    PWM5 -> P1.7
//                  MPC82x52 & MPC82x54
//                    PWM0 -> P3.7
//                    PWM1 -> P3.5
//                    PWM2 -> P2.0
//                    PWM3 -> P2.4
//              Output:
//                  P3.4 generate a signal to PWM0(P1.2).(width increasingly)
//              Detail:MPC82_PCA_Capture_Demo.JPG
//
/////////////////////////////////////////////////////////////////////////////////////


P3.4 output signal:

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

You can set capture by negative-edge(CCAPMx = 0x11) ,by positive-edge(CCAPMx = 0x21)
or by transition(CCAPMx = 0x31)

When captured, MCU will save count(TH,TL) to CCAPxH and CCAPxL.
The picture as below show when will capture.

negative-edge:

  ----+ +--+   +----+     +------+       +--------+         +----------+
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      +-+  +---+    +-----+      +-------+        +---------+          +--
      |    |        |            |                |                    |
      +    +        +            +                +                    +
      C    C        C            C                C                    C

C : Capture

positive-edge:

  ----+ +--+   +----+     +------+       +--------+         +----------+
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      +-+  +---+    +-----+      +-------+        +---------+          +--
        |      |          |              |                  |
        +      +          +              +                  +
        C      C          C              C                  C

transition:

  ----+ +--+   +----+     +------+       +--------+         +----------+
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      | |  |   |    |     |      |       |        |         |          |
      +-+  +---+    +-----+      +-------+        +---------+          +--
      | |  |   |    |     |      |       |        |         |          |
      + +  +   +    +     +      +       +        +         +          +
      C C  C   C    C     C      C       C        C         C          C

PS:If you use Keil C51 to complier assembly code you need to do this

Menu bar -> Flash -> Configure Flash Tools
Change to A51 option and you can see "Special Function Registers"
then disable "Define 8051 SFR Names"
