Skip to content

Real Time Clock

Ivan Cenov edited this page Feb 14, 2019 · 2 revisions

Real Time Clock.

The Real Time Clock is an application specific device (hardware and/or software). So it must be implemented in the application. It has to have defined a procedure that is called at RTC_TICK intervals. This procedure is usually an interrupt responding procedure for the Real Time Clock. This procedure makes the timers 'tick' by calling their Tick macros. Each tick makes timer's counter to increment by one (however forward/backward variable timers may count with different steps).

Intervals that are measured by the timers are multiples of RTC_TICK. The accuracy of the intervals is 1/2 RTC_TICK. It is convenient to define several time units and this is usually done in the application header file. The example header.h contains such definition, assuming that RTC_TICK is 10ms:

#define RTC_TICK    (100u)          // 100 x 0.1ms = 10ms

// time units in rtc ticks
#define MU_001S (100u/RTC_TICK)     // 0.01 sec
#define MU_01S  (1000u/RTC_TICK)    // 0.1 sec
#define MU_1S   (10000u/RTC_TICK)   // 1 sec
#define MU_10S  (100000uL/RTC_TICK) // 10 sec
#define MU_1MIN (600000uL/RTC_TICK) // 1 min

Then setting an interval of 500ms may looks looks like (50u*MU_001S) or (5u*MU_01S) and for even easier life the time intervals may be defined:

#define T_RUN_TIME  (5u*MU_01S)     // 500ms
#define T_IDLE_TIME (20u*MU_01S)    // 2sec