Real Time Clocks – A Different (Unusual) Approach.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Real Time Clocks – A Different (Unusual) Approach.

Post by JohnCrow »

There are many different versions of Real Time Clocks (RTC), both on the Matrix Forums and on the Internet generally.
This project approaches the topic in a slightly more unusual way.

Firstly, let me say the actual idea for this project is not mine.
It comes from the projects section of the Elektor magazine Website.

http://www.elektor.com

This is an area for the magazines subscribers to post projects, and it has not actually been published in the magazine itself.

Project 42 – What-Remains-Of-The-Day-Clock. Analog-Meets-Digital.

The credit for this article goes to Jὄrg Trautmann.

The basic idea uses a normal LCD to show the time, but it also uses a moving coil meter, calibrated 0 to 100 to show how much remains of the day as a percentage.
The moving coil meter is driven by PWM
The original project uses an Atmel ATMega8 device, programmed using AVR Studio.

My first thoughts were, that would be easy to setup using the meter component on my 4D Visi Display, rather than a physical moving coil meter, and do the software in Flowcode.

For more information on the Visi Display components, see my previous tutorial post or refer to the manufacturers website.
http://www.4dsystems.com.au

2.0 Hardware & Software:

The following hardware will be required

EB002 Screw Terminal Boards
EB006 Matrix Programmer (Fitted with 16F877A)
Generic Power Supply to Suit
Generic 4 x 20 LCD Display
Generic 3231 RTC Board (Setup with current date and time)
32PTU 4D Systems Visi Display Board (Mounted n Development Board)
Visi Programming Lead

Port B LCD Board – Used for initial development.
Port C Both the RTC and the Visi Board connect to Port C

C3 – RTC SCL -Clock
C4 – RTC SDA - Data

C6 – Visi RX0 (Pin 24 On Development Board)
C7 – Visi TX0 (Pin 26 On Development Board)

The project can only be programmed in Flowcode6 and later.
The 3231 RTC component will need to be downloaded from the Matrix TSL forums and installed in the Flowcode Components folder.

Also, early releases of FC6 do not have full support for the Visi Component.

3.0 Design Brief:

Before using the Visi display, I decided to test the ideas behind the flowchart using a simple 4 x 20 LCD display.
This allows all the data to be easily displayed at once and thus aids debugging.

The time calculation is taken care of using a DS3231 RTC device with battery backup.

The project also uses the multi-form feature of the Visi Display.

Form 0

Form 0 shows

Percent Remaining on a Analogue Meter
Percent Remaining as a 2 Digit LED Display (Shown as an integer)
Time as a 3 x 2 Digit LED Display
Temperature as a 2 Digit LED Display

Temperature can be realised by reading a register in the DS3231.
This will not be as accurate as using a dedicated sensor such as a LM35 or a thermocouple, but is perfectly acceptable for an application like this and does not add cost or tie up extra ports and memory on the microcontroller.

Form 1

Form 1 shows

Time as a 3 x 2 Digit LED Display
Date as a 3 x 2 Digit LED Display
Percent Remaining as a 2 Digit LED Display (Shown as an integer)

Forms are swopped by means of a “Touch Button” at the bottom of the display.

3.1 Calculations

To perform the percentage of day remaining calculation, it will be necessary to convert the time completely to seconds.
This is done as follows.

There are:
86400 seconds in 1 day
3600 seconds in 1 hour
60 seconds in 1 minute

The program uses Jordy’s DS3231 component, which can display the time as either a string or as separate Hour , Minute , Second variables.
It is the latter of these which are used for the calculations.

The first line on the LCD will display time using the string option, and then the used, left and percent variables are displayed.
These are just simply to verify the calculations are working correctly and can be calculated manually to check them.
Seconds Used = ((Hours * 3600) + (Minutes * 60) + Second)
Seconds Left = 86400 – Seconds Used
Percent Of Day = ((Seconds Used / 86400) * 100)

Example.
Current time is:

08:31:09
This works out as

Seconds Used =( (8*3600) + (31*60) + 9)
Seconds Used = 28800 + 1860 + 9
Seconds Used = 30669

Seconds Left = 86400 – 30669
Seconds Left = 55731

Percentage Left =( (Seconds_Left / Total Seconds In Day) * 100)
Percentage Left = ((55731/ 86400) * 100)
Percentage Left = 64.5%

The Visi display needs to be configured using 4D Workshop – Visi Genie, prior to being connected to the EB006.

The display source code is attached below along with the Flowcode file.
Form 0.jpg
Form 0.jpg (49.04 KiB) Viewed 7419 times
Form 1.jpg
Form 1.jpg (51.18 KiB) Viewed 7419 times
DS3231_RTC.jpg
DS3231_RTC.jpg (93.25 KiB) Viewed 7413 times
TimeRemaining_Dual_Display_Temperature.zip
(4.75 KiB) Downloaded 734 times
1 in 10 people understand binary, the other one doesn't !

wayne millard
Posts: 234
Joined: Thu May 31, 2007 2:18 pm
Has thanked: 7 times
Been thanked: 12 times
Contact:

Re: Real Time Clocks – A Different (Unusual) Approach.

Post by wayne millard »

Hi John,

Nice project keep up the good work

Wayne :D

Post Reply