Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
34
Добавлен:
27.04.2015
Размер:
1.98 Mб
Скачать

Timer Interrupt Priorities

9.3 Timer Interrupt Priorities

The timer module has a simple interrupt-priority scheme among its different timers, as shown in Table 9-7. It is important to service timer interrupts with higher priorities in a timely fashion to determine if any timer interrupts with a lower priority are also present.

Table 9-7. Timer Interrupt Priorities

Timer

Priority

 

 

 

 

0

Highest

 

 

1

Middle

 

 

2

Lowest

 

 

9.4 Event Counting with the Timer Module

This section contains examples of how to program some of the timing and counting capabilities of the general-purpose timers. This set of examples is by no means a complete list of either the capabilities or the programming techniques that can be used. Instead, it offers a representative range of what can be accomplished. The timer module can be used as an event counter. Setting the ES bits to 11 configures the timer to count the number of edges (external events) detected on the specified TIO pin. An external event is defined as a rising edge when the INV bit is cleared or as a falling edge when the INV bit is set. After the pin is conditionally inverted, it is synchronized to the Phi clock. Events on the TIO pin can be counted in wait mode, but cannot be counted in stop mode.

NOTE:

The maximum allowed frequency on the TIO pin is the frequency of the

Phi clock divided by four.

Timers 9-9

Timers

Example 9-1 shows how to count events on a pin.

Example 9-1. Counting Events on a Pin

;******************************************************** ;* Example of Counting Events on a pin (with interrupt) *

;* for Timer Module

 

*

 

;* of DSP56824 chip

 

*

 

;********************************************************

 

START

EQU

$0040

; Start of program

BCR

EQU

$FFF9

; Bus Control Register

IPR

EQU

$FFFB

; Interrupt Priority Register

TCR01

EQU

$FFDF

; Timer 0 & 1 Control Register

TCR2

EQU

$FFDA

; Timer 2 Control Register

TCT0

EQU

$FFDD

; Timer 0 Count Register

TPR0

EQU

$FFDE

; Timer 0 Preload Register

;**************

 

 

 

;* Vector setup*

 

 

 

;**************

 

 

 

ORG

P:$0000

 

;Cold Boot

JMP

START

 

;also Hardware RESET vector (Mode 0, 1, 3)

ORG

P:$E000

 

;Warm Boot

JMP

START

 

;Hardware RESET vector (Mode 2)

ORG

P:$0018

 

;

 

JSR

TISR

 

;Timer 0 Overflow vector

ORG

P:START

 

;Start of program

;**************

 

 

 

;* General setup*

 

 

 

;**************

 

 

 

MOVEP

#$0000,X:BCR

;External Program memory has 0 wait states.

 

 

 

;External data memory has 0 wait states.

 

 

 

;Port A pins tri-stated when no external

 

 

 

; access.

BFCLR

#$0200,SR

;Allow IPL (Interrupt Priority Level) 0

 

 

 

; -- Enable maskable interrupts.

;*********************

 

; -- (peripherals, and so on)

 

 

 

;* Timer Module setup*

 

 

 

;*********************

 

 

 

MOVEP

#$0013,X:TCR01

;Configure:

 

 

 

;Timer 0 & 1 disabled.

 

 

 

;Timer 0

 

 

 

; - don’t Invert input: detect rising edges

 

 

 

; - Overflow Interrupt enabled

 

 

 

; - TIO pin configured as input

 

 

 

; - timer clock Event source is TIO pin

MOVEP

#$0000,X:TCR2

;Timer 2 disabled

MOVEP

#234,X:TCT0

;Set Timer 0 Count Register to 234--235 events

MOVEP

#234,X:TPR0

;Set Timer 0 Preload Register to 234.

BFSET

#$0800,X:IPR

;Enable timer module interrupts.

; ...

 

 

 

 

BFSET

#$0080,X:TCR01

;Enable Timer 0

;**************

 

 

 

;* Main routine*

 

 

 

;**************

 

 

 

TEST

 

 

;Test Loop

BRA

TEST

 

; ...

 

 

 

 

TISR

 

 

;Timer Interrupt Service Routine

RTI

 

 

; interrupt code

 

 

 

 

 

 

 

 

 

9-10

DSP56824 User’s Manual

 

Event Counting with the Timer Module

A timer can also be used to decrement to zero and generate an interrupt, as shown in Example 9-2.

Example 9-2. Decrementing to Zero and Generating an Interrupt

;********************* ;* INTERRUPT example * ;* for Timer Module * ;* of DSP56824 chip *

;*********************

 

START

EQU

$0040

; Start of program

BCR

EQU

$FFF9

; Bus Control Register

IPR

EQU

$FFFB

; Interrupt Priority Register

PCR0

EQU

$FFF2

; PLL Control Register 0

PCR1

EQU

$FFF3

; PLL Control Register 1

TCR01

EQU

$FFDF

; Timer 0 & 1 Control Register

TCR2

EQU

$FFDA

; Timer 2 Control Register

TCT0

EQU

$FFDD

; Timer 0 Count Register

TPR0

EQU

$FFDE

; Timer 0 Preload Register

;****************

 

 

;* Vector setup *

 

 

;****************

 

 

ORG

P:$0000

 

; Cold Boot

JMP

START

 

; also Hardware RESET vector (Mode 0, 1, 3)

ORG

P:$E000

 

; Warm Boot

JMP

START

 

; Hardware RESET vector (Mode 2)

ORG

P:$0018

 

;

JSR

TISR

 

; Timer 0 Overflow vector

ORG

P:START

 

; Start of program

;*****************

 

 

;* General setup *

 

 

;*****************

 

 

MOVEP

#$0000,X:BCR

; External Program memory has 0 wait states.

 

 

 

; External data memory has 0 wait states.

 

 

 

; Port A pins tri-stated when no external access

BFCLR

#$0200,SR

; Allow IPL (Interrupt Priority Level) 0

 

 

 

; -- Enable maskable interrupts.

 

 

 

; -- (peripherals, and so on)

;***************************

;* PLL setup

 

*

;* (to increase Phi Clock) *

;***************************

MOVEP

#$0180,X:PCR1

; Configure:

 

 

; (PLLE) PLL disabled (bypassed)

 

 

; -- Oscillator supplies Phi Clock

 

 

; (PLLD) PLL Power Down disabled (PLL active)

 

 

; -- PLL block active for PLL to attain lock

 

 

; (LPST) Low Power Stop disabled

 

 

; (PS[2:0]) Prescaler Clock disabled

 

 

; Select Phi Clock for Clockout pin (CLKO)

MOVEP

#$0260,X:PCR0

; Set Feedback Divider to 1/20

 

 

; ...

 

 

; insert delay here: wait for PLL lock

 

 

; as specified in data sheet

 

 

; ...

BFSET

#$4000,X:PCR1

; Enable PLL for Phi Clock.

 

Timers

9-11

Timers

Example 9-2. Decrementing to Zero and Generating an Interrupt (Continued)

;**********************

 

;* Timer Module setup *

 

;**********************

 

MOVEP

#$001C,X:TCR01

; Configure:

 

 

; Timer 0 & 1 disabled

 

 

; Timer 0

 

 

; -- don’t Invert TIO input: detect rising edges

 

 

; (irrelevant but mentioned for completeness)

 

 

; -- Overflow Interrupt enabled

 

 

; -- Timer Output toggles TIO pin on overflow

 

 

; -- timer clock Event source is Phi Clock /4

MOVEP

#$0000,X:TCR2

; Timer 2 disabled

MOVEP

#99,X:TCT0

; Set Timer 0 Count Register to 99 (100 events).

MOVEP

#99,X:TPR0

; Set Timer 0 Preload Register to 99.

BFSET

#$0800,X:IPR

; Enable Timer Module interrupts.

 

 

; ...

BFSET

#$0080,X:TCR01

; Enable Timer 0

;****************

 

;* Main routine *

 

;****************

; ...

 

 

TEST

 

; Test Loop

BRA

TEST

 

TISR

 

; Timer Interrupt Service Routine

RTI

 

; interrupt code

 

 

 

 

 

9-12

DSP56824 User’s Manual

 

Event Counting with the Timer Module

Example 9-3 shows how to program Timer 0 and Timer 1 to generate a timing signal with a 25 percent duty cycle.

Example 9-3. Timer Using 25% Duty Cycle

;**************************

 

;* 25% duty cycle example *

 

;* for Timer Module*

 

 

 

;* of DSP56824 chip

*

 

 

;**************************

 

START

 

EQU

$0040

; Start of program

 

BCR

 

EQU

$FFF9

; Bus Control Register

 

IPR

 

EQU

$FFFB

; Interrupt Priority Register

 

PCR0

 

EQU

$FFF2

; PLL Control Register 0

 

PCR1

 

EQU

$FFF3

; PLL Control Register 1

 

TCR01

 

EQU

$FFDF

; Timer 0 & 1 Control Register

 

TCR2

 

EQU

$FFDA

; Timer 2 Control Register

 

TCT0

 

EQU

$FFDD

; Timer 0 Count Register

 

TCT1

 

EQU

$FFDB

; Timer 1 Count Register

 

TPR0

 

EQU

$FFDE

; Timer 0 Preload Register

 

TPR1

 

EQU

$FFDC

; Timer 1 Preload Register

 

;****************

 

 

 

;* Vector setup *

 

 

 

;****************

 

 

 

;+-----------------------------------------------------------------------

 

 

 

 

+

;| Note: Bootstrap ROM configures OMR (Operating Mode Register) to set

|

;|

chip operating mode for Mode 2 (Normal Expanded Mode), then

|

;|

jumps to first location of internal program RAM (P:$0000).

|

;+-----------------------------------------------------------------------

ORG

P:$0000

 

; Cold Boot

+

 

 

 

 

JMP

START

 

; also Hardware RESET vector (Mode 0, 1, 3)

 

ORG

P:$E000

 

; Warm Boot

 

 

JMP

START

 

; Hardware RESET vector (Mode 2)

 

 

ORG

P:START

 

; Start of program

 

;*****************

 

 

 

;* General setup *

 

 

 

;*****************

 

 

 

 

MOVEP

#$0000,X:BCR

; External Program memory has 0 wait states.

 

 

 

 

; External data memory has 0 wait states.

 

 

 

 

; Port A pins tri-stated when no external access.

;***************************

 

;* PLL setup

 

 

*

 

;* (to increase Phi Clock) *

 

;***************************

 

 

MOVEP

#$0180,X:PCR1

; Configure:

 

 

 

 

 

; (PLLE) PLL disabled (bypassed)

 

 

 

 

 

; -- Oscillator supplies Phi Clock

 

 

 

 

 

; (PLLD) PLL Power Down disabled (PLL active)

 

 

 

 

; -- PLL block active for PLL to attain lock

 

 

 

 

; (LPST) Low Power Stop disabled

 

 

 

 

 

; (PS[2:0]) Prescaler Clock disabled

 

 

 

 

 

; Select Phi Clock for Clockout pin (CLKO).

 

MOVEP

#$0260,X:PCR0

; Set Feedback Divider to 1/20.

 

 

 

 

 

; ...

 

 

 

 

 

; insert delay here: wait for PLL lock

 

 

 

 

; as specified in data sheet

 

 

 

 

 

; ...

 

 

BFSET

#$4000,X:PCR1

; Enable PLL for Phi Clock.

 

 

Timers

9-13

Соседние файлы в папке DSP568xx