SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
The T24’s capture block is used to collect timing information about external signals. The capture block can be programmed to capture the 24 bit timer value on an edge on the external signal. It can also generate an interrupt on the edge.
The edge control bits can select:
00 = No Capture (Default)
01 = Rising Edge
10 = Falling Edge
11 = Both Edges
For example, to program for both edges:
TimerRegs.T24CAPCTRL.bit.EDGE = 3; //both edges
There are CAP_INT_ENA and CAP_INT_FLAG bits which work much the same as the overflow bits for the 24 bit counter. They are also in the T24CAPCTRL register.
For low speed signals, a single capture block can be used for both edges. For example, to determine the positive pulse width of a signal:
result = TimerRegs.T24CAPDAT.bit.CAP_DAT;
result = TimerRegs.T24CAPDAT.bit.CAP_DAT - result;
Note that overflow handling may be necessary as well. This depends on the expected timing of the signal.
One simple solution is that if the final result is negative, adding 0x1000000, (224) will give the correct result. This is accurate so long as only one overflow has occurred. If there is a possibility of more than one overflow occurring, it will be necessary to keep track of this.
The same approach can apply to any combination of edges.
For measuring fast pulses, it may be necessary to use both capture pins for a single signal. For a fast positive pulse, for example, program one capture register for the rising edge and one for the falling edge. Note that this only works when the low signal time is long enough to permit initialization. If the low going pulse is fast also, it is not possible to tell which edge came first.
There is also a T24CAPIO register which permits using the TCAP pin as a General Purpose I/O pin. It is very straightforward to use. See Section 11.22.5 for more information.
Note that the registers will continue to capture edges. The capture registers do not take the first capture value and hold it. Instead, they will give the time value of the latest edge.
The capture can also come from other sources. There is a CAP_SEL bitfield in the T24CAPCTRL register. It can select from 4 signal sources: