Software Real Time Clock Implementation on MC9S08LG32



Similar documents
IRTC Compensation and 1 Hz Clock Generation

Connecting Low-Cost External Electrodes to MED-EKG

How To Control A Motor Control On An Hvac Platform

Windows 7: Using USB TAP on a Classic CodeWarrior Installation (MGT V9.2 DSC V8.3)

Flexible Active Shutter Control Interface using the MC1323x

etpu Host Interface by:

Using WinUSB in a Visual Studio Project with Freescale USB device controller

Connecting to an SMTP Server Using the Freescale NanoSSL Client

Blood Pressure Monitor Using Flexis QE128 Gabriel Sanchez RTAC Americas

How To Build A Project On An Eclipse Powerbook For Anarc (Powerbook) On An Ipa (Powerpoint) On A Microcontroller (Powerboard) On Microcontrollers (Powerstation) On Your Microcontroller 2 (Powerclock

Local Interconnect Network (LIN) Physical Interface

Freescale Embedded GUI Converter Utility 2.0 Quick User Guide

Cyclic Redundant Checker Calculation on Power Architecture Technology and Comparison of Big-Endian Versus Little-Endian

How to Convert 3-Axis Directions and Swap X-Y Axis of Accelerometer Data within Android Driver by: Gang Chen Field Applications Engineer

MC13783 Buck and Boost Inductor Sizing

USB HID bootloader for the MC9S08JM60

Hardware Configurations for the i.mx Family USB Modules

Installation of the MMA955xL CodeWarrior Service Pack Author: Fengyi Li Application Engineer

Using the Performance Monitor Unit on the e200z760n3 Power Architecture Core

Initializing the TSEC Controller

Freescale Semiconductor. Integrated Silicon Pressure Sensor. On-Chip Signal Conditioned, Temperature Compensated and Calibrated MPX4080D.

Programming Audio Applications in the i.mx21 MC9328MX21

Understanding LCD Memory and Bus Bandwidth Requirements ColdFire, LCD, and Crossbar Switch

Handling Freescale Pressure Sensors

Using eflexpwm Module for ADC Synchronization in MC56F82xx and MC56F84xx Family of Digital Signal Controllers

Performance Monitor on PowerQUICC II Pro Processors

Emulated EEPROM Implementation in Dual Flash Architecture on MC9S08LG32 With Demo Description

Freescale Variable Key Security Protocol Transmitter User s Guide by: Ioseph Martínez and Christian Michel Applications Engineering - RTAC Americas

How To Measure Power Of A Permanent Magnet Synchronous Motor

Generate Makefiles from Command Line Support in Eclipse-Based CodeWarrior Software

Point-of-Sale (POS) Users Guide Lech José Olmedo Guerrero Jaime Herrerro Gallardo RTAC Americas

Improving Embedded Software Test Effectiveness in Automotive Applications

PowerQUICC II Pro (MPC83xx) PCI Agent Initialization

Using the Kinetis Security and Flash Protection Features

MCF54418 NAND Flash Controller

Configuring the FlexTimer for Position and Speed Measurement with an Encoder

User Interface Design using CGI Programming and Boa Web Server on M5249C3 Board

Ref Parameters Symbol Conditions Min Typ Max Units. Standby μa. 3 Range kpa. 4 Resolution 0.15 kpa. 5 Accuracy -20ºC to 85ºC ±1 kpa

Freescale Semiconductor. Integrated Silicon Pressure Sensor. On-Chip Signal Conditioned, Temperature Compensated and Calibrated MPX5500.

Detecting a CPM Overload on the PowerQUICC II

Using XGATE to Implement LIN Communication on HCS12X Daniel Malik 8/16-Bit Products Division East Kilbride, Scotland

Comparison of MC9S08QE128 and MCF51QE128 Microcontrollers Scott Pape and Eduardo Montanez Systems Engineering, Freescale Microcontroller Division

NOT RECOMMENDED FOR NEW DESIGN

DRM for Driver Information System on S12G128. Reference Design

3-Phase BLDC Motor Control with Hall Sensors Using 56800/E Digital Signal Controllers

MLPPP in the Evolving Radio Access Network

Data Movement Between Big-Endian and Little-Endian Devices

Robust Over-the-Air Firmware Updates Using Program Flash Memory Swap on Kinetis Microcontrollers

NOT RECOMMENDED FOR NEW DESIGN

Processor Expert Software Microcontrollers Driver Suite Getting Started Guide

VGA Output using TV-Out Extension Solution i.mx21

How To Fit A 2Mm Exposed Pad To A Dfn Package

Avoiding Read While Write Errors When Developing In-Software Flash Programming Applications for Kinetis and ColdFire+ MCUs

Techniques and Tools for Software Analysis

MPC8245/MPC8241 Memory Clock Design Guidelines: Part 1

VLE 16-bit and 32-bit Instruction Length Decode Algorithm

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

Implementing Positioning Algorithms Using Accelerometers

Adding SDIO Wi-Fi Solution to i.mx Windows CE 5.0/Windows CE 6.0

Understanding Pressure and Pressure Measurement

RF Power Field Effect Transistors N- Channel Enhancement- Mode Lateral MOSFETs

MSC8156 and MSC8157 PCI Express Performance

KIT34845EPEVME Evaluation Board

User Guide. Introduction. HCS12PLLCALUG/D Rev. 0, 12/2002. HCS12 PLL Component Calculator

How to Do EEPROM Emulation Using Double Flash Array on MC9S08LC60 Ronald Gonzalez and Tatiana Orofino RTAC Americas

Real Time Development of MC Applications using the PC Master Software Visualization Tool. 1. Introduction. 2. Development of Motor Control.

i.mx28 Ethernet Performance on Linux

3-Phase BLDC Motor Control with Hall Sensors Using the MC56F8013

NOT RECOMMENDED FOR NEW DESIGN

Enhanced Serial Interface Mapping

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

Using the High Input Voltage Charger for Single Cell Li-Ion Batteries (KIT34671EPEVBE)

PQ-MDS-T1 Module. HW Getting Started Guide. Contents. About This Document. Required Reading. Definitions, Acronyms, and Abbreviations

Pressure Freescale Semiconductor

ColdFire Security SEC and Hardware Encryption Acceleration Overview

Using the HC08 SCI Module

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

Using Program Memory As Data Memory. 1. Introduction Program Memory and Data. Contents. Memory. Freescale Semiconductor Application Note

White Paper. Freescale s Embedded Hypervisor for QorIQ P4 Series Communications Platform

Freescale Semiconductor. Integrated Silicon Pressure Sensor

Freescale Semiconductor, I

MPXAZ6115A MPXHZ6115A SERIES. Freescale Semiconductor Technical Data. MPXAZ6115A Rev 4, 01/2007

Efficient Low-Level Software Development for the i.mx Platform

BLDC Motor Control with Hall Effect Sensors Using the 9S08MP

Genesi Pegasos II Setup

Motion and Freefall Detection Using the MMA8451, 2, 3Q

How To Improve Performance On A P4080 Processor

Developing an Application for the i.mx Devices on the Linux Platform

1 Introduction. Freescale Semiconductor Application Note. Document Number: AN3031 Rev. 1, 04/2010

AND8365/D. 125 kbps with AMIS-4168x APPLICATION NOTE

Installing Service Pack Updater Archive for CodeWarrior Tools (Windows and Linux) Quick Start

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

Figure 1. CodeWarrior IDE with Processor Expert Workspace

APPLICATION. si32library. Callback CMSIS HARDWARE. Figure 1. Firmware Layer Block Diagram

ZigBee-2.4-DK 2.4 GHZ ZIGBEE DEVELOPMENT KIT USER S GUIDE. 1. Kit Contents. Figure GHz ZigBee Development Kit

LC898300XA. Functions Automatic adjustment to the individual resonance frequency Automatic brake function Initial drive frequency adjustment function

Transcription:

Freescale Semiconductor Document Number: AN4478 Rev. 0, 03/2012 Software Real Time Clock Implementation on MC9S08LG32 by: Nitin Gupta Automotive and Industrial Solutions Group 1 Introduction The MC9S08LG32 is a member of the Freescale HCS08 family MCUs. It uses the S08 core and integrates many peripherals, such as LCD, SPI, I 2 C, SCI, ADC, and Real Time Counters. This application note describes how to initialize and maintain the Real Time Clock (RTC) in the MC9S08LG32 microcontroller family. MC9S08LG32 Demo Board used for RTC setup is shown in Figure 1. The system communicates with the MC9S08LG32 target via a USB Background Debug Mode (BDM) interface. With BDM protocol, system can update the MC9S08LG32 firmware. RTC is implemented using the Real Time Counter IP (S08RTCV1) on MC9S08LG32. RTC can be displayed on the LCD connected on the board. In this application note, the MC9S08LG32 RTC driver interfaces are explained. Various applications for MC9S08LG32 can make use of this driver. The following sections will describe the details and the steps for creating an application using it. This application note does not cover how to configure the LCD. For details, please see AN3823 on http:// www.freescale.com. Contents 1 Introduction...1 2 Real Time Clock (RTC)...2 3 RTC driver framework...2 3.1 RTC.c...3 3.2 RTC.h...5 3.3 RTC_main.c...6 4 Integration of RTC driver...7 5 Test results...7 6 Conclusion...8 7 References...8 2012 Freescale Semiconductor, Inc.

Real Time Clock (RTC) Figure 1. MC9S08LG32 demo board setup 2 Real Time Clock (RTC) The RTC, or, sometimes referred to as time of the day, can be implemented using either a hardware or a software module. The primary function of an RTC implementation is to provide the information of time, day, week, month, and year. A hardware RTC implementation refers to one that uses an external RTC hardware module that may be connected through I 2 C or SPI bus. On the other hand, some hardware RTC implementations are provided by an on-chip peripheral in the MCU. The advantage of hardware RTC is accuracy of time. Although not sought after for their accuracy, software RTCs can be a viable solution for some applications. Software RTC can be implemented with a timer or a counter that generates an interrupt based on a specified time interval. The number of time intervals are counted and then converted to time. A one second time interval is a convenient configuration for the software RTC. Since the software RTC function is not a part of the hardware, legacy systems can implement software RTC functionality with a firmware update. If the RTC is implemented in software, it will have lower system cost, requires fewer external components, and requires less power. For MC9S08LG32, software RTC is implemented using Real Time Counter (S08RTCV1), configured to use the external oscillator of 32.768 khz. S08RTCV1 accurately keeps the track of time in low-power mode, which is a critical parameter in automotive applications to prevent high battery discharge rates and conserve the battery charge between vehicle starts (recharge cycles). Vehicle manufacturers expect that a vehicle should start even if the battery is not charged for long period (say 6-8 weeks), and still keep a very good accuracy on the daily digital clock. The MC9S08LG32 family of microcontrollers provides a range of features to enable users to achieve this goal. 3 RTC driver framework The RTC driver is provided as C code files. 2 Freescale Semiconductor, Inc.

RTC driver framework The driver consists of three files, namely: RTC.c RTC.h RTC_main.c MC9S08LG32 RTC driver project is illustrated in Figure 2 Figure 2. MC9S08LG32 RTC driver The details of each of the files are given in the following subsections. 3.1 RTC.c RTC.c consists of application programming interfaces (APIs) which enable the software RTC on the MC9S08LG32 series. The description of each API is as follows: 3.1.1 RTC_Init This API initializes the RTC and the system clock. It uses a 32.768 khz external crystal oscillator, having 30 ppm tolerance. During the initialization of the clock, the operating modes have been taken into consideration. As per the application, the operating mode can be either of the following: Normal mode: In this mode, the RTC interrupt will occur every 1 second. Stop3 mode: In this mode, the RTC interrupt will occur after every 8 seconds. Freescale Semiconductor, Inc. 3

RTC driver framework void RTC_Init(void) 3.1.2 IRQ_Init This API initializes the IRQ pin, which is connected to the ignition. It is assumed that a proper signal conditioning is present on the pin. void IRQ_Init(void) : 3.1.3 RTC_ISR This interrupt service routine (ISR) is called each time the RTC interrupt occurs. In this, clock-time is updated as per the mode and interrupt flag is cleared. There can be two possibilities: Normal mode: In this mode, the time interval of the interrupt is 1 second (frequency ~ 1 Hz). Stop3 mode: In this low-power Stop3 mode, the RTC interrupt acts as a wakeup source for the MCU and the time interval of the interrupt is increased to 8 seconds (frequency ~ 0.125 Hz). This, in-turn will reduce the overall current consumption, as the execution of the ISR will take 2-10 µs, depending on the number of instructions which need to be executed in this ISR. NOTE The time interval given above is as per the present RTC driver. void interrupt VectorNumber_Vrtc RTC_ISR(void) 3.1.4 IRQ_ISR This ISR is called each time a falling edge is detected at the IRQ/Ignition pin. It is assumed that the falling edge will be generated, each time ignition is ON/OFF, which is done through a signal conditioning on the Ignition pin. 4 Freescale Semiconductor, Inc.

RTC driver framework void interrupt VectorNumber_Vrtc IRQ_ISR(void) 3.1.5 UpdateAndDisplayTime This API should be called each time there is an interrupt from the RTC or from the IRQ to update the clock structures to the latest values. void UpdateAndDisplayTime(void) 3.1.6 ClockCorrection This API should be called, each time there is a correction required. This API should be changed as per the crystal characteristics. For example, when the crystal characteristics are such that the clock is gaining 1 second every 8 hours under the ambient temperature conditions, this API should be called when the hours are equal to 8, 16, and 24, but only once and consequently, 1 should be subtracted from the seconds variable in order to provide a correct and accurate clock. void ClockCorrection(void) 3.2 RTC.h This header file contains the clock structure and the function prototypes. This file also contains the macros, which are used to initialize the clock structures, which are described in detail below: Freescale Semiconductor, Inc. 5

RTC driver framework 3.2.1 RTC_HOURS This macro is used to initialize the hours value in the clock structure and can be changed as per the requirement of the application. 3.2.2 RTC_MINUTES This macro is used to initialize the minutes value in the clock structure and can be changed as per the requirement of the application. 3.2.3 RTC_SECONDS This macro is used to initialize the seconds value in the clock structure and can be changed as per the requirement of the application. 3.2.4 RTCMOD_NORMAL_VALUE This macro is used in Normal mode to load the RTCMOD register. 3.2.5 RTCMOD_LP_VALUE This macro is used in Stop3 mode to load the RTCMOD register. 3.3 RTC_main.c This file contains the main function, which acts as an application for the present RTC driver. This can be removed, when the driver is integrated into the application. 3.3.1 System_Init This API initializes the overall system. It disables the watchdog and enables the Stop3 mode only when the ignition is stopped and is captured through the IRQ, and Low Voltage Detect (LVD) reset is disabled. void System_Init(void) 6 Freescale Semiconductor, Inc.

3.3.2 Main This API is the entry point. Integration of RTC driver void main(void) 4 Integration of RTC driver In order to integrate the RTC driver in the existing code, add the following files: RTC.c RTC.h From the main of the existing application, call RTC_Init() and IRQ_Init(). The present RTC driver presumes the external crystal oscillator used is 32.768 khz and configures the prescaler value to 2 10 (1024), thus, making the RTC clock to 32 Hz (32.768 khz/ 1024). If an application uses a crystal with a different frequency, then the prescaler needs to be reconfigured and the RTC driver needs to be recalibrated. See ClockCorrection for more details. The application should always wait for the oscillator clock to stabilize and then initialize other drivers. In the main loop, the application should always check the MCU operating mode, so that when the MCU wakes up due to ignition, the application should correct the clock, by loading the correct value in milliseconds. 5 Test results RTC soaking results under various temperature conditions, with and without corrections are displayed in Table 1. All the readings are noted, after the temperature was stabilized. The results may show lot of variation in time due to PCB characteristics, crystal characteristics and the components used on the board. Table 1. RTC driver test results under various temperature conditions S. No. Results without correction Results with 1 second correction / 8 hours Temperature Ambient Ambient 1 Number of hours 185 h 185 h Time gain 24 s 1 s Temperature 40.1 C 40.1 C 2 Number of hours 65 h 65 h Time gain 10 s 2 s Table continues on the next page... Freescale Semiconductor, Inc. 7

Conclusion Table 1. RTC driver test results under various temperature conditions (continued) S. No. Results without correction Results with 1 second correction / 8 hours Temperature 60.9 C 60.9 C 3 Number of hours 70 h 70 h Time gain 12 s 3 s Temperature 80.5 C 80.5 C 4 Number of hours 24 h 24 h Time gain 8 s 5 s 6 Conclusion The RTC driver can be added into the application, by easily adding 2 files (described in Integration of RTC driver), but care must be taken to calibrate the driver as per the crystal characteristics in order to get accurate clock in the vehicle. The application can also add compensation algorithm based on the temperature characteristics of the crystal for better accuracy of the clock with temperature. The accuracy of the software RTC is affected by the frequency tolerance of the microcontroller clock source. If the clock source is an external crystal (for instance), a high ppm frequency tolerance would be preferred. 7 References 1. MC9S08LG32RM available at http://www.freescale.com 2. DEMO9S08LG32 Schematic available at http://www.freescale.com 8 Freescale Semiconductor, Inc.

How to Reach Us: Home Page: www.freescale.com Web Support: http://www.freescale.com/support USA/Europe or Locations Not Listed: Freescale Semiconductor Technical Information Center, EL516 2100 East Elliot Road Tempe, Arizona 85284 +1-800-521-6274 or +1-480-768-2130 www.freescale.com/support Europe, Middle East, and Africa: Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen, Germany +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (German) +33 1 69 35 48 48 (French) www.freescale.com/support Japan: Freescale Semiconductor Japan Ltd. Headquarters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Japan 0120 191014 or +81 3 5437 9125 support.japan@freescale.com Asia/Pacific: Freescale Semiconductor China Ltd. Exchange Building 23F No. 118 Jianguo Road Chaoyang District Beijing 100022 China +86 10 5879 8000 support.asia@freescale.com Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductors products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any liability, including without limitation consequential or incidental damages. "Typical" parameters that may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including "Typicals", must be validated for each customer application by customer's technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claims alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. RoHS-compliant and/or Pb-free versions of Freescale products have the functionality and electrical characteristics as their non-rohs-complaint and/or non-pb-free counterparts. For further information, see http://www.freescale.com or contact your Freescale sales representative. For information on Freescale's Environmental Products program, go to http://www.freescale.com/epp. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. 2012 Freescale Semiconductor, Inc. Document Number: AN4478 Rev. 0, 03/2012