Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
8XC196Kx,8XC196Jx,87C196CA microcontroller family user's manual.1995.pdf
Скачиваний:
65
Добавлен:
23.08.2013
Размер:
3.97 Mб
Скачать

EVENT PROCESSOR ARRAY (EPA)

With this method, the resolution of the EPA (Figure 10-8 on page 10-18 and Figure 10-9 on page 10-19) determines the maximum PWM output frequency. (Resolution is the minimum time required between a capture or compare.) At 16 MHz, a 250 ns resolution results in a maximum PWM of 4 MHz.

10.5 PROGRAMMING THE EPA AND TIMER/COUNTERS

This section discusses configuring the port pins for the EPA and the timer/counters; describes how to program the timers, the capture/compare channels, and the compare-only channels; and explains how to enable the EPA interrupts.

10.5.1 Configuring the EPA and Timer/Counter Port Pins

Before you can use the EPA, you must configure the pins of port 1 and port 6 to serve as the spe- cial-function signals for the EPA and, optionally, for the timer/counter clock source and direction control signals. See “Bidirectional Ports 1, 2, 5, and 6” on page 6-4 for information about configuring the port pins.

NOTE

If you use T2CLK as the timer 2 input clock, you cannot use EPA capture/compare channel 0. If you use T2DIR as the timer 2 direction-control source, you cannot use EPA capture/compare channel 1.

Table 10-2 on page 10-3 lists the pins associated with the EPA and the timer/counters. Pins that are not being used for an EPA channel or timer/counter can be configured as standard I/O.

10.5.2 Programming the Timers

The control registers for the timers are T1CONTROL (Figure 10-8) and T2CONTROL (Figure 10-9). Write to these registers to configure the timers. Write to the TIMER1 and TIMER2 registers to load a specific timer value.

10-17

8XC196Kx, Jx, CA USER’S MANUAL

T1CONTROL

Address:

1F98H

 

Reset State:

00H

The timer 1 control (T1CONTROL) register determines the clock source, counting direction, and count rate for timer 1.

7

 

 

 

 

 

 

 

 

 

 

 

 

0

CE

UD

 

M2

 

 

M1

 

M0

P2

P1

 

P0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

Bit

 

 

 

 

 

 

Function

 

 

 

Number

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

CE

Counter Enable

 

 

 

 

 

 

 

 

 

This bit enables or disables the timer. From reset, the timers are

 

 

 

 

disabled and not free running.

 

 

 

 

 

 

 

0

= disables timer

 

 

 

 

 

 

 

 

 

1

= enables timer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6

UD

Up/Down

 

 

 

 

 

 

 

 

 

 

This bit determines the timer counting direction, in selected modes (see

 

 

 

mode bits, M2:0)

 

 

 

 

 

 

 

 

 

0

= count down

 

 

 

 

 

 

 

 

 

1

= count up

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5:3

M2:0

EPA Clock Direction Mode Bits

 

 

 

 

 

 

 

These bits determine the timer clocking source and direction control

 

 

 

source.

 

 

 

 

 

 

 

 

 

 

M2

M1

M0

Clock Source

Direction Source

 

 

 

 

0

 

0

 

0

FOSC/4

UD bit (T1CONTROL.6)

 

 

 

 

X

 

0

 

1

T1CLK Pin

UD bit (T1CONTROL.6)††

 

 

 

 

0

 

1

 

0

F /4

T1DIR Pin††

 

 

 

 

 

 

 

 

 

OSC

T1DIR Pin††

 

 

 

 

0

 

1

 

1

T1CLK Pin

 

 

 

 

1

 

1

 

1

quadrature clocking using T1CLK and T1DIR pins††

 

 

 

If an external clock is selected, the timer counts on both the rising and

 

 

 

falling edges of the clock.

 

 

 

 

 

 

 

††

These modes are reserved on the 8XC196CA, Jx devices.

 

 

 

 

 

 

 

 

2:0

P2:0

EPA Clock Prescaler Bits

 

 

 

 

 

 

 

These bits determine the clock prescaler value.

 

 

 

 

 

 

P2

P1

P0

Prescaler

 

Resolution (at 16 MHz)

 

 

 

0

 

0

 

0

divide by 1 (disabled)

250 ns

 

 

 

 

0

 

0

 

1

divide by 2

 

500 ns

 

 

 

 

0

 

1

 

0

divide by 4

 

1 µs

 

 

 

 

0

 

1

 

1

divide by 8

 

2 µs

 

 

 

 

1

 

0

 

0

divide by 16

 

4 µs

 

 

 

 

1

 

0

 

1

divide by 32

 

8 µs

 

 

 

 

1

 

1

 

0

divide by 64

 

16 µs

 

 

 

 

1

 

1

 

1

reserved

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 10-8. Timer 1 Control (T1CONTROL) Register

10-18

EVENT PROCESSOR ARRAY (EPA)

T2CONTROL

Address:

1F9CH

 

Reset State:

00H

The timer 2 control (T2CONTROL) register determines the clock source, counting direction, and count rate for timer 2.

7

 

 

 

 

 

 

 

 

 

 

 

 

 

0

CE

UD

 

M2

 

 

M1

 

M0

 

P2

P1

 

P0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

Bit

 

 

 

 

 

 

Function

 

 

 

Number

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

CE

Counter Enable

 

 

 

 

 

 

 

 

 

 

This bit enables or disables the timer. From reset, the timers are

 

 

 

 

disabled and not free running.

 

 

 

 

 

 

 

0

= disables timer

 

 

 

 

 

 

 

 

 

 

1

= enables timer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6

UD

Up/Down

 

 

 

 

 

 

 

 

 

 

 

This bit determines the timer counting direction, in selected modes (see

 

 

 

mode bits, M2:0).

 

 

 

 

 

 

 

 

 

 

0

= count down

 

 

 

 

 

 

 

 

 

 

1

= count up

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5:3

M2:0

EPA Clock Direction Mode Bits.

 

 

 

 

 

 

 

These bits determine the timer clocking source and direction source

 

 

 

M2

M1

M0

Clock Source

Direction Source

 

 

 

 

0

 

0

 

0

FOSC/4

UD bit (T2CONTROL.6)

 

 

 

 

X

 

0

 

1

T2CLK Pin

UD bit (T2CONTROL.6)

 

 

 

 

0

 

1

 

0

FOSC/4

T2DIR Pin

 

 

 

 

0

 

1

 

1

T2CLK Pin

T2DIR Pin

 

 

 

 

1

 

0

 

0

timer 1 overflow

UD bit (T2CONTROL.6)

 

 

 

 

1

 

1

 

0

timer 1

same as timer 1

 

 

 

 

1

 

1

 

1

quadrature clocking using T2CLK and T2DIR pins

 

 

 

If an external clock is selected, the timer counts on both the rising and

 

 

 

falling edges of the clock.

 

 

 

 

 

 

 

 

 

 

 

2:0

P2:0

EPA Clock Prescaler Bits

 

 

 

 

 

 

 

These bits determine the clock prescaler value.

 

 

 

 

 

 

P2

P1

P0

Prescaler

 

Resolution (at 16 MHz)

 

 

 

0

 

0

 

0

divide by 1 (disabled)

250 ns

 

 

 

 

0

 

0

 

1

divide by 2

 

500 ns

 

 

 

 

0

 

1

 

0

divide by 4

 

1 µs

 

 

 

 

0

 

1

 

1

divide by 8

 

2 µs

 

 

 

 

1

 

0

 

0

divide by 16

 

4 µs

 

 

 

 

1

 

0

 

1

divide by 32

 

8 µs

 

 

 

 

1

 

1

 

0

divide by 64

 

16 µs

 

 

 

 

1

 

1

 

1

reserved

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 10-9. Timer 2 Control (T2CONTROL) Register

10-19

8XC196Kx, Jx, CA USER’S MANUAL

10.5.3 Programming the Capture/Compare Channels

The EPAx_CON register controls the function of its assigned capture/compare channel. The registers for EPA0, EPA2, and EPA4–9 are identical. The registers for EPA1 and EPA3 have an additional bit, the remap bit (RM), which is used to enable and disable remapping for high-speed PWM generation (see “Generating a High-speed PWM Output” on page 10-16). This added bit (bit 8) requires an additional byte, so EPA1_CON and EPA3_CON must be addressed as words, while the others can be addressed as bytes.

To program a compare event, write to EPAx_CON (Figure 10-10) to configure the EPA capture/compare channel and then load the event time into EPAx_TIME. To program a capture event, you need only write to EPAx_CON. Table 10-6 shows the effects of various combinations of EPAx_CON bit settings.

Table 10-6. Example Control Register Settings and EPA Operations

Capture Mode

TB

CE

MODE

RE

AD

ROT

ON/RT

 

Operation

7

6

5

4

3

2

1

0

 

 

 

X

0

0

0

0

 

None

X

0

0

1

X

X

X

 

Capture on falling edges

X

0

1

0

X

X

X

 

Capture on rising edges

X

0

1

1

X

X

X

 

Capture on both edges

X

0

X

1

X

1

X

 

Capture on falling edge and reset opposite timer

X

0

1

X

X

1

X

 

Capture on rising edge and reset opposite timer

X

0

0

1

1

X

X

 

Start A/D conversion on falling edge

X

0

1

0

1

X

X

 

Start A/D conversion on rising edge

 

 

 

 

 

 

 

Compare Mode

 

 

 

 

 

 

 

 

 

TB

CE

MODE

RE

AD

ROT

ON/RT

 

Operation

7

6

5

4

3

2

1

0

 

 

 

X

1

0

0

X

0

None

X

1

0

1

X

X

X

X

 

Clear output pin

X

1

1

0

X

X

X

X

 

Set output pin

X

1

1

1

X

X

X

X

 

Toggle output pin

X

1

X

X

X

X

0

1

 

Reset same timer

X

1

X

X

X

X

1

1

 

Reset opposite timer

X

1

X

X

X

1

X

X

 

Start A/D conversion

NOTES: — = bit is not used

X = bit may be used, but has no effect on the described operation. These bits cause other operations to occur.

10-20

EVENT PROCESSOR ARRAY (EPA)

EPAx_CON

x = 0–9 (8XC196K x)

x = 0–3, 8, 9 (8XC196CA, J x)

Address:

1F60H + (x * 4)

Reset State:

F700H (x = 1 & 3)

 

00H(x = 0, 2, 4–9)

The EPA control (EPAx_CON) registers control the functions of their assigned capture/compare channels. The registers for EPA0, EPA2, and EPA4–9 are identical. The registers for EPA1 and EPA3 have an additional bit, the remap bit. This added bit (bit 8) requires an additional byte, so EPA1_CON and EPA3_CON must be addressed as words, while the others can be addressed as bytes.

 

 

15

 

 

 

 

 

 

 

 

 

 

8

x = 1, 3

 

 

RM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

M0

 

 

RE

 

AD

ROT

 

ON/RT

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

x = 0, 2, 4–9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

M0

 

 

RE

 

AD

ROT

 

ON/RT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

Bit

 

 

 

 

Function

 

 

 

 

Number

 

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

15:9

 

Reserved; always write as zeros.

 

 

 

 

 

 

8

 

RM

Remap Feature

 

 

 

 

 

 

 

 

 

 

 

 

 

The Remap feature applies to the compare mode of the EPA1 and EPA3

 

 

 

 

only.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

When the remap feature of EPA1 is enabled, EPA capture/compare

 

 

 

 

channel 0 shares output pin EPA1 with EPA capture/compare channel 1.

 

 

 

 

When the remap feature of EPA3 is enabled, EPA capture/compare

 

 

 

 

channel 2 shares output pin EPA3 with EPA capture/compare channel 3.

 

 

 

 

0 = remap feature disabled

 

 

 

 

 

 

 

 

 

 

 

 

1 = remap feature enabled

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

 

TB

Time Base Select

 

 

 

 

 

 

 

 

 

 

 

 

 

Specifies the reference timer.

 

 

 

 

 

 

 

 

 

 

 

 

0 = Timer 1 is the reference timer and Timer 2 is the opposite timer

 

 

 

 

1 = Timer 2 is the reference timer and Timer 1 is the opposite timer

 

 

 

 

A compare event (start of an A/D conversion; clearing, setting, or toggling

 

 

 

 

an output pin; and/or resetting either timer) occurs when the reference

 

 

 

 

timer matches the time programmed in the event-time register.

 

 

 

 

 

When a capture event (falling edge, rising edge, or an edge change on

 

 

 

 

the EPAx pin) occurs, the reference timer value is saved in the EPA event-

 

 

 

 

time register (EPAx_TIME).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These bits apply to the EPA1_CON and EPA3_CON registers only.

Figure 10-10. EPA Control (EPAx_CON) Registers

10-21

8XC196Kx, Jx, CA USER’S MANUAL

EPAx_CON (Continued) x = 0–9 (8XC196K x)

x = 0–3, 8, 9 (8XC196CA, J x)

Address:

1F60H + (x * 4)

Reset State:

F700H (x = 1 & 3)

 

00H(x = 0, 2, 4–9)

The EPA control (EPAx_CON) registers control the functions of their assigned capture/compare channels. The registers for EPA0, EPA2, and EPA4–9 are identical. The registers for EPA1 and EPA3 have an additional bit, the remap bit. This added bit (bit 8) requires an additional byte, so EPA1_CON and EPA3_CON must be addressed as words, while the others can be addressed as bytes.

 

 

15

 

 

 

 

 

 

 

 

 

 

8

x = 1, 3

 

 

 

RM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

 

RE

 

AD

ROT

ON/RT

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

x = 0, 2, 4–9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

 

RE

 

AD

ROT

ON/RT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

Bit

 

 

 

 

 

Function

 

 

 

Number

 

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6

 

CE

Compare Enable

 

 

 

 

 

 

 

 

 

 

 

 

 

Determines whether the EPA channel operates in capture or compare

 

 

 

 

mode.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 = capture mode

 

 

 

 

 

 

 

 

 

 

1 = compare mode

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5:4

 

M1:0

EPA Mode Select

 

 

 

 

 

 

 

 

 

 

In capture mode, specifies the type of event that triggers an input capture.

 

 

 

 

In compare mode, specifies the action that the EPA executes when the

 

 

 

 

reference timer matches the event time.

 

 

 

 

 

 

 

M1

M0

Capture Mode Event

 

 

 

 

 

 

 

0

0

no capture

 

 

 

 

 

 

 

 

 

 

0

1

capture on falling edge

 

 

 

 

 

 

 

1

0

capture on rising edge

 

 

 

 

 

 

 

1

1

capture on either edge

 

 

 

 

 

 

 

M1

M0

Compare Mode Action

 

 

 

 

 

 

 

0

0

no output

 

 

 

 

 

 

 

 

 

 

0

1

clear output pin

 

 

 

 

 

 

 

 

 

1

0

set output pin

 

 

 

 

 

 

 

 

 

 

1

1

toggle output pin

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3

 

RE

Re-enable

 

 

 

 

 

 

 

 

 

 

 

 

 

Re-enable applies to the compare mode only. It allows a compare event

 

 

 

 

to continue to execute each time the event-time register (EPAx_TIME)

 

 

 

 

matches the reference timer rather than only upon the first time match.

 

 

 

 

0 = compare function is disabled after a single event

 

 

 

 

 

 

1 = compare function always enabled

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These bits apply to the EPA1_CON and EPA3_CON registers only.

Figure 10-10. EPA Control (EPAx_CON) Registers (Continued)

10-22

EVENT PROCESSOR ARRAY (EPA)

EPAx_CON (Continued) x = 0–9 (8XC196K x)

x = 0–3, 8, 9 (8XC196CA, J x)

Address:

1F60H + (x * 4)

Reset State:

F700H (x = 1 & 3)

 

00H(x = 0, 2, 4–9)

The EPA control (EPAx_CON) registers control the functions of their assigned capture/compare channels. The registers for EPA0, EPA2, and EPA4–9 are identical. The registers for EPA1 and EPA3 have an additional bit, the remap bit. This added bit (bit 8) requires an additional byte, so EPA1_CON and EPA3_CON must be addressed as words, while the others can be addressed as bytes.

 

 

15

 

 

 

 

 

 

 

 

 

 

 

8

x = 1, 3

 

 

 

RM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

 

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

 

RE

 

AD

ROT

 

ON/RT

 

 

 

7

 

 

 

 

 

 

 

 

 

 

 

0

x = 0, 2, 4–9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

 

RE

 

AD

ROT

 

ON/RT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

Bit

 

 

 

 

 

Function

 

 

 

 

Number

 

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2

 

AD

A/D Conversion

 

 

 

 

 

 

 

 

 

 

 

 

 

Allows the EPA to start an A/D conversion that has been previously set up

 

 

 

 

in the A/D control registers. To use this feature, you must select the EPA

 

 

 

 

as the conversion source in the AD_CONTROL register.

 

 

 

 

 

0 = causes no A/D action

 

 

 

 

 

 

 

 

 

 

 

 

1 = EPA capture or compare event triggers an A/D conversion

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

ROT

Reset Opposite Timer

 

 

 

 

 

 

 

 

 

 

 

 

Controls different functions for capture and compare modes.

 

 

 

 

 

In Capture Mode:

 

 

 

 

 

 

 

 

 

 

 

 

 

0 = causes no action

 

 

 

 

 

 

 

 

 

 

 

 

1 = resets the opposite timer

 

 

 

 

 

 

 

 

 

 

In Compare Mode:

 

 

 

 

 

 

 

 

 

 

 

 

 

ROT selects the timer that is to be reset if the RT bit is set:

 

 

 

 

 

0 = selects base timer

 

 

 

 

 

 

 

 

 

 

 

 

1 = selects opposite timer

 

 

 

 

 

 

 

 

 

 

 

 

The TB bit (bit 7) selects which timer is the reference timer and which

 

 

 

 

timer is the opposite timer.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These bits apply to the EPA1_CON and EPA3_CON registers only.

Figure 10-10. EPA Control (EPAx_CON) Registers (Continued)

10-23

8XC196Kx, Jx, CA USER’S MANUAL

EPAx_CON (Continued) x = 0–9 (8XC196K x)

x = 0–3, 8, 9 (8XC196CA, J x)

Address:

1F60H + (x * 4)

Reset State:

F700H (x = 1 & 3)

 

00H(x = 0, 2, 4–9)

The EPA control (EPAx_CON) registers control the functions of their assigned capture/compare channels. The registers for EPA0, EPA2, and EPA4–9 are identical. The registers for EPA1 and EPA3 have an additional bit, the remap bit. This added bit (bit 8) requires an additional byte, so EPA1_CON and EPA3_CON must be addressed as words, while the others can be addressed as bytes.

 

 

15

 

 

 

 

 

 

 

 

 

 

8

x = 1, 3

 

 

 

RM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

RE

 

 

AD

ROT

ON/RT

 

 

 

7

 

 

 

 

 

 

 

 

 

 

0

x = 0, 2, 4–9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TB

CE

M1

 

M0

 

RE

 

 

AD

ROT

ON/RT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

Bit

 

 

 

 

 

Function

 

 

 

Number

 

Mnemonic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

ON/RT

Overwrite New/Reset Timer

 

 

 

 

 

 

 

 

 

 

 

The ON/RT bit functions as overwrite new in capture mode and reset

 

 

 

 

timer in compare mode.

 

 

 

 

 

 

 

 

 

 

 

In Capture Mode (ON):

 

 

 

 

 

 

 

 

 

 

 

An overrun error is generated when an input capture occurs while the

 

 

 

 

event-time register (EPAx_TIME) and its buffer are both full. When an

 

 

 

 

overrun occurs, the ON bit determines whether old data is overwritten or

 

 

 

 

new data is ignored:

 

 

 

 

 

 

 

 

 

 

 

 

0 = ignores new data

 

 

 

 

 

 

 

 

 

 

 

1 = overwrites old data in the buffer

 

 

 

 

 

 

 

 

 

In Compare Mode (RT):

 

 

 

 

 

 

 

 

 

 

 

0 = disables the reset function

 

 

 

 

 

 

 

 

 

1 = resets the ROT-selected timer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These bits apply to the EPA1_CON and EPA3_CON registers only.

Figure 10-10. EPA Control (EPAx_CON) Registers (Continued)

10-24

Соседние файлы в предмете Электротехника