beautypg.com

Examples of use of clock timer – Epson S1C33210 User Manual

Page 310

background image

III PERIPHERAL BLOCK: CLOCK TIMER

B-III-7-6

EPSON

S1C33210 FUNCTION PART

Examples of Use of Clock Timer

The following shows examples of use of the clock timer and how to control the timer in each case.

To use the clock timer as a timer/counter

Example in which while the CPU is inactive, the clock timer is kept operating in order to start again the CPU
after a specified length of time has elapsed (e.g., three days):

1. Make sure the low-speed (OSC1) oscillation circuit is oscillating stably (SOSC1 = "1").

Wait for approximately three seconds after the oscillation starts for its oscillation to stabilize.

2. Disable the clock timer interrupt using the interrupt controller (ECTM = "0").
3. Stop the clock timer and set "3 days" in the day-comparison register (TCRUN = "0", TCCN = "3").
4. Choose a "day-specified alarm" using the alarm-factor select bit and set "none" in the interrupt-factor

select bit (TCASE = "100", TCISE = "111").

5. Reset the interrupt factor and alarm factor generation flags (FCTM = "0", TCAF = "0").
6. Reenable the clock timer interrupt using the interrupt controller (ECTM = "1").
7. Switch the CPU operating clock to the low-speed (OSC1) clock (CLKCHG = "0").
8. Turn off the high-speed (OSC3) oscillation circuit (SOSC3 = "0").
9. Reset the clock timer (TCRST = "0").
10.Start the clock timer (TCRUN = "1").
11.Execute the halt instruction to stop the CPU.

:

Wait until an interrupt is generated by a day-specified alarm from the clock timer. When an interrupt occurs,
the CPU starts up using the OSC1 clock.

:

12.If necessary, turn on the high-speed (OSC3) oscillation circuit and change the CPU operating clock back to

the OSC3 clock.

In the above example, if the device is reset before a three-day period has elapsed, the device operates as
follows:
• The CPU starts up using the OSC3 clock.
• The clock timer counters are not reset. They remain in the RUN state.
The time during which the CPU has been idle can be checked by reading out the clock timer counters.

For using the clock timer as RTC

Example in which the clock timer is kept operating and an alarm is generated at 10:00 A.M. every day:

1. Disable the clock timer interrupt using the interrupt controller (ECTM = "0").
2. Stop the clock timer (TCRUN = "0").
3. Reset the clock timer (TCRST = "1").
4. Set the current day and time in the minute (TCHD), hour (TCDD), and day (TCND) counters. For the day

counter, set a number of days starting from the reference day (e.g., January 1, 1990). When the count is
read, it is converted into the current date by the software.

5. Set "10:00" in the hour-compare register (TCCD = "0x0A").
6. Select an a "hour-specified alarm" using the alarm factor select bit, and set "none" in the interrupt factor

select bit (TCASE = "010", TCISE = "111").

7. Reset the interrupt factor and alarm-factor generation flags (FCTM = "1", TCAF = "0").
8. Reenable the clock timer interrupt using the interrupt controller (ECTM = "1").
9. Start the clock timer (TCRUN = "1").

:

The clock timer is made to generate an interrupt at 10:00 every day by an hour-specified alarm.

:

In the above example, if any interrupt factor other than an alarm is selected, an interrupt is also generated by
that interrupt factor. To determine which factor caused the interrupt generated, read the interrupt factor
generation flag TCIF and alarm factor generation flag TCAF. If TCAF is set to 1, the interrupt has been
caused by an alarm. If you select an interrupt factor (other than a 1-day factor) along with the hour-specified
alarm, the selected interrupt factor occurs at the same time as the alarm factor.