Cornell University ECE4760
Realtime clock and Calender (RTCC)

Realtime Clock

The realtime clock and calender (RTCC) maintains time-of-day and date based on an external 32768 Hz crystal or oscillator. Note that most solderless prtotype boards have too much capacitance for an external crystal, which requires around 12 pf of load capacitance ( part number 535-9034-ND). Typically, each side of the crystal would have a 12 pf capacitor to ground and would be connected to SOSCI and SOSCO (pins 11 and 12 on the 28 pin PIDP). Alternatively an external oscillator can be connected to SOSCI, for instance digikey part number DS32KHZS#T&RCT-ND. The crystal circuit is shown below but is very sensitive to stray capacitance. You will probably have to tune the frequency using different capacitors, and the one second pulse as discussed below.

Setting up the RTCC is easy, but remember that the time and date registers store data in BCD format! The lowest 4 bits store the first decimal digit, the next 4 bits the second decimal digit, so that decimal 10 is stored as 0x10 and decimal 18 is stored as 0x18. See the reference manual chapter for details on time/date format and setting the time. For testing, the following code initializes the clock and produces a 1 Hz square wave at pin 7 to check crystal accuracy. Always do this.

// init the clock
RtccSetTimeDate(0x0, 0x0); // for testing accuracy
RtccSelectPulseOutput(1); // select the seconds clock pulse as the function of the RTCC output pin
RtccOutputEnable(1); // enable the Output pin of the RTCC (PIN 7 on 28 pin PDIP)

An example code starts the clock and sets it in main, then reads it in the command thread. As usual, you will also need protothreads to run this.

Copyright Cornell University December 3, 2015