The following program determine the period of a square wave as by

advertisement

Electrical Engineering Technology

SUNY College of Technology, Alfred, NY

Embedded Controller Applications ELET 3144

Spring Semester 2008

Input Capture Registers

There are 3 Input Capture Registers in the 68HC11 , TIC1, TIC2 and TIC3 , and they are 16 bit registers. They are connected to pins PA2, PA1 and PA0 ( Input only pins) at Port A.

These registers make a capture when an edge occurs on one of these input pins. When a capture is made on one of the registers, the time of the capture (input capture) is copied from the TCNT register into the I nput C apture

Register ( TIC ). There are three 16-bit TIC registers (TIC1, TIC2, TIC3), at memory locations $1010 to $1015

The I nput C aptures are controlled by the edge bits in TCTL2 ($1021) in the following way:

TCTL2 at $1021

0 0 EDG1A EDG2B EDG2A EDG3B EDG3A

EDGxB EDGxA Configuration

0

1

1

1

0

1

Capture on rising edges only

Capture on falling edge only

Capture on any edge (rising or falling)

Example 1.

The time of a falling edge on pin PA1 must be detected. How must TCNTL2 be set up to do this?

PA1 is connected to TIC2 ( I nput C apture Register 2). The previous table shows that the edge bits must be 1 and 0 , respectively, to capture a falling edge, thus the code:

LDAA #$08

STAA $1021 will set up TCTL2 to capture the time of a falling edge on PA1.

Input Flags and Interrupts.

Bits 0, 1 and 2 of the TFLG 1 register, at $1023, are used to signal an input capture on registers 3, 2,and 1, respectively, as shown in the following figure,

TMSK1 at $1022

OC1I OC2I OC3I OC4I OC5I IC1I IC2I IC3I

TFLG1 at $1023

OC1F OC2F OC3F OC4F OC5F IC1F IC2F IC3F

If a capture is made, the flag will set. The flag can be cleared by writing a " 1 " into its bit position.

The corresponding interrupt bit is in TMSK1.

If this bit is set, a capture will cause an interrupt in accordance with the following table:

Register

TIC1

TIC2

TIC3

Pin Location

PA2

PA1

PA0

INTERRUPT VECTOR

$FFEE - $FFEF

$FFEC - $FFED

$FFEA - $FFEB

PSEUDO-VECTOR

$00E8-$00EA

$00E5-$00E7

$00E2-$00E4

Example 2. Determining the Period of a Square Wave.

The following program determines the period of a square wave by finding the time between rising edges. The

TCTL at $1021 is set up to detect rising edges on PA0 . Then the program jumps to SUB2 , which clears the input capture flag IC3F, and waits until it is set again. The time of its setting is stored in TIC3 , at $1014 and $1015 . This time is saved in memory (at location FIRST ) and SUB2 is executed again to get the time of the next positive edge.

The difference between the times is a measure of pulse width.

; *** This is a program to determine the period of a square wave

; *** connected to PA0. PA0 is connected to TIC3

TCTL: EQU $21

TFLG1: EQU $23

FIRST: FDB

RESULT: FDB

BEGIN: LDX #$1000

LDAA

STAA

JSR

LDD

JSR

LDD

SUBD

#$01

TCTL,X

SUB2

TIC3,X

SUB2

TIC3,X

FIRST

; Set the edge bits for IC3

; to capture on rising edges

; Clear IC3F and wait until it sets

; Save time of first edge

; Clear IC3F and wait until it sets

; Get time of next edge

; Subtract to get the time difference

SWI ; End of main program

; * Subroutine to clear the input capture flag IC3F, and then wait until it sets again

SUB2: LDAA #$01 ; Clear the ICF3

LOOP: BRCLR TFLG1,X $01 LOOP

RTS

END

NOTE:

; Wait until it sets

This program works for any period less than 32.77

ms. If the period is longer, the TCNT register will completely roll over at least once. In this case the number of times TCNT rolls around must be counted by counting the number of time TOF sets. Thus TOF must be cleared at the beginning of the program, and it must be monitored as well as the input capture flag, IC3F .

For this case, the time between pulses can be measured as follows:

1. If the time of the second pulse is greater than the time of the first pulse, subtract them to find the difference. Then add 32.77

ms times the number of TOF ’s

2. If the time of the second pulse is less than the time of the first pulse, subtract the time of the first pulse from the time of the second pulse. Then subtract 1 from the number of TOF s. Then multiply this result by 32.77

ms and add it to the previous result.

Download