Interfacing Real Time Clock With PIC32 For Real Time Systems

DOI : 10.17577/IJERTV2IS60243

Download Full-Text PDF Cite this Publication

Text Only Version

Interfacing Real Time Clock With PIC32 For Real Time Systems

Umesh Goyal1, Kavita2, Dr. Neelam Rup Prakasp

M.E. Student1, 2, Supervisor & Head3, Electronics & Electrical Communications Department, PEC University of Technology, India

Abstract

This paper describes the design for Real Time Clock with PIC32MX795F512L microcontroller. This paper also describes how to interface PIC32MX675F512L with RTC to get real time clock time and calendar. Real time clock is used to provide real time in hours, minutes and seconds, calendar: Weekday, Date, Month and Year. There are many other features of RTC that have been described in this paper. The hardware design presented here can be used with any microcontroller having integrated I2C module. This paper also describes the functionality of RTC in flow chart form. After reading this paper, one can implement both hardware and software of RTC.

Keywords RTC, RTCC, PIC, I2C

  1. Introduction

    The Real Time Clock is used in almost every real time system where we need to know the real time, date and many other factors. This real time is used in many applications, used to provide accurate time delays wherever needed, used in control systems where time is the factor to control the system.

    PIC32MX795F512L microcontroller has an inbuilt RTCC module. This PIC32MX795F512L microcontroller is a 32 bit microcontroller. This RTCC module provides real-time clock and calendar functions. It is intended for those applications where we need to maintain accurate time for long periods of time with minimum or no interventions from the CPU. There are a number of key features of this RTCC module. These features are as follows:

    • RTCC module Provides calendar showing Weekday, Date, Month and Year

    • In this one can configure Alarm for half second, 1 second, 10 seconds, 1 minute, 10 minutes, 1 hour, 1 day, 1 week, 1 month, 1 year

    • Alarm can be repeated using decrementing counter

    • Indefinite repeat chime Alarm

    • Year Range can vary from 2000 to 2099

    • Leap year correction is possible

    • BCD formatting is done for smaller firmware overhead

    • Time is shown in Hours, Minutes and Seconds

    • 24-hour format is possible

    • Visibility of one-half second period is possible

    • Fractional second synchronization can be done

    • It is Optimized for long term battery operation

    • User can calibrate clock crystal frequency with auto-adjust feature

    • Calibration Range is ±0.66 seconds error per month

    • It can Calibrate up to 260 ppm of error(crystal)

    • External 32.768 kHz Clock Crystal is required for its operation [1].

  2. Structure of the system

    Fig. 1 shows the block diagram of RTCC Module present in PIC32MX795F512L microcontroller. This block diagram shows the different blocks present in the module that includes RTCC prescaler used for scaling purposes, RTCC timer, Comparator, Interrupt Logic circuitry etc.

    Fig. 1 Block Diagram of RTCC Module

  3. Design of RTC Interface With PIC32MX795F512L

    PIC32MX795F512L microcontroller is used for interfacing with RTC. It is a 32 bit microcontroller that

    has inbuilt RTCC module. Here an external RTC 1208 is used for real time clock and calendar purposes. The circuit is designed using ORCAD schematic capture. The circuit designed is shown in fig. 3(a). In this figure supply section is shown with the microcontroller and some other necessary circuitry that is essential to power up this controller. The external crystal oscillator used with this microcontroller is 12 MHz

    The RTC that is interfaced with this microcontroller is attached using I2C bus. I2C stands for Inter-Integrated Circuit. I2C is a synchronous protocol that allows a master device to initiate communication with a slave device. I2C is a two wire (DATA (SDA) and Clock (SCL)) communication protocol and Clock is generated by the master to control the data transfer but slow slaves may hold the clock pins low to prevent the data transfer. I2C works by having a pull-up resistor on

    the line and only devices pull the line low during communication.

    Fig. 2 bit transfer on I2C bus

    The data on the SDA line must be stable during the HIGH period of the SCL line. The state of the data line can only change when SCL line is LOW.

    Fig. 3(a) ORCAD design of the system

    Fig. 3(b) shows the ORCAD design of Real Time Clock IC ISL 1208. The external crystal oscillator used with this IC is 32.768 KHz. The capacitors used with oscillator are of 33pf. SDA and SCL are two wire of

    I2C bus that is connected with the SDA and SCL lines of microcontroller

    Fig. 3(b) ORCAD design of the system

  4. Theory of Operation

    The ISL1208 device is a low power real time clock. It has many features like timing and crystal compensation, clock/calendar, power fail indicator, periodic alarm, battery backup switching and battery-backed user SRAM [2]. The oscillator uses an external, low-cost 32.768 kHz crystal for its operation. Real time clock tracks time with separate registers for seconds, minutes, and hours and tracks date with calendar registers for date, day of the week, month and year. The calendar is accurate from the year 2000 to 2099, with automatic leap year correction.

    Fig. 4 Block Diagram of ISL 1208

    1. Power Control Operation

      The power control circuit accepts a VDD and a VBAT input to power up the device. Different types of batteries can be used with Intersil RTC products as VBAT input. For example, 3.0V or 3.6V Lithium batteries are appropriate, and battery sizes are available that can power the ISL1208 for up to 10 years. Another option is to use a Super Cap for those applications where, the VDD is interrupted up to a month.

      1. Normal Mode to Battery Back-up Mode:

        To change from Mode to Mode the following two conditions should be met:

        Condition 1: < – , where is around 50 mV.

        Condition 2: <, where is around 2.2 V.

      2. Battery Back-up Mode to Normal Mode:

      To change from Mode to Mode the following two conditions should be met:

      Condition > +, where is around 50 mV.

      Condition 2: > + , where is around 30mV.

    2. Low Power Mode

      The normal power switching of the ISL1208 is so designed to switch into the battery backup mode only if the VDD power is lost. This will ensure that the device can take a wide range of backup voltages from many types of sources while constantly switching into backup mode. Another mode, named Low Power Mode, is available that allows direct switching from VDD to VBAT without making VDD to drop below VTRIP. Since the further monitoring of VDD vs VTRIP is no longer needed, that circuitry is shut down and a smaller amount of power is used while operating in VDD. Power savings are typically 600nA at VDD which is equal to 5V [3]. Low Power Mode is activated via the LPMODE bit is in the control and status registers.

    3. RTC operation

      An external 32.768 kHz quartz crystal is used by the Real Time Clock (RTC) so as to maintain an accurate internal representation of second, minute, hour, day of week, date, month, and year. The RTC has leap- year correction also. The clock corrects for months having fewer than 31 days. It also has a bit that controls 24-hour or AM/PM format. When the ISL1208 powers up after the loss of both the VDD and the VBAT, the clock will not start incrementing until one byte is witten to the clock register [4].

    4. Accuracy of the real time clock

      The accuracy of the RTC mainly depends on the frequency of the external quartz crystal which is used with the RTC. Since the resonant frequency of the crystal depends on temperature, the performance of RTC will also depend upon the temperature. The frequency deviation of the crystal is a function of the turnover

      temperature of the crystal from the crystals nominal frequency. For example, a ~40ppm frequency deviation translates into an accuracy of ~2 minute per month. The manufacturer of crystal provides these parameters. The ISL1208 provides on-chip crystal compensation networks to adjust load capacitance to tune oscillator frequency from -94ppm to +140ppm [5].

      Flowchart to start RTC

      If I2C2CONbi ts.RSEN=1?

      ok

      RTC

      error

      Call Start RTC function

      Flowchart to stop RTC

      Generate Start Condition by setting I2C2CONbits.SEN=1

      Call Start RTC function

      Insert RTC Time Out to check whether RTC is faulty or not

      Generate Start Condition by setting I2C2CONbits.PEN=1

      If I2C2CONbi ts.SEN=1?

      Insert RTC Time Out to check whether RTC is faulty or not

      RTC

      error

      ok

      If I2C2CONbi ts.PEN=1?

      Flowchart to Restart RTC

      Call Start RTC function

      ok

      REFERENCES

      RTC

      error

      Generate Start Condition by setting I2C2CONbits.RSEN=1

      Insert RTC Time Out to check whether RTC is faulty or not

      1. Alexander Hanzlik, Astrit Ademaj, A Composable Algorithm for Clock Synchronization in Multi-Cluster Real-Time Systems , IEEE.

      2. Ying-Wen Bai, Hsiao-Chung Chen, AN ADJUSTABLE DESIGN FOR THE REAL TIME CLOCK OF HIGH-END SERVER SYSTEMS, IEEE.

      3. Songyan Xu, Ratnesh Kumar, Real-Time Control of Dense- Time Systems Using Digital-Clocks, IEEE Transactions On Automatic Control, Vol. 55, No. 9, September 2010.

      4. Hsiao-Chung Chen, Ying-Wen Bai, An Adjustable Design with Component Tolerance for the Real Time Clock of High- End Server Systems, IEEE.

      5. W. Klische, G. Kramer Hardware aspects of a Real-time Software Clock, IEEE.

Umesh Goyal, is currently pursuing Masters in Engineering in

Electronics Engineering from PEC University of Technology, Chandigarh, India. He has completed his Bachelors of Technology in Electronics and Communication Engineering.

The major field of his work is related to Electronic Embedded Systems with PIC 32- bit microcontrollers, Digital Electronics, Signal Processing.

Kavita Saharan, is currently pursuing Masters in Engineering in

Electronics Engineering from PEC University of Technology, Chandigarh, India. She has done her Bachelors of Engineering in Electronics and Communication Engineering.

Her areas of interest include Embedded Systems, Networks, Signal and Systems and Digital Electronics.

Dr. Neelam Rup Prakash, did her B.E. (E & Ec) in 1987 from Punjab

Engineering College, Chandigarh. She has rich working experience of 25 years both with industry and academia. Her areas of interest include Communication, Digital Design and Computer Aided diagnostics. Presently, She is working as Head department of Electronics and Electrical Communication, PEC University of Technology, Chandigarh.

Leave a Reply