CHAPTER 4: PERIPHERAL CIRCUITS AND OPERATION (Stopwatch Timer)
4.10 Stopwatch Timer
4.10.7 Control of stopwatch timer
Table 4.10.7.1 lists the stopwatch timer control bits and their addresses.
Table 4.10.7.1 Control bits of stopwatch timer
D3 D2 D1 D0 Name Init*1 1 0
D0H
DKM0 EDIR DKM2
Enable direct input function
Direct key mask factor 0: Non, 1: K02, 2: K02-03, 3: K02-03-10, 4: K10, 5: K10-11, 6: K10-11-12, 7: K10-11-12-13
Enable Disable DKM1
DKM2 EDIR
D1H
SWRST LCURF CRNWF
Lap data carry-up request flag Capture renewal flag Stopwatch timer Run/Stop Stopwatch timer reset MSB
Address Register Comment
*5
EIRUN Interrupt mask register (Stopwatch direct RUN)
Interrupt mask register (Stopwatch direct LAP) Interrupt mask register (Stopwatch 1 Hz) Interrupt mask register (Stopwatch 10 Hz)
FDH
IRUN Interrupt factor flag (Stopwatch direct RUN)
Interrupt factor flag (Stopwatch direct LAP) Interrupt factor flag (Stopwatch 1 Hz) Interrupt factor flag (Stopwatch 10 Hz) *4
*4 *4 *4
*1 Initial value at the time of initial reset *5 Constantly "0" when being read
*2 Not set in the circuit *6 Refer to main manual
*3 Undefined *7 Page switching in I/O memory is not necessary
*4 Reset (0) immediately after being read
SWL0–SWL3: Stopwatch timer data 1/1,000 sec (D2H)
Data (BCD) of the 1/1,000 sec column of the capture buffer can be read out.
The hold function of the capture buffer works by reading this data.
These 4 bits are read-only, and cannot be used for writing operations.
At initial reset, the timer data is set to "0".
SWM0–SWM3: Stopwatch timer data 1/100 sec (D3H)
Data (BCD) of the 1/100 sec column of the capture buffer can be read out. These 4 bits are read-only, and cannot be used for writing operations.
At initial reset, the timer data is set to "0".
SWH0–SWH3: Stopwatch timer data 1/10 sec (D4H)
Data (BCD) of the 1/10 sec column of the capture buffer can be read out. These 4 bits are read-only, and cannot be used for writing operations.
At initial reset, the timer data is set to "0".
Note: Be sure to data reading in the order of SWL→SWM→SWH.
CHAPTER 4: PERIPHERAL CIRCUITS AND OPERATION (Stopwatch Timer)
EDIR: Direct input function enable register (D0H•D3) Set the direct input (RUN/LAP) function to enable or disable.
When "1" is written: Enabled When "0" is written: Disabled
Reading: Valid
The direct input function is set to enable by writing "1" to EDIR, and then RUN/STOP and LAP control can be done by external key input. When "0" is written, the direct input function is invalid, and the stopwatch timer is controlled by the software only.
Further the function switching is actually done by synchronizing with the falling edge of fOSC1/32 (1,024 Hz) after the data is written to this register (after 977 µsec maximum).
At initial reset, this register is set to "0".
DKM2, DKM1, DKM0: Direct key mask factor setting (D0H•D2, D1, D0)
Selects a combination of the key inputs for concurrence judgment with RUN and LAP inputs when the direct input function is set.
Table 4.10.7.2 Key mask selection DKM2
0 0 0 0 1 1 1 1
DKM1 0 0 1 1 0 0 1 1
DKM0 0 1 0 1 0 1 0 1
Mask key combination None (at initial reset) K02
K02, K03 K02, K03, K10 K10
K10, K11 K10, K11, K12 K10, K11, K12, K13
When the concurrence is detected, RUN and LAP inputs cannot be accepted until the concurrence is released.
At initial reset, these registers are set to "0".
SWRST: Stopwatch timer reset (D1H•D0) This bit resets the stopwatch timer.
When "1" is written: Stopwatch timer reset When "0" is written: No operation
Reading: Always "0"
The stopwatch timer is reset when "1" is written to SWRST. When the stopwatch timer is reset in the RUN status, operation restarts immediately. Also, in the STOP status the reset data is maintained.
Since this reset does not affect the capture buffer, the capture buffer data in hold status is not cleared and is maintained.
This bit is write-only, and is always "0" at reading.
SWRUN: Stopwatch timer RUN/STOP (D1H•D1)
This register controls the RUN/STOP of the stopwatch timer, and the operating status can be monitored by reading this register.
• When writing data
When "1" is written: RUN When "0" is written: STOP
The stopwatch timer enters the RUN status when "1" is written to SWRUN, and the STOP status when "0" is written.
In the STOP status, the timer data is maintained until the next RUN status or resets timer. Also, when the STOP status changes to the RUN status, the data that was maintained can be used for resuming the count.
RUN/STOP control with this register is valid only when the direct input function is set to disable. When the direct input function is set, it becomes invalid.
CHAPTER 4: PERIPHERAL CIRCUITS AND OPERATION (Stopwatch Timer)
• When reading data
When "1" is read: RUN When "0" is read: STOP
Reading is always valid regardless of the direct input function setting. "1" is read when the stopwatch timer is in the RUN status, and "0" is read in the STOP status.
At initial reset, this register is set to "0".
LCURF: Lap data carry-up request flag (D1H•D3)
This flag indicates a carry that has been generated to 1 sec-digit when the data is held.
When "1" is read: Carry is required When "0" is read: Carry is not required
Writing: Invalid
If the capture buffer shifts into hold status while the 1 Hz interrupt factor flag ISW1 is set to "1", LCURF is set to "1" to indicate that a carry-up to 1-sec digit is required. When performing a processing such as a LAP input preceding with 1 Hz interrupt processing, read this flag before processing and check whether carry-up is needed or not.
This flag is renewed (set/reset) every time the capture buffer shifts into hold status.
At initial reset, this flag is set to "0".
CRNWF: Capture renewal flag (D1H•D2)
This flag indicates that the content of the capture buffer has been renewed.
When "1" is read: Renewed When "0" is read: Not renewed
Writing: Invalid
The content of the capture buffer is renewed if the LAP key is input when the data held into the capture buffer has not yet been read. Reading SWH in that status sets this flag to "1", and the hold status is main-tained. Consequently, when data that is held by a LAP input is read, read this flag after reading the SWH and check whether the data has been renewed or not.
This flag is renewed when SWH is read.
At initial reset, this flag is set to "0".
EIRUN, EILAP, EISW1, EISW0: Interrupt mask registers (F5H)
These registers are used to select whether to mask the stopwatch timer interrupt.
When "1" is written: Enabled When "0" is written: Masked
Reading: Valid
The interrupt mask registers EIRUN, EILAP, EISW1 and EISW0 are used to separately select whether to mask the direct RUN, direct LAP, 1 Hz and 10 Hz interrupts.
At initial reset, these registers are both set to "0".
IRUN, ILAP, ISW1, ISW0: Interrupt factor flags (FDH) These flags indicate the status of the stopwatch timer interrupt.
When "1" is read: Interrupt has occurred When "0" is read: Interrupt has not occurred
Writing: Invalid
The interrupt factor flags IRUN, ILAP, ISW0 and ISW1 correspond to the direct RUN, direct LAP, 1 Hz and 10 Hz interrupts respectively. With these flags, the software can judge whether a stopwatch timer interrupt has occurred. However, regardless of the interrupt mask register setting, these flags are set to "1" when the timing condition is established.
These flags are reset when read out by the software.
Reading of interrupt factor flags is available at EI, but be careful in the following cases.
If the interrupt mask register value corresponding to the interrupt factor flags to be read is set to "1", an interrupt request will be generated by the interrupt factor flags set timing, or an interrupt request will not be generated.
At initial reset, these flags are set to "0".
CHAPTER 4: PERIPHERAL CIRCUITS AND OPERATION (Stopwatch Timer)
4.10.8 Programming notes
(1) The interrupt factor flag should be reset after resetting the stopwatch timer.
(2) Be sure to data reading in the order of SWL→SWM→SWH.
(3) When data that is held by a LAP input is read, read the capture buffer renewal flag CRNWF after reading the SWH and check whether the data has been renewed or not.
(4) When performing a processing such as a LAP input preceding with 1 Hz interrupt processing, read the LAP data carry-up request flag LCURF before processing and check whether carry-up is needed or not.
(5) When the interrupt factor flag ISW1 is set to "1", if reading it (reading FDH) before the capture buffer shifts into hold status, the LAP data carry-up request flag is not set to "1". Pay attention to the interrupt processing.
(6) Reading of interrupt factor flags is available at EI, but be careful in the following cases.
If the interrupt mask register value corresponding to the interrupt factor flags to be read is set to "1", an interrupt request will be generated by the interrupt factor flags set timing, or an interrupt request will not be generated.
Fig. 4.10.8.1 Flow chart of stopwatch timer interrupt processing Stopwatch
interrupt routine
Read capture:
SWL, SWM, SWH
CRNWF = 1?
Read interrupt factor flag:
IRUN, ILAP, ISW1, ISW0
ILAP = 1?
Acquire for lap data
LCURF = 1?
Carry up 1 sec for lap data
IRUN = 1?
Control for RUN/STOP
ISW1 = 1?
Carry up 1 sec for stopwatch data
ISW0 = 1?
10 Hz interrupt (application) RETURN