3-2 setup example – Panasonic MN101C77C User Manual

Page 231

Advertising
background image

VI - 17

Chapter 6 8-bit Timers

8-bit Timer Count

6-3-2

Setup Example

„

Timer Operation Setup Example (Timers 0, 1, 4 and 5)

Timer function can be set by using timer 0 that generates the constant interrupt. By selecting fs/4 (at fosc

= 20 MHz) as a clock source, interrupt is generated every 250 clock cycles (100 µs).

An example setup procedure, with a description of each step is shown below.

(1)

Set the TM0EN flag of the timer 0 mode

register (TM0MD) to "0" to stop the counting of

timer 0.

(2)

Set the TM0PWM flag and TM0MOD flag of

the TM0MD register to "0" to select the normal

timer operation.

(3)

Select the prescaler output to the clock source

by the TM0CK2-0 flag of the TM0MD register.

(4)

Select fs/4 to the prescaler output by the

TM0PSC1-0, TM0BAS flag of the timer 0

prescaler selection register (CK0MD).

Also, set the PSCEN flag of the prescaler

control register (PSCMD) to "1" to enable the

counting of the prescaler.

(5)

Set the value of the interrupt generation cycle

to the timer 0 compare register (TM0OC). The

cycle is 250, so that the setting value is set to

249 (x'F9').

At that time, the timer 0 binary counter

(TM0BC) is initialized to x'00'.

(6)

Set the interrupt level by the TM0LV1-0 flag of

the timer 0 interrupt control register (TM0ICR).

If the interrupt request flag may be already set,

clear the request flag.

[ Chapter 3 3-1-4. Interrupt flag setting ]

Setup Procedure

(1)

Stop the counter.

TM0MD (x'3F54')

bp3

:TM0EN

= 0

(2)

Select the normal timer operation.

TM0MD (x'3F54')

bp4

:TM0PWM = 0

bp5

:TM0MOD

= 0

(3)

Select the count clock source.

TM0MD (x'3F54')

bp2-0

:TM0CK2-0 = 001

(4)

Select the prescaler output and

enable the counting.

CK0MD (x'3F56')

bp2-1

:TM0PSC1-0 = 01

bp0

:TM0BAS

= 1

PSCMD (x'3F6F')

bp0

:PSCEN

= 1

(5)

Set the cycle of the interrupt

generation.

TM0OC (x'3F52') = x'F9'

(6)

Set the interrupt level.

TM0ICR (x'3FE9')

bp7-6

:TM0LV1-0 = 10

Description

Advertising
This manual is related to the following products: