EM6605 EM Microelectronic, EM6605 Datasheet - Page 17

no-image

EM6605

Manufacturer Part Number
EM6605
Description
4 bit Microcontroller
Manufacturer
EM Microelectronic
Datasheet
EM6605
8. Timer/Event Counter
The EM6605 has a built-in 8 bit auto-reload Timer/Event counter that takes an input from either the
prescaler or Port PA3. If the Timer/Event counter counts down to $00 the interrupt request flag INTTE is
set to 1. If the Timer/Event counter interrupt is enabled by setting the mask flag MTimC set to 1, then an
interrupt request is generated to the CPU. See also section 9. If used as an event counter, pulses from the
PA3 terminal are input to the event counter. See figure 10 and tables 29 and 30 on the next page for PA3
source selection (debounced or not, Rising/Falling edge). By default rising and debounced PA3 input is
selected.
The timer control register TimCtr selects the auto-reload function and input clock source. At initial RESET
this bit is cleared to 0 selecting no auto-reload. To enable auto-reload TimAuto must be set to 1. The
timer/counter can be enabled or disabled by writing to the TIMen control bit in the BEEP register. At initial
RESET it is cleared to 0. When used as timer, it is initialised according to the data written into the timer
load/status registers LTimLS (low 4 bits) and HTimLS (high four bits). The timer starts to count down as
soon as the LTimLS value is written. When loading the timer/event counter registers the correct order
must be respected: First, write either the control register TimCtr or the high data nibble HTimLS. The last
register written should be the low data nibble LTimLS. During count down, the timer can always be
reloaded with a new value, but the high four bits will only be accepted during the write of the low four bits.
In the case of the auto-reload function, the timer is initialised with the value of the load registers LTimLS
and HTimLS. Counting with the auto-reload function is only enabled during the write to the low four bits,
(writing TEauto to 1 does not start the timer counting down with the last value in the timer load registers
but it waits until a new LTimLS load). The timer counting to $00 generates a timer interrupt event and
reloads the registers before starting to count down again. To stop the timer at any time, a write of $00 can
be made to the timer load registers, this sets the TimAuto flag to 0. If the timer is stopped by writing the
TimEn bit to 0, the timer status can be read. The current timer status can be always obtained by reading
the timer registers LTimLS and HTimLS. For proper operation read ordering should be respected such
that the first read should be of the LTimLS register followed by the HTimLS register. Example: To have
continuos 1sec timer IRQ with 128Hz one has to write 128dec (80hex) in Timer registers with auto-reload.
Using the timer/counter as the event counter allows several possibilities:
1.) Firstly, load the number of PA3 input edges expected into the load registers and then generate an
interrupt request when counter reaches $00.
2.) The second is to write timer/counter to $FF, then select the event counter mode, and lastly enable the
event counter by setting the TIMen bit to 1, which starts the count.
Because the counter counts down, a binary complement has to be done in order to get the number of
events at the PA3 input.
3) Another option is to use the timer/counter in conjunction with the prescaler interrupt, such that it is
possible to count the number of the events during two consecutive ck[6], ck[4], ck[1], (32Hz, 8Hz or 1Hz
*f1) prescaler interrupts.
Figure 10.Timer / Event Counter
© EM Microelectonic-Marin SA, 02/99, Rev. B/243
17

Related parts for EM6605