OLED real time clock (Group Input)

mrburnette

Senior Member
While messing around in the 18M2 serial driver code for the OLED AXE133Y display, it seemed that with all that blank program space, that I really should do something to up the consumption ratio! I was thinking about Adrian Hudson's OLED brightness question at the time so I had "clock" on my mind.

I started my prototyping on an 08M2 connected to the AXE133Y and will port the code over to the 18M2 when my new display arrives tomorrow. In the mean time, I started a short blog detailing the working prototype code here: http://www.picaxeforum.co.uk/entry.php?38-IR-time-set-OLED-digital-clock-w-08M2-and-old-wall-clock-quartz-module

As digital clocks are often tackled by beginners, I thought I would try and document the process in enough detail that someone could follow the logic and reproduce the results. As I often do, I will probably post the completed project in my Instructables corner.

As I am pre-port of the 08M2 code to the 18M2 code, I thought it might be nice to ask forum members what they would like to have (want) in a dedicated OLED clock. Then, experienced forum members can suggest an approach to satisfy the need. If you already know how to implement a feature, simply post that feature with the code snippet. Keep things simple... the idea is to have a final project that a novice can replicate.


Some ideas for evolution:
(1) I already have the 08M2 code for a digital thermometer along with the EEPROM table values for using a 10K resistor/10K thermistor as the active temperature sensor: http://www.instructables.com/id/PICAXE-Pitcher-Perfect-Thermometer/ The entire 1st line of the OLED display is "free" for use...

(2) Alarm

(3) Improvements on the GetIR to eliminate repeat digits without using a delay

(4) A solution for the OLED brightness issue surfaced by Adrian

(5) Alternate 1-second sources to drive the PICAXE PINC.3
a. 50/60Hz sources (electrically isolated)
b. National timebases such as WWBV / MSF / etc.



(6).... your ideas and code snippets and alternative (read this: more efficient) replacement code for my current skeleton code. To those who take offense with the "goto" statement, please note the RevEd AXE133Y official post. If you want to rewrite it with DO/LOOP, go for it... I'll try your implementation

Thanks for your ideas. Let's build something fun and useful and reasonably simple.

-Ray
 

westaust55

Moderator
Some extra ideas/features:
Add a World Time zone mode where you can step through all of the time zones around the world while retaining the home/base time.
Add a Daylight Saving mode to cater for those countries and states where DLS is embraced
Add an LED as a "torch"
Add a snooze mode with on/off for the alarm function
 

westaust55

Moderator
Some extra ideas/features:
Add a World Time zone mode where you can step through all of the time zones around the world while retaining the home/base time.
Add a Daylight Saving mode to cater for those countries and states where DLS is embraced
Add an LED as a "torch"
Add a snooze mode with on/off for the alarm function
 

hippy

Ex-Staff (retired)
Things I would say are a priority for any clock beyond the most basic -

* Automatic adjustments for Daylight Saving Time.

* Independent alarm times for weekdays and both days of the weekend.

* Simple 'jump to nearest hour' time setting so you can easily correct the clock's time with a single button push.

* Ability to use just a watch crystal ( no DS1307 ) for accurate time-keeping if not worried about battery backup. I can't recall the consumption of the OLED when nothing is displayed but I think it's very low so it could be possible to have it battery backed up even without a DS1307.

I've always thought it would be handy for a clock to show the time the power failed rather than simply flashing "00:00".

A means ( PIR input ? ) for the alarm / snooze function to deactivate itself when you forget to cancel it would be useful, though perhaps just me; two alarms and I'm fed up of having to go back upstairs to cancel the 'backup safety' having forgotten.
 

KeithRB

Senior Member
Here is a good way to get a 1 pps pulse:
http://www.sparkfun.com/products/540

Use a 32 KHz watch crsytal and a 16 bit counter. start the counter at 0x8000 and it will overflow in one second. Reset the counter and start again. While you might be able to use Pulsein commands, an external counter will free up the PicAxe.
 

mrburnette

Senior Member
Things I would say are a priority for any clock beyond the most basic -

* Automatic adjustments for Daylight Saving Time.
* Independent alarm times for weekdays and both days of the weekend.
* Simple 'jump to nearest hour' time setting so you can easily correct the clock's time with a single button push.
* Ability to use just a watch crystal ( no DS1307 ) for accurate time-keeping if not worried about battery backup.

I can't recall the consumption of the OLED when nothing is displayed but I think it's very low so it could be possible to have it battery backed up even without a DS1307.

I've always thought it would be handy for a clock to show the time the power failed rather than simply flashing "00:00".

A means ( PIR input ? ) for the alarm / snooze function to deactivate itself when you forget to cancel it would be useful, though perhaps just me; two alarms and I'm fed up of having to go back upstairs to cancel the 'backup safety' having forgotten.
I'm a little confused with the bold suggestions:
- The existing prototype on my blog page shows the use of an IR remote to accurately set the PICAXE time variables... after the 6th input for decimal seconds, the clock restarts with the correct time (+/- about 1 second.) I could provide a single push-button for a time hack to force the seconds to "00" and increment the minutes by 1 and so that a shortwave receiver or more accurate timepiece could sync the clock.

- I am using a "watch crystal" and at present, I'm getting about +1 second over 48 hours in a non-temperature controlled basement. I had not planned on detailing the construction of a power supply beyond simply specifying +5V from a source, so battery backup is a distinct possibility by only adding a battery pack and a single diode to switch over. The question, assuming a battery back-up is do we wish to blank the OLED and flash a LED to indicate power-failure? I would only need 1 of the 3 available pins of the 18M2 to implement this concept.

- For the power-failure time display, is the DOW necessary, too? Like L1: "Power Fail Tue @" and L2: XX:XX:XX with the bold being variable: Mon, Tue, Wed, Thu, Fri, Sat, Sun. DOW is pretty easy for IR setting by assigning 1 to Sun, 2 to Mon... and 7 to Sat for the week.

- Ray
 

mrburnette

Senior Member
Here is a good way to get a 1 pps pulse:
http://www.sparkfun.com/products/540

Use a 32 KHz watch crsytal and a 16 bit counter. start the counter at 0x8000 and it will overflow in one second. Reset the counter and start again. While you might be able to use Pulsein commands, an external counter will free up the PicAxe.
Hippy posted several forum articles about using external crystals with PICAXE for accurate clocking. However, remember that I am porting from an 08M2 to the 18M2 used in the OLED serial interface. While your idea is very interesting, I have not seen anything on the forum about connecting a watch crystal to the 18M2 and the internal recognition of a quasi-timebase variable which could be software interrogated. If we decide to leave the SERIN command in the codebase so that the display can be used for other than a dedicated clock, then SERIN is a blocking command and an internal interrupt could not be used to increment seconds.

I'm thinking that I want to extend the OLED instructions so that an attached serial device(s) could simply command the OLED to flip into time/date display mode if there was no data to report via the serial interface. By removing the SERIN command, the AXE133Y is forever isolated and will just be a clock. It's a design decision I have not made and I wish comments on this aspect.
 

hippy

Ex-Staff (retired)
@ mrburnette : I only glanced at the blog so was just throwing ideas out. I think it's important to decide if it's an AXE133Y as only a clock or a clock and display as that will affect things.

The 'jump to nearest hour' function is something I've considered useful so you can 'listen to the pips' on the radio which mark exact time ( may be just a UK thing ), watch a radio controlled clock, or just assume the X o'clock news has started at X o'clock, then just hit a button on the one being set. IE, master clock hits "21:00", press the button, whether the clock is slow or fast, '20:31' to '21:29', it will immediately jump to '21:00' and be synchronised again. No having to fast-forward seconds for ages, miss the mark, and go round again, taking so long you then have to adjust the minutes.
 

mrburnette

Senior Member
Some extra ideas/features:
Add a World Time zone mode where you can step through all of the time zones around the world while retaining the home/base time.
Add a Daylight Saving mode to cater for those countries and states where DLS is embraced
Add an LED as a "torch"
Add a snooze mode with on/off for the alarm function
Should the World Time Zones include (or just "GMT+ ?? number); that is, city: http://www.timeanddate.com/worldclock/???
It would require an external EEPROM to hold all the city names listed in the web reference, but I can look into the user programming 24 cities names of their choice of zones if the EEPROM space is available after my temperature routines. More likely if storage is cramped, a sequential span of EEPROM can be used in a manner such as this:
EEPROM xxx, (home_GMT_offset, "Home_City", GMToffset, "London", GMT_offset, ... ) as far as storage will allow. Using this convention, each button short-push would move forward by +1 GMT from the home_GMT so I do not need to deal with negative movement; that is, if UTC-5 and 'Atlanta' the short push would move to UTC-4 and Aruba. A long-push could be used to quickly return to the home zone time/city name which would have a fixed EEPROM starting address. I can find each of the user-input UTC values & cities by looking at the ASCII byte value of the EEPROM byte to determine if it is a letter or a number.... City names would be encapsulated between numeric, so I can parse that out... and end the whole sequence with %11111111 to force a wrap-around to home_zone.

"Add a LED torch"... you planning on carrying this to the theatre and need the torch mode to read the programme? According to some, the OLEDs by themselves are bright enough to be considered a torch...

-Ray

View attachment 9810
 

mrburnette

Senior Member
@ mrburnette : I only glanced at the blog so was just throwing ideas out. I think it's important to decide if it's an AXE133Y as only a clock or a clock and display as that will affect things.

The 'jump to nearest hour' function is something I've considered useful so you can 'listen to the pips' on the radio which mark exact time ( may be just a UK thing ), watch a radio controlled clock, or just assume the X o'clock news has started at X o'clock, then just hit a button on the one being set. IE, master clock hits "21:00", press the button, whether the clock is slow or fast, '20:31' to '21:29', it will immediately jump to '21:00' and be synchronised again. No having to fast-forward seconds for ages, miss the mark, and go round again, taking so long you then have to adjust the minutes.
1) Agreed... I'm on the fence with his at the moment and the biggest obstacle is that the original AXE133Y code uses SERIN which will block. Isolating the OLED from other input, however, would be a shame.
2) It is not a UK only thing... we call it 'hacking the second-hand' here... probably a Ham radio overtone or something... unsure of the origin

- Ray
 
Okay, I am going to have to do a little embarrassed owning up here :)

Many years ago, when I was about 15 I made a digital clock (when digital clocks were still considered a pretty neat idea) I made a clock using a Mostec MK50250 clock chip and a circuit board from a company called SINTEL which went on to become the UK company Research Machines (now RM Computers). I didn't (and still don't have) any education in electronics - analogue electronics are a complete mystery to me - I can just about manage digital circuits like these we mess with here with the odd decoupling capacitor.

Anyway, I loved my clock and it ran for 37 years without fail until I switched it off recently and when I switched it back on - poof :-(

I spent a looong time trying to fix it and nearly did except the alarm would not work - I think the alarm pin on the IC had failed. During my search for info on the chip I happened on the PICAXE line of devices. Nice... digital... I can understand (and my career since I made my first clock has been totally in IT - so programming these things is a nice pastime and you can make things do things with them!). So, naturally I decided to replace the innards of my old clock (it has a teak case - yes, I know, teak... not good, but this was before we understood about things like caring for the environment) with a PICAXE based clock - reconnecting all the old controls and trying to reuse the original 7-segment display.

Unfortunately the picaxe isnt quite up to driving the multiplexing of the display without visible hiccups as the time is retrieved from a RTC chip so I bought the OLED display - which is where the brightness post comes from... as a bedside clock it is just too bright and I don't want to have things like touch switches etc to turn it on when needed - the old clock didn't have that and I want the rebuilt clock to be as like the old one as possible.

So... making a clock is where I am at *blush*

The original clock counted the mains 50hz as a time base as this is guaranteed to be exactly the correct number of cycles over a 24 hour period (although it drifts faster and slower during the day - which is a concept that I love) - so, your idea of a 50 or 60hz timebase would be very well received. The idea of using a national timebase - although not for this particular clock - would be great for the next clock so can I second that idea too.

(Have you noticed I am a clock nut by now??)
 

westaust55

Moderator
Should the World Time Zones include (or just "GMT+ ?? number); that is, city: http://www.timeanddate.com/worldclock/
In terms of World Time Zone, based on a wrist watch I had around 15 years ago and more recently a travel clock (stolen from my luggage in transit during recent overseas trip) , I envisage being able to select a “travel”/alternate time zone to the home time zone that will show the time directly in the local time as opposed to just GMT +/-x. That way you can see time and set alarm for the current local time and quickly be able to see one’s “home” time (to ensure it is 3pm and not 3am when you ring home

"Add a LED torch"... you planning on carrying this to the theatre and need the torch mode to read the programme? According to some, the OLEDs by themselves are bright enough to be considered a torch...]
The theatre may be one option. Being able to move around in a hotel, motel or construction site accomodation village in the middle of nowhere or even at home when the power is off can be an advantage - Being able to see the clock and "grab it" can be faster than search for a torch. (For myself, due to a person at home with severe medical condition, I have some lights in my home on a UPS)
 

mrburnette

Senior Member
Okay, I am going to have to do a little embarrassed owning up here :)
<...> so I bought the OLED display - which is where the brightness post comes from... as a bedside clock it is just too bright and I don't want to have things like touch switches etc to turn it on when needed - the old clock didn't have that and I want the rebuilt clock to be as like the old one as possible.

So... making a clock is where I am at *blush*

The original clock counted the mains 50hz as a time base as this is guaranteed to be exactly the correct number of cycles over a 24 hour period (although it drifts faster and slower during the day - which is a concept that I love) - so, your idea of a 50 or 60hz timebase would be very well received. The idea of using a national timebase - although not for this particular clock - would be great for the next clock so can I second that idea too.

(Have you noticed I am a clock nut by now??)
My original thinking about multiple timebases was driven because I am using the "guts" of a battery-powered wall clock with a crystal and modified to work off +5V. There is not a ready supply (that I can find) of these circuit boards and Internet searches indicate that some clocks can be modified and others cannot. Worst, some battery powered wall clocks have tossed the crystal in favor of a ceramic resonator... bummer. Since I cannot specify a good part source, I felt there would be a need for an alternate clock source.

Because I am using IR to set the clock, IR could be used (I assume) for all controlling signals. The current, working code in the 08M2 only uses IR for the initial time setting. The pulse from the modified clock guts generates a 50mS pulse and I hold the 08M2 in a wait-state until the pulse is received (0V->4.5V) and then hold it again until the pulse returns to ground. After this, I have roughly 900mS to do all the math, display routines, and come back to await the next positive transition. My issue with extensive IR is that IRIN is a blocking command. In theory, I can set an interrupt and can assume that the interrupt will fire after either of the current DO/WHILE wait routines, but again I cannot "wait" more than 900mS for the IR to be processed... this effectively rules out using IR during counting of the input pulse... unless one of the forum's clever folks has a creative idea.

Would it be possible Adrian for you to post a pic of your old clock so that I can visualize the controls that you have... the pic and a list of functions would be helpful since I would like to accommodate your wants while still trying to incorporate such things as time zones, alarms, etc.

Note to self: I wanted to use a simple 1-second, 50-60Hz, or other pulse train to keep the entire clock near the co$t of the AXE133Y... but it is going to be difficult (opinion) to add sufficient functionality to the code of the 18M2 serial PICAXE without having a RTC off-board doing clock-ish stuff. I also only have 3 spare 18M2 lines; 4 if I kill the serial input.

- Ray

PS: I have a teak box that the Bible from my wedding back in 1973 resides. At least, it is not ivory.
 

mrburnette

Senior Member
<...>, I envisage being able to select a &#8220;travel&#8221;/alternate time zone to the home time zone that will show the time directly in the local time as opposed to just GMT +/-x. That way you can see time and set alarm for the current local time and quickly be able to see one&#8217;s &#8220;home&#8221; time (to ensure it is 3pm and not 3am when you ring home

The theatre may be one option. Being able to move around in a hotel, motel or construction site accommodation village in the middle of nowhere or even at home when the power is off can be an advantage - Being able to see the clock and "grab it" can be faster than search for a torch. (For myself, due to a person at home with severe medical condition, I have some lights in my home on a UPS)
Ah, one of those "Ah moments"... I understand. Kind of like the emergency flashlight that stays plugged into the mains... it lights when the power fails and you can just jerk it out of the wall and run away. The implication is that the 'clock' would have rechargeable batteries and the software would turn on a bright white LED (perhaps w/ reflector taken from an old mini-flashlight.)

- Ray
 
Hello Ray,

Disregard my old clock for the purposes of your project. I intend to use a backlit LED display from Rapid and drive it directly rather than using the AXE133Y mostly so I can buy a bigger display and hopefully drive the backlight from the PICAXE - strobing it to produce a dimmer output - or give up completely and put a pot in line with it!!

As far as driving the clock, I know I could do it all much easier with the AXE133Y module and I like your idea of using spare space in the 18M2 but I want to do it the hard way by making as much of the gubbins myself. I am really following this thread for the ideas and solutions that you and the people here are coming up with. I will probably end up incorporating them as extra functions in my clock.

Could I ask what mechanism you would use to count mains electricity pulses? I guess it would have to be extracted from a home-made power supply - perhaps as a half wave rectified signal - would it be best to use the on chip ADCs or would the simple connection to a binary input be okay do you think? Do you think the signal would need to be converted to a square wave or would the sinusoidal wave suffice?

Adrian
 

hippy

Ex-Staff (retired)
I decided to replace the innards of my old clock ... reconnecting all the old controls and trying to reuse the original 7-segment display.

Unfortunately the picaxe isnt quite up to driving the multiplexing of the display without visible hiccups as the time is retrieved from a RTC chip ...

want the rebuilt clock to be as like the old one as possible.
Perhaps post details and circuits of that clock and people here may be able to suggest how to interface to that and make it work without the hiccups that you experienced.
 

hippy

Ex-Staff (retired)
I decided to replace the innards of my old clock ... reconnecting all the old controls and trying to reuse the original 7-segment display.

Unfortunately the picaxe isnt quite up to driving the multiplexing of the display without visible hiccups as the time is retrieved from a RTC chip ...

I want the rebuilt clock to be as like the old one as possible.
Perhaps post details and circuits of that clock and people here may be able to suggest how to interface to that and make it work without the hiccups that you experienced.
 

geoff07

Senior Member
There is always one (or two) - Standard time zone:UTC/GMT +5:45 hours

To stop IR from blocking use a dedicated 08 for the IR and get that to interrupt the main cpu with the command data. This works very well and costs nothing if you have a pre-M2 chip to use up.

Mains hum being what it is, it is probably possible to pick up 50Hz (or 60Hz) off the air in many places and still be battery operated. It is certainly easy to pick it up when you don't want to.
 
Perhaps post details and circuits of that clock and people here may be able to suggest how to interface to that and make it work without the hiccups that you experienced.
Hi Hippy,
I don't want to hijak this thread although I will post a reply to your kind suggestion here because I don't know how to link to new threads etc... perhaps you could move this to a new one if you think that would be better.

The display is a really simple setup of 6 x 7-seg LEDS with all the similar segments connected to one line each. Each common cathode is connected to its own line in such a way that if raised with a "high" command, that 7-seg display turns on those segments that are also "high".

All the "a" segments are connected to B.0, all the "b" segments are connected to B.1, all the "c" segments are connected to B.2 etc

The common cathode of 7-segment digit 1 (e.g the hours tens) is pulled low when C.5 is made "high"
The common cathode of 7-segment digit 2 (the hours units) is pulled low when C.4 is made "high"
and so on

So, to turn on all "a" segments at the same time
high B.0 (segment "a")
high C.0 (common cathode for digit 1)
high C.1 (common cathode for digit 2)
high C.2 (etc)
high C.3
high C.4
high C.5


There is no way to turn on segments independantly other than turning on the required segments (B port pins), selecting the correct digit by turning it on (C port pins) , waiting a moment and turning it off then moving on to the next digit.

My code, below, has a portion to generate hours, minutes and secods that will be replaced in a working example by data coming from a clock chip and code to convert that data to the required output patterns and strobing on and off the digits in sequence.

The code works fine in the loop "strobe: ... goto strobe" but when it goes back to "nextsecond:" the extra time that is expended in the code between the labels "nextsecond:" and where it drops through into the "strobe:" loop causes a definate blip in the display that is unacceptable. I have done some tests and most of the time is in the "lookup" statements. I dont know how to make them run any quicker. This is a 28X2 running at 16mhz which is the fastest it will go I believe without an external oscillator.

Adrian

Code:
#picaxe 28X2
#no_data

symbol dig1 = C.5
symbol dig2 = C.4
symbol dig3 = C.3
symbol dig4 = C.2
symbol dig5 = C.1
symbol dig6 = C.0

symbol ht = b2
symbol hu = b3
symbol mt = b4
symbol mu = b5
symbol st = b6
symbol su = b7

symbol hh = b8
symbol mm = b9
symbol ss = b10

symbol t = b11

symbol hhb = b12
symbol mmb = b13
symbol ssb = b14



start0:

	let dirsC=%11111111
	let dirsB=%11111111

	hhb = 22
	mmb = 38
	ssb = 40

	setfreq m16


nextsecond:

	SETTIMER t1s_16
	
	
' -----------------------------------------------------
' This code is simply to generate some data to display.
' 
	inc ssb
	if ssb > 59 then
		ssb = 0
		inc mmb
		if mmb > 59 then
			mmb = 0
			inc hhb
			if hhb > 23 then
				mmb = 0
			endif
		endif
	endif

	hh = bintobcd hhb
	mm = bintobcd mmb
	ss = bintobcd ssb

'
'  end of test data creation code
'------------------------------------------------------

	
	ht = hh / 16
	hu = hh & $0F

	mt = mm / 16
	mu = mm & $0F

	st = ss / 16
	su = ss & $0F

	lookup ht,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),ht
 	lookup hu,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),hu
 	lookup mt,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),mt
 	lookup mu,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),mu
 	lookup st,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),st
 	lookup su,(%01111110,%00110000,%01101101,%01111001,%00110011,%01011011,%01011111,%01110000,%01111111,%01111011),su

	t = timer

strobe:

'select the first digit
	pinsB = ht
	high dig1
	pause 1
	low dig1
	
	pinsB = hu
	high dig2
	pause 1
	low dig2
	
	pinsB = mt
	high dig3
	pause 1
	low dig3
	
	pinsB = mu
	high dig4
	pause 1
	low dig4
	
	pinsB = st
	high dig5
	pause 1
	low dig5
	
	pinsB = su
	high dig6
	pause 1
	low dig6

	if t = timer then strobe    ' just display the display until the second is up
	
	goto nextsecond
 
Last edited:

westaust55

Moderator
By the way... sorry but I don't know how to insert code the way you peeps do so here is is in the raw:
Reading the sticky post at the start of the active forum explains about code tags and more:
http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!

But to get you started, you wrap your code in [code] and [/code] tags.

Type them by hand or if you click on the Go Advanced button at the bottom right of the post window, you get extra editing/formatting icons on the post toolbar.
Then select the program code (Click and drag method) then click on the hash (#) icon at the right hand end of the middle row of formatting icons which will place the code tags around the program listing.
 

mrburnette

Senior Member
<...>


Could I ask what mechanism you would use to count mains electricity pulses? I guess it would have to be extracted from a home-made power supply - perhaps as a half wave rectified signal - would it be best to use the on chip ADCs or would the simple connection to a binary input be okay do you think? Do you think the signal would need to be converted to a square wave or would the sinusoidal wave suffice?

Adrian
This is way oversimplified and are just ballpark values. Input would be to a PICAXE pin that is ST and simply count in code. There are caveats, but this is the general idea:

5V pulse.jpg

JUST FOR EXAMPLE: Please understand that wall-warts are very nasty little beasts, the transformers are (generally) low-quality for the most part and you need to provide fusing, surge/transient protection, etc. DO NOT build this circuit and then use it in conjunction with the same transformer (secondary winding) providing the +5V and GND reference via a full-wave bridge. A common ground would need to be established between the two GND references created so that the PICAXE saw a common reference... a transformer with two separate (not CT) windings would be the best choice but those with electronic experience will have no issues with implementation... it is that this forum is not the proper place to teach basic electronics for power supplies.

- Ray

Here is the SPICE link:http://www.falstad.com/circuit/
Here is the code:
Code:
$ 1 5.0E-6 66.51416330443618 50 5.0 50
v 176 288 176 144 0 1 50.0 9.0 0.0 0.0 0.5
r 304 144 304 288 0 570.0
d 304 144 432 144 1 0.805904783
w 176 288 304 288 0
c 176 144 304 144 0 1.0E-5 4.8522410875917705
O 432 144 496 144 0
w 304 288 432 288 0
z 432 288 432 144 1 0.805904783 4.9
o 5 64 0 35 10.0 9.765625E-5 0 -1
o 7 64 0 35 10.0 0.1 1 -1
 
Last edited:

hippy

Ex-Staff (retired)
I have done some tests and most of the time is in the "lookup" statements. I dont know how to make them run any quicker. This is a 28X2 running at 16mhz which is the fastest it will go I believe without an external oscillator.
You are right; LOOKUP is expensive in terms of execution time. The easy fix is to use READ or READTABLE and define the actual looked-up values with EEPROM or TABLE. You will see a massive speed gain.

It would also be well worth purchasing a 16MHz resonator so you can have 64MHz operation as that will also see a four-fold speed increase.

Beyond that, the maths to determine digit tens and units has some cost so it is better to keep track of all digits separately rather than hours, minutes and seconds eg -

su = su + 1 // 10
If su = 0 Then
st = st +1 // 6
...
End If

That will allow both the BINTOBCD and subsequent tens and units extraction to disappear. You can also do the lookup of display segment bits only when the value which affects that changes so for most second ticks you only need to do one lookup.

Slightly more complicated is to alter the seconds tick code so it's interleaved with the display multiplexing; all those PAUSE 1 'do nothing' so you can use that time to do something useful instead.

It's best to move towards the 'ultimate solution' step by step so it's much clearer and obvious how you got to that and you will learn a lot more that way. There is a fair bit of incremental effort involved, altering things seeing how that affects things but it's great seeing flicker get minimised and know you're going in the right direction.

To start a new thread; go to the forum home page, select the Active Forum, and click on the "+Post New Thread". I can copy any relevant posts here over to that.
 
As for the timebase there are several options:
- half-rectified 50/60 Hz mains pulses are very accurate but will stop as soon the electricity drops. Useless technique on battery supply
- the guts of an old watch or quartz clock adapted to give 5v pulses accuracy 3 sec/week
- ICM7213 (intersil) is a normal DIL IC and needs a quartz crystal and gives accuracy of 3 sec/week and gives pulses every second and every minute
- what's wrong with the good old 1308 I2C clock?

What I would like to see in an alarmclock?

- After a freezing night I like to be woken a bit earlier (and notified why with an asterix (*) somewhere in the display) to have some extra time to clear the windscreen of the car
- adjusting display by a lightsensor
- if mains power is down the clock will run on batteries and will still wake me up. Only the display is very dim or muted and will light on a push on the (snooze?) button.
 
Last edited:

srnet

Senior Member
If you assume that a clock needs to be immune time keeping wise from mains power fails or battery packs going flat, then the only reasonable practical device I can think of would need to uses an RTC device that has its own backup battery. I2C devices are readily PICAXE able.

So which is the best choice of I2C RTC ?

There is one RTC chip around that saves the power fail time in some (battery backed up) registers, this could be a useful feature.

There are other RTC devices that can charge a small lithium battery.

There are RTC devices that have multiple alarms that could wake up a PICAXE clock from a very long sleep .....
 

mrburnette

Senior Member
As for the timebase there are several options:
- half-rectified 50/60 Hz mains pulses are very accurate but will stop as soon the electricity drops. Useless technique on battery supply
- the guts of an old watch or quartz clock adapted to give 5v pulses accuracy 3 sec/week
- ICM7213 (intersil) is a normal DIL IC and needs a quartz crystal and gives accuracy of 3 sec/week and gives pulses every second and every minute
- what's wrong with the good old 1308 I2C clock?

What I would like to see in an alarmclock?

- After a freezing night I like to be woken a bit earlier (and notified why with an asterix (*) somewhere in the display) to have some extra time to clear the windscreen of the car
- adjusting display by a lightsensor
- if mains power is down the clock will run on batteries and will still wake me up. Only the display is very dim or muted and will light on a push on the (snooze?) button.
Erik - very good enhancements.
All forum responders: great suggestions! I am appreciative for all the input.

I started the thread because I had been given an old quartz wall clock by my wife from her office which was destined for the garbage and she diverted it to me to gut. I then modified the quartz module as per the link in my blog (re: this subject) and wrote some 08M2 code which fed the AXE133Y OLED display as a kind of proof-of-concept for a completely software-driven clock design which would require only a 1-sec. input pulse which could be generated by anything external. The intent was then to port the 08M2 code to the existing 18M2 that is the serial OLED driver.

Since I was just playing around anyway and was going to have to make the 08M2 port and create a bunch of specialized subroutines to deal with formatting, internal serialization of strings, etc. I though it might be nice to add some software functionality that forum members thought useful... to build a skeleton for others to follow, easily.

In addition to asking forum members for ideas on functionality, I also asked for M2'ish demo code that would implement such ideas! I am not lazy, but... one of my beliefs is that one learns by doing.

For MY prototype which will (eventually) be posted in the completed projects section, I will use a 1-sec cheap-trick clock module from an old wall clock. It is an external timebase, so others can easily replace this with a 50Hz/60Hz counter, Low-freq timebase signal, GPS second ticker, etc. It will be set with an IR remote control.

I personally do not plan on writing external timebase routines or prototyping 'em in hardware. Anyone can search the forum on how to use a clock-calendar chip. I want the bulk of my code in software as a learning experience. What I hope to leave behind from this project is a foundation that others can reuse, just as the Magic Morse algorithms or the Bank-swapping 08M2 RAM concept. The clock may not be highly polished and will certainly lack many features mentioned in this thread, but I will try and leave a foundation for enhancement and a well-documented set of extensible code. Whose knows how this may evolve? SRNET took my Magic Morse algorithm far beyond my expectations and in doing so earned the right to call it his circuit and his project.

Thanks again to everyone - I am more than a little surprised at the response that I have received and the breath of wants and needs in this little area.
- Ray
 
Last edited:
Ok another one then... If you want to set the clock using IR and a remote, why dont you add a pin code to be entered first to prevent accidental adjustments?

since this also involves a time-out when the PIN is not finished.
 

mrburnette

Senior Member
Has MSF been mentioned in this thread?
For users over in this corner of the pond,
a useful backup device.

e
I mentioned it early on...

I've seen some novel and simple designs for receivers for both MSF and WWVB.

- Ray
 
Last edited:

mrburnette

Senior Member
Ok another one then... If you want to set the clock using IR and a remote, why dont you add a pin code to be entered first to prevent accidental adjustments?

since this also involves a time-out when the PIN is not finished.
Present issue w/ IR: It is a blocking command. So, current test code found in my blog for the 08M2 only uses IR when the power comes on to the chip... time is set and then the loop begins for keeping time. Forcing IR update then breaks the loop! Right now, IR is used to eliminate time "setting" buttons! Expanding the demo code to include calendar would require that the dialog go something like: year, month, day, time... since the last digit seconds terminate the IR conversation and starts the timing loop... 100mS is being used to lock the external pulse which leaves 900mS for all the variable updating, formatting, serialization, and OLED controlling.

One responder suggested a time-hacking button that could be pushed while observing/listening to an external time reference. I can interrupt drive such a button, so this is a great idea to incorporate.

- Ray
 
Has MSF been mentioned in this thread?
I had to look it up. I found MSF is the Atomic time radio broadcast in the UK, as the DCF is broadcasting in Germany and WWVB in the USA see http://en.wikipedia.org/wiki/Radio_clock for details on other countries.

Usually these signals are used to synchronise a free running RealTimeClock (like the 1308) once or twice a day, not to replace the complete timepiece.

I didn't find a I2Cor SPI chip doing it and it's quite a study to catch the protocol in a picaxe program
It would be a nice project, though

And with the multi-program Picaxes these days....

Topic starter Ray wants to re-use the electronic guts from an old quartzclock and therefore asks for funny anhancements on the theme 'clock'
 

srnet

Senior Member
Has MSF been mentioned in this thread?
For users over in this corner of the pond,
a useful backup device.

e
Decoding the slow code from the Rugby time signal (yes I know its the MSF clock now) is not that difficult either, I did it many years ago in PIC assembler. The frequency, 60khz, is low enough that you can use audio amplification and filtering techniques.
 
Thanks for your reply Ray. Unfortunately I understood very little of that indeed. I get the part about schmidtt triggers being the best option... but little else.
...this forum is not the proper place to teach basic electronics for power supplies.
...rather puts an end to this particular stream of thought ;-) I do understand that this thread isn't about power supplies though.
Regards,
Adrian
 
You are right; LOOKUP is expensive in terms of execution time. The easy fix is to use READ or READTABLE and define the actual looked-up values with EEPROM or TABLE. You will see a massive speed gain.

It would also be well worth purchasing a 16MHz resonator so you can have 64MHz operation as that will also see a four-fold speed increase.
READ, indexing into a table, together with realisation that I had the 28X 3V module which goes up to 64mhz has completlely solved my issue. THANK YOU Hippy!! Display now looks as good as it did in the 1980s!! (These 7-seg LEDs were only rated to have a 3 year life - back then then had no idea how long they would last)
 

mrburnette

Senior Member
Apologies.
Advanced search didn't find it. :-(

e
Well, I mentioned it in passing in regard to WWVB and
(5) Alternate 1-second sources to drive the PICAXE PINC.3
a. 50/60Hz sources (electrically isolated)
b. National timebases such as WWBV / MSF / etc.

Sorry I did not give it much space. There is a rather lengthy MSF thread from a few years back:
http://www.picaxeforum.co.uk/showthread.php?11334-Decoding-UK-s-NPL-MSF-Time-Signal

and some good articles and PDF info from a Google search. Perhaps someone will take the topic and post a simple receiver with a 1-second output to drive the 18M2 OLED clock-to-be. One of the reasons I wanted an external 1-second source is for flexibility in selecting the clock source.

- Ray
 

srnet

Senior Member
Flexibility (of the clock timing source) is a good thing.

But if I was developing this, constantly changing the code etc, it would iritate me a great deal having to manually set the time and date every time you did a code download or power reset.

I can see in minimal component situations that inventive solutions to an accurate time source, such as hacking a old digital watch, have merit.

But we already have a 18M2 and an OLED, so is the extra cost of a RTC such as DS1307 (code readily available) a big deal ?

And going forward into developing a unit that is a useful device once built, the ability to remember the time after a power fail would be essential in my view.
 
Top