2 event counting – Panasonic MN103001G/F01K User Manual

Page 244

Advertising
background image

8-bit Timers

10-24

10.6.2

Event Counting

When using an 8-bit timer for event counting, make the settings according to the procedure described below.

When using the timers as a 16-, 24- or 32-bit timer by means of a cascaded connection, refer to section
10.6.3, "Cascaded Connection."

Procedure for initiating operation

(1) Set the timer division ratio.

Set the division ratio in TMnBR.
An interrupt request is then generated when the rising edge on the pin input is counted (value set in TMnBR +

1) times.

(2) Select the clock source.

Through TMnCK[2:0] in the TMnMD register, set the clock source to the TMnIO pin input.

(3) Initialize the timer.

Set TMnLDE to "1" in the TMnMD register to initialize timer n. The value set in TMnBR is loaded into
TMnBC as the initial value.

After initialization, be certain to set TMnLDE to "0" to return to normal operation mode.

(4) Set the I/O port.

Set the I/O port to the general-purpose input pin.
For details on the I/O port register settings, refer to chapter 15, "I/O Ports."

(5) Enable the timer counting operation.

Once TMnCNE is set to "1" in the TMnMD register, the counting operation is enabled.

Once the counting operation is enabled, the rising edge on the pin input is counted, and an interrupt request is
generated when there is an underflow in the binary counter. (Refer to Fig. 10-6-4.)

If the value in the TMnBR register is changed while the counting operation is in progress, that value is loaded as the

initial value the next time that an underflow is generated.

■ Procedure for ending operation
(1) Stop the timer counting operation.

Set TMnCNE to "0" in the TMnMD register, stopping the counting operation.

(2) Initialize the timer, if necessary.

If TMnLDE is set to "1" in the TMnMD register, the value that is set in TMnBR is loaded into TMnBC as the

initial value.
If only the timer is stopped and "1" is not written to TMnLDE, the status of the binary counter is maintained as

it was before the counting operation was stopped. If TMnCNE is set to "1", the count resumes from the state
that was in effect immediately before the counting operation was stopped.

Advertising