Super Clock
This is a clock with a lot of features.
It can display the time in up to 20 different locations in analogue or digital format (12 or 24 hour). Each location can be configured with its own title, time zone, daylight saving rules and type of display.
You can switch between clocks by tapping on the left or right hand sides of the display to step through the list of configured clocks.
The Super Clock can use three different time sources. An extremely accurate real time clock (RTC) module, a GPS module or an internal RC oscillator (for testing).
The Super Clock was described in the July 2016 issue of Silicon Chip magazine. This web page provides a shorter description so, if you would like the full story, you are encouraged to read the magazine article. Back issues of the magazine can be purchased from Silicon Chip or electronic access can be purchased for about the cost of the printed issue.
Micromite LCD Backpack
This project is based on the Micromite LCD Backpack which is a combination of a low cost colour LCD display and a 32 bit microcontroller programmable in BASIC. In part this project was created to provide an example of what the Micromite is capable of so please feel free to download the BASIC program and extract portions of it for your own projects.
If you have a backpack and just want to play with the program you can do this because the Super Clock will drop into demo mode if it cannot find a real time clock (RTC) or GPS module.
Usage
The Super Clock can display up to 20 different clocks with each configured to display the time in either analogue format with hour, minute and second hands, or in normal 12 hour digital format with AM/PM indicator or in 24 hour digital format (ie, military time). These three modes are illustrated below.
To switch between the various clocks you tap on the left or right hand side of the screen to move backwards or forwards through the list of configured clocks.
To configure the Super Clock you tap on the centre of the screen and when you do this a screen such as the one shown below/right will be displayed. Using the CHANGE button on this screen you can step through the clock types (hidden, analogue, digital 12h and digital 24h) and this setting will apply to the current clock.
The particular screen shown on the right will be displayed if you are using an RTC as the time source. In that case the SET DATE/TIME buttons are displayed and when pressed they will take you to another screen (see below) where you can set the date and time.
If a GPS module is used the firmware will display the state of the GPS time synchronisation in this place. The status will normally be "GPS Time Synchronised" however it may display "No sync for n.nn hrs" which means that the GPS module has not been able to get a signal from sufficient satellites for the past n.nn hours (ie, if it has been two and a quarter hours since an accurate time fix it will display "No sync for 2.25 hrs").
If the GPS signal has been lost the Super Clock will use the crystal controlled oscillator within the GPS module for timekeeping. This is reasonably accurate and the clock will keep using this for up to 24 hours before it will halt and display an error message.
The PREV and NEXT buttons at the bottom of the configuration screen will take you backwards and forwards through through all 20 screens, even if they are set to hidden. This is how you setup a new clock, you step through until you find a hidden clock and then set it to visible (analogue or digital).
The CONFIGURE CLOCK button will take you to a screen where you can change the title, the time zone and the daylight saving rules for the particular clock. An example of this screen is shown on the right.
The daylight saving rules can be configured to suit most countries around the world. The actual switch to/from daylight saving is made at 2AM (non daylight saving time) except for the UK (time zone zero) when the change is made at 1AM.
The following images show some of the detailed configuration screens.
When configuring the daylight saving rules you can specify the month, the day of the week and the position of that day in the month (ie, 1st, 2nd, 3rd or last). This format suits most countries around the world. |
Changing the title of a clock is easy. When you touch a letter that character is appended to the end of the title while DEL will delete the last character. The red triangles will step you through the character set. |
This is the screen used to set the clock if it is using an RTC or running from the Micromite's internal clock. The time being set is the local time for the currently displayed clock. All other clocks will then be automatically updated.. |
Note that all the settings (including the current clock on display) are saved in non volatile flash memory and are automatically reinstated on power up. Because the Super Clock uses a touch sensitive screen for its setup it is easy to drive and after ten minutes you will get the hang of it and have your clocks configured.
Time Source
The Super Clock can use three different time sources; a GPS module, a real time clock (RTC) or the internal Micromite clock.
I recommend using a GPS module because they get the time from the GPS satellites and therefor the time never needs to be set and it is always accurate to within a second. The disadvantage is that sometimes the module cannot get a lock on the satellites, especially indoors where a tin roof, a double story house, rain and other factors can make this difficult. A good test is that if your mobile phone can get a GPS signal then probably a GPS module will also.
The GPS signal can drop in/out but the firmware makes allowance for this by relying on the accurate crystal oscillator within the GPS module in the case of a signal loss. It will do this for up to 24 hours which is a long time and by then the module will have inevitably regained its lock on the satellite signal.
The benefit of using a real time clock (RTC) is that it is not dependent on an external signal and will always work. The recommended RTC uses the DS3231 chip which can keep time to an accuracy of ±5 seconds per month.
Finally, you can use the built in clock within the Micromite chip. This is reset to 1st January 2010 on power up and is not very accurate but it is useful if you have a Micromite with an attached LCD display panel and just want to experiment with the software without connecting an RTC or GPS module.
The Super Clock will first try for a connected RTC module. That only takes a few milliseconds and if that is found it will immediately startup displaying the time. If that is not found the display will show the message "Searching for GPS" and the software will then search for a valid GPS signal on COM1. The search takes about ten seconds and involves scanning the standard baud rates for both the standard (TTL) polarity and the inverted (RS232) signals.
If the GPS module was not found the software will display a dialog box stating that neither the RTC or GPS can be found. When you touch the OK button the clock will then carry on using the internal clock within the Micromite.
GPS Module
The firmware will work with almost any GPS module on the market. This includes either 3.3V or 5V modules and will automatically search for the correct baud rate in the range of 4800 baud to 38,400 baud. It will automatically accommodate modules that use either TTL or RS232 signaling voltages and it uses the RMC message which is standard across all GPS modules. The only modules that will not work with are ones that have a USB interface.
Suitable modules include:
- Fastrax UP501
- USGlobalSat EM-408
- Ublox NEO-7M-C
- Ublox NEO-6M
- Skylab MT3329/SKM53
- V.KEL VK16HX
- Ublox or V.KEL VK2828U7G5LF
I used the V.KEL VK2828U7G5LF (illistrated on the right) and, at the time of writing, it is available for about $20 (incl free freight) from Banggood.com.
As each module is different you will have to invent your own method of mounting it. The simplest would be to fasten it to the inside top of the box (perhaps using glue) and use flying leads to connect it to the Micromite LCD Backpack. The important thing is that the antenna (the square ceramic object on top of the module) must be positioned so that its top surface is horizontal and pointing to the sky. Some modules do not have an antenna and in that case you will have to purchase it separately.
Check the data sheet for your module as some have an enable input which often must be connected to Vcc to take the module out of power saving mode.
Be warned that all GPS modules will take some time (up to an hour) to get their first fix after being powered up for the very first time. See my page on the EM-408 for a more detailed explanation.
Real Time Clock (RTC)
The RTC can be any of the types that the Micromite supports (see the Micromite User Manual) but I recommend modules that uses the DS3231 chip as illustrated on the right.
The DS3231 contains its own temperature compensated oscillator and as a result it is very accurate (±5 seconds per month) - much better than most other RTC chips. Just search eBay for DS3231 and you will get hundreds of hits.
This particular module is designed to use a LIR2032 battery which is a rechargeable Lithium Ion battery and it can be hard to find. You can also use the popular CR2032 non rechargeable battery in its place and it will last 20 or more years however, if you do this, you must disable the charging circuit by removing the diode circled in red. This is important, failure to do this could cause the CR2032 battery to catch fire.
If you are using a DS3231 RTC module the SET TIME button in the configuration screen has an additional feature; if you hold it down for five or more seconds you will be taken to the Aging Offset setting for the DS3231.
This can be used to trim the DS3231's crystal oscillator to achieve an even greater accuracy than normal. By default the aging offset value is set to zero but you can set it to any number from +127 to -127. Typically a change of plus or minus one will change the clock's timing by 0.1 part per million, which is about a quarter of a second over a month. Incrementing the number will slow down the clock and decrementing will speed it up.
Circuit
The Super Clock is really just a Micromite LCD Backpack with a time source (RTC or GPS) and a BASIC program.
The Micromite LCD Backpack consists of a 28-pin microcontroller with a low cost LCD display and less than a dozen other components and can be built in half an hour. If you are not familiar with it you should read this web page for the full description and assembly instructions.
Another component that you need to be familiar with is the standard 28-pin Micromite and this page provides a short description of it. For further information it is worth downloading the Micromite User Manual which covers every aspect of the device.
The RTC or GPS connect directly to the backpack as illustrated below
The DS3231 chip used by the RTC module uses the I2C protocol to deliver the time so it connects to the I2C signal lines on the backpack (pins 17 and 18). The DS3231 chip can run from either 3.3V or 5V but 5V is needed to power the battery charging circuit (if a rechargeable battery is used) so it is shown connected to that supply. Remember to disable the charging circuit (described above) if a non rechargeable battery is used. |
The GPS version can work with modules that require either 3.3V or 5V. Just connect the power lead to the correct supply on the Micromite LCD Backpack. The GPS module uses a serial interface and the 1K resistor and diode are necessary to protect the Micromite in case the GPS module is using RS232 signaling. However, if you are sure that your module uses TTL signal levels (most do), you can dispense with the diode and replace the resistor with a wire link. |
In both cases the main power supply (+5V) to the backpack is shown using a USB connector and this enables you to use one of the many cheap USB chargers that are available. You could also use a regulated 5V plug pack or wall wart but make sure that it does have a regulated output and its voltage will not rise above 5.5V when unloaded.
Construction
To construct the Micromite LCD Backpack you should refer to its web page.
When it comes to putting the completed clock into a box you can use whatever is handy. I built mine in a standard sized UB3 plastic box. Suitable suppliers for this are Altronics (Cat H0203) and Jaycar (Cat HB6013).
I replaced the lid with a transparent plastic sheet sold by Silicon Chip which was laser cut by them to suit the 2.8" version of the Micromite LCD Backpack (they also supply opaque panels). If you do not want to go to this expense you can fabricate your own by cutting the required holes in the standard lid supplied with the box.
New Firmware Version
Version 4 is now available in the download area below. The changes from the first version are:
- Corrected a small bug with the displayed date on an analogue clock when the date changes from the end of one month to the start of the next (the most significant digit of the previous day value was left on the screen).
- Includes a workaround for a bug in MMBasic 5.3 which would cause daylight saving to not work.
- The file SuperClockFull.hex has been upgraded to MMBasic 5.04.08 which contains a number of bug fixes and provides much faster screen updates.
Loading the Firmware
The firmware is contained in the file SuperClockFull.hex (available below). This can be loaded into the Micromite using a PICkit3 programmer (see this web page for a full description).
If you do not have a PIC32 programmer you can purchase a 28-pin PIC32 microcontroller from Silicon Chip magazine pre programmed with the full firmware (ie, SuperClockFull.hex) by following this link. This makes it very easy, all that you need do is just plug the chip into its socket on the PCB.
Silicon Chip also offer a full kit of parts for the Super Clock including the Micromite LCD Backpack, their front panel, RTC or GPS module, the PCB, etc. Follow the above link if you are interested.
The Super Clock hex file includes four components. The Micromite firmware including the BASIC interpreter, the option settings for the LCD display, a set of embedded fonts and the BASIC program for the Super Clock. These components can be loaded individually and the method for doing this is explained in the Micromite User Manual (refer to the chapter titled "Micromite LCD Backpack").
If you wish you can separately download the fonts and BASIC program from below - this is handy if you just want to play with the BASIC program on a Micromite LCD Backpack that you have already built and configured. The font file has to be loaded first then saved to the library before loading the program file. The process is reasonably simple:
- Using AUTOSAVE or XMODEM load the file SuperClockFonts.bas into MMBasic and then save it to the library with the command LIBRARY SAVE.
- Then using AUTOSAVE or XMODEM load the file SuperClock.bas into MMBasic and issue the command RUN.
SuperClockFull.hex This is a combined firmware file that contains the Micromite firmware configured for the LCD panel, the fonts loaded into the library and the BASIC Super Clock program. |
DOWNLOAD |
Super Clock BASIC Program (includes SuperClockFonts.bas and SuperClock.bas) |
DOWNLOAD |