2 event counting – Panasonic MN103001G/F01K User Manual

Page 290

Advertising
background image

16-bit Timers

11-36

11.7.2

Event Counting

When using timer 11, 12, or 13 as an event counter, make the settings according to the procedure described below.

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 is counted (value set in TMnBR + 1) times in

the pin input.

(2) Select the clock source.

Select the clock source through TMnCK[2:0] in the TMnMD register to "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 "input pin."

For details on the I/O port register settings, refer to chapter 15, "I/O Ports."

(5) Enable the timer counting operation.

The counting operation is enabled when the TMnCNE in the TMnMD register is set to "1".

Once the counting operation is enabled, the counter counts rising edges on the pin input. When an underflow

occurs in the binary counter, an interrupt is generated and the value set in TMnBR is loaded into TMnBC. (Refer
to Fig. 11-7-4.)

If the value in the TMnBR register is changed while the counting operation is in progress, this changed 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 TMnLDE is not set to "1" after the timer is stopped, the binary counter is maintained as it was before the

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

timer was stopped.

Advertising