manufacturer of I/O-rich SBCs, operator interfaces, handheld instruments, and development tools for embedded control low cost single board computers, embedded controllers, and operator interfaces for scientific instruments & industrial control development tools for embedded control order our low cost I/O-rich embedded control products embedded controller manufacturer profile single board computers & embedded controllers development tools & starter kits for your embedded design operator interfaces with touchscreens and graphical user interface plug-in expansion modules for digital & analog I/O C language & Forth language integrated development tools, IDE single board and embedded computer accessories embedded controller enclosures, bezels, environmental gaskets

QScreen C User Guide

Table of Contents

PART 1 GETTING STARTED

Introduction. How to Use This Manual

Chapter 1: Getting to Know Your QScreen Controller

PART 2 PROGRAMMING THE QSCREEN CONTROLLER

Chapter 2: Your First Program

Chapter 3: The IDE: Writing, Compiling, Downloading and Debugging Programs

Chapter 4: Making Effective Use of Memory

Chapter 5: Real Time Programming

Chapter 6: Failure and Run-Time Error Recovery

PART 3 COMMUNICATIONS, MEASUREMENT, AND CONTROL

Chapter 7: Digital and Timer-Controlled I/O

Chapter 8: Data Acquisition Using Analog to Digital Conversion

Chapter 9: Serial Communications

Chapter 10: The Battery-Backed Real-Time Clock

Setting and Reading the Real Time Clock

PART 4: PUTTING IT ALL TOGETHER

Chapter 11: A Turnkeyed Application

PART 5: REFERENCE DATA

Appendix A: QScreen Electrical Specifications

Appendix B: Connector Pinouts

Appendix C: QScreen Schematics

Chapter 10

<< Previous | Next>>

The Battery-Backed Real-Time Clock

A battery-backed Real-Time Clock (RTC) is optionally available for the QScreen Controller and is included with the QScreen Starter Kit.  You may, 

Use the RTC to keep track of events in rea, i.e., calendar and clock, time;

Use it to battery-back a 128K RAM on your QScreen (but not a 512K RAM);

 Use built-in software drivers to read or set the RTC anytimel.

A Real-Time Clock is included with the QScreen Starter Kit.  The accuracy of the clock is better than +/- 2 minutes per month.  A 7 ma-hr Lithium rechargable battery is used for the clock.  This backup battery charges automatically while +5V is applied to the QScreen. 

The QScreen that comes with the Starter Kit has 512K of RAM which can not be battery-back with the battery used by the real-time clock.  For smaller RAM sizes like 128K, the battery can be used to battery-back the RAM.

The length of time the battery lasts varies from board to board primarily because RAM chips (if the smaller 128K is installed) vary device-to-device in their leakage currents.  Their leakage currents also depend strongly on ambient temperature so that while a battery may last a long time at normal or low ambient temperatures, at greater temperature it may discharge more quickly.

We have measured battery discharge times for typical 128K devices and have found the following:

  Actual measurements at normal temperatures (<40°C) show the battery should backup the memory more than two years between recharging.  Our actual measurements of the RAM current draw show it to draw much less than its “typical” spec from its datasheet.

  Assuming the “typical” current specifications of the RAM data sheets the battery should last 139 days; and,

  At the worst case current specification for the RAM, battery life would be 44 days at normal temperatures, and as little as 6 days if operated continuously at an ambient temperature of 70°C.

  If the RAM is not battery backed, but the RTC installed, typical RTC retention time at 25°C should be 300 days.

Figure 10‑1 illustrates the dependence of battery lifetime between charges while backing up the 128K RAM and powering the RTC, and ambient temperature.

Figure 10‑1  Battery discharge time as a function of ambient temperature.

After each cold restart the kernel re-initializes the RTC chip to charge the battery and to use battery backup on removal of power.  The maximum battery recharge time is 22 hours.

Setting and Reading the Real Time Clock

The built-in library functions SetWatch() and ReadWatch() make it easy to set and read the real time clock.  The SetWatch() and ReadWatch() functions use the top 16 bytes of the 68HC11F1’s on-chip RAM as a buffer to hold intermediate results during the data transfers, and the top 8 bytes at addresses 0xB3F8-0xB3FF serve as the watch_results structure that contains the results returned by the most recent call to ReadWatch() as described below.

Because the structure that is written to by ReadWatch() is at a fixed location, this code is not re-entrant.  This is not a problem in single-task applications or applications where only one task uses the watch.  But it can cause problems if multiple tasks are executing ReadWatch().  For example, assume that task #1 calls ReadWatch(), but before it can access the contents of the structure using the assignment statement, the timeslice interrupt occurs and task#2 proceeds to call ReadWatch(), then the contents of the structure could be changed before task#1 is able to execute its assignment statement.  To avoid this situation, the multitasking application can be configured so that only one task calls ReadWatch() and SetWatch() and shares the data with other tasks. 

Another option is to define a resource variable to mediate access to the watch.  The routines needed to accomplish this are declared in the MTASKER.H file and described in detail in the Control-C Glossary. The following brief example illustrates how to design a re-entrant function that returns the current WATCH_MINUTE:

 

RESOURCE watch_resource;     // declare resource variable: controls

                             // watch access

  _Q int CurrentMinute(void) // reads watch, returns current minute

   {  int minute;

      GET(watch_resource);   // get access to watch; Pause() if

                             // another task has it

      ReadWatch();           // updates contents of watch structure

      minute = WATCH_MINUTE;

                             // you can also transfer other contents

                             // from the watch structure to

                             // "task-private" variables here

      RELEASE(watch_resource); // release access to watch so other

                             // tasks can use it

      return minute;

   }

The CurrentMinute() function can be simultaneously called from multiple tasks without causing any conflicts.  The GET() and RELEASE() macros automatically mediate access to the watch, ensuring that only one task has access at a time.

All of the input and output parameters of SET.WATCH and READ.WATCH are passed on the Forth data stack.  Because they are re-entrant they can be simultaneously called from multiple tasks in a single QED-Forth application without producing any conflicts.

The battery-backed clock is pre-set at the factory to Pacific Time in the United States.  To re-set the smart watch to your time zone, your program can call the function:

 

void SetWatch(hundredth_seconds,seconds,minute,hour,day,date,month,year)

The interactively callable routine named SetTheWatch() is defined in the TIMEKEEP.C file so you can set the watch from your terminal.  As explained in the Control-C Glossary, the hour parameter ranges from 0 to 23, the day from 1 to 7 (Monday=1 in this example), and the year parameter ranges from 00 to 99.  For example, if it is now 10 seconds past 5:24 PM on Wednesday, May 26, 2004, you could interactively set the watch by typing:

SetTheWatch( 0, 10, 24, 17, 3, 26, 5, 4)

The watch is set and read using 24-hour time, where midnight is hour 0, noon is hour 12, and 11 PM is hour 23.  Note that you may assign any day of the week as “day number 1”.

The function ReadWatch() writes the current time and date information into a structure named watch_results that occupies the top 8 bytes of on-chip RAM at addresses 0xB3F8-0xB3FF. Pre-coded macros name the structure elements so it is easy to access the time and date information.  For example, the following simple function in the TIMEKEEP.C file reads the smart watch and prints the time and date:

 

_Q void SayDate(void)

{   ReadWatch();     // results are placed in watch_results structure

printf(“\nIt is now %d:%d:%d on %d/%d/%d.\n”,

WATCH_HOUR, WATCH_MINUTE, WATCH_SECONDS,

WATCH_MONTH, WATCH_DATE, WATCH_YEAR);

}            

It simply calls ReadWatch(), and then executes a printf() statement using the pre-coded structure macros to reference the time parameters in the watch_results structure.  If you called this function immediately after setting the watch as described in the prior section, the response at your terminal might be:

It is now 17:24:31 on 5/26/04.

After compiling TIMEKEEP.C, you can interactively type at your terminal:

SayDate( )

at any time to see a display of the current time and date.

For backwards compatibility with the QED product line, the hundredths of a second field is present but it is not used.  The hundredths of a second value is required for SET.WATCH SetWatch() but it is ignored and it is always 0 from READ.WATCH ReadWatch().

<< Previous | Next>>


Home|Site Map|Products|Manuals|Resources|Order|About Us
Copyright (c) 2006 Mosaic Industries, Inc.
Your source for single board computers, embedded controllers, and operator interfaces for instruments and automation