uC-Clk User Manual

Introduction

The management of time is important in many microprocessor-based embedded systems. For instance, what would VCRs (Video Cassette Recorders) and DVRs (Digital Video Recorders) be without clock/calendars to schedule the recording of television programs?

A clock/calendar is a useful module for an embedded system. If you need a clock/calendar, you have to decide whether to implement it in hardware or software.

Clock/calendar chips are readily available and most can directly interface with microprocessors. These chips accurately maintain the time-of-day, and some chips even provide a built-in calendar. Some chips include a battery and can continue to keep track of date and time even when power is removed from the unit. Clock/calendar chips generally require a crystal, which further increases the recurring cost of your system. Clock/calendar chips are manufactured by a large number of semiconductor companies such as Freescale, National Semiconductor, Maxim, Dallas Semiconductor, etc. Just because you have a clock/calendar chip doesn’t mean you don’t need to write any software.

Your application software will still need to:

  • program the clock/calendar chip with the correct date and time,
  • program any alarm clock functions, and
  • read the current date and time.

A software-maintained clock/calendar is the best solution when your application cannot afford the extra cost associated with a clock/calendar chip, a battery, and an extra crystal. A software-implemented clock/calendar module can offer most of the benefits of a hardware approach (except that it can’t maintain date and time when power is removed).

Maintaining a clock/calendar is a trivial task for a microprocessor. The first thing you will need is a periodic time source that will interrupt the microprocessor at regular intervals. Such a time source is easy to find. AC power line frequencies (50 or 60 Hz) are generally very accurate over long periods of time. For short-term accuracy, the crystal used to clock the microprocessor is also a good candidate; however, for such an application, the crystal frequency must be divided down. If your application software runs under a real-time multitasking operating system, the OS’s clock tick is a convenient periodic time source, as long as the tick rate is an integer fraction of one second (for example 60 Hz and not 18.2 Hz as found on PCs).

A software approach requires very little ROM, RAM, and CPU time and does not add recurring cost to your system. Also, you can easily add features, such as alarm clock functions (with many alarm setpoints), timestamps, string-formatting utilities to convert date and time to ASCII, etc. Software-implemented clock/calendars are found in a number of familiar appliances such as VCRs, DVRs, stereos, FAX machines, microwave ovens, etc. If the microprocessor has a low-power standby mode, the software-implemented clock/calendars can be made to maintain correct date and time when the power is removed by also including a battery to power the microprocessor.