Real Time Clock in PICAXE hardware

techElder

Well-known member
Noticing that there are many posts on the forum about this or that RTC chip, I've often wondered why that function isn't built into the PICAXE silicon by now.

Seems like a natural thing to have functions that deal with accurate real time and not just timing.

After all, Mr. Hippy has done enough "clocks" in PICAXE Basic to show that something like that is feasible.
 

hippy

Technical Support
Staff member
After all, Mr. Hippy has done enough "clocks" in PICAXE Basic to show that something like that is feasible.
I think that's also part of the reasoning behind Microchip not adding real RTC to a PICmicro; if you can do it easily in software there's arguably no need for dedicated hardware. I would also guess there has to be consideration that adding real RTC ( with battery backup etc ) on-chip would eat into their own, and other manufacturer's, market for selling specialised RTC IC's. Alternatively it may be that it's actually too complicated to make sense to do it, simply easier to have it as an external chip solution.
 

srnet

Senior Member
It is down to Microchip who make the PICs used by Rev Ed.

Microchip do have real time clocks in some of the higher end (more expensive) 24 series PICs, but choose not to add the hardware to the silicon used in the cheaper PICs typically used in PICAXEs.

What could (in theory) be done in PICAXEs (28X2, 40X2 for instance) is to put a clock crystal on the Secondary Oscillator and have that increment one of the internal timers. So in software you could use interrupts to produce a low power background RTC, with the clock independant of the PICAXEs running clock.
 

techElder

Well-known member
Well, if it's so easily done in software, then couldn't we get PICAXE commands to work with RTC functions that are native to the code? GETCLOCKTIME, SETCLOCKTIME, ALARMTIME. I suppose it's a matter of code space? That's certainly changing with the passage of time.
 

westaust55

Moderator
Well, if it's so easily done in software, then couldn't we get PICAXE commands to work with RTC functions that are native to the code? GETCLOCKTIME, SETCLOCKTIME, ALARMTIME. I suppose it's a matter of code space? That's certainly changing with the passage of time.
But, for which RTC ?

the "basic" DS1307 or the DS1338 which is 100% compatible but can operate at 400 kHz i2c clock speed?

A DS1337 with 2 inbult alarms

other more precision devices or with other features?

Is the interface to be the usual i2c or SPI or even 1-Wire?
 

srnet

Senior Member
Well, if it's so easily done in software, then couldn't we get PICAXE commands to work with RTC functions that are native to the code? GETCLOCKTIME, SETCLOCKTIME, ALARMTIME. I suppose it's a matter of code space? That's certainly changing with the passage of time.
Whilst possible in software, that does not mean its easy, background interrupts (that must always be serviced) can impact on lots of other stuff too.

And code space would be an issue of course.
 

Captain Haddock

Senior Member
Has anyone written a subroutine for setting the time on a ds1307 using buttons and lcd without having to connect a pc to set it? I have set mine with the i2c write program and re-loaded the picaxe with the previous program afterwards, this seems a very messy way to do it, I've tried search but nothing shows up.
 

hippy

Technical Support
Staff member
Well, if it's so easily done in software, then couldn't we get PICAXE commands to work with RTC functions that are native to the code? GETCLOCKTIME, SETCLOCKTIME, ALARMTIME. I suppose it's a matter of code space? That's certainly changing with the passage of time.
Firmware space is one issue, and it would also need RAM to be used to hold current and alarm times, but a transparent software implementation of a full RTC would still be at odds with allowing blocking commands where it couldn't keep accurate track of time while blocked.

If people want to use a PICAXE as an RTC with the limitations on what else they can do there's not a lot stopping them from doing that as it is. The M2's have the 'time' variable which goes some way to aiding that, the X2's have SETTIMER and interrupts, and it is possible to configure the PICAXE as if it were an RTC.
 

mrburnette

Senior Member
Has anyone written a subroutine for setting the time on a ds1307 using buttons and lcd without having to connect a pc to set it? I have set mine with the i2c write program and re-loaded the picaxe with the previous program afterwards, this seems a very messy way to do it, I've tried search but nothing shows up.
Would half of the solution help? I use IR receive to set the time for my OLED clock but I'm not using an external DS1307... it would be simple code to augment the following to format and write to the DS1307:
Code:
SetClock:   ; Gather double-digits from IR for Hours / Minutes / Seconds in 24-hour format
{
	hour = 00 : mins = 00 : secs = 00 : Line = 1
	DispFlag = 3 : GoSub Display
	Pause 6000
	DispFlag = 5 : GoSub Display
	
	HOURS:
	; X_:__:__
	GoSub GetIR
	hour = InfraRed * 10
	IF hour > 20 then HOURS
	DispFlag = 2 : GoSub Display

	; _X:__:__
	GoSub GetIR
	hour = hour + InfraRed
	IF hour > 24 then HOURS
	DispFlag = 2 : GoSub Display

	MINUTES:
	; __:X_:__
	GoSub GetIR
	mins = InfraRed * 10
	If mins > 50 then MINUTES
	DispFlag = 2 : GoSub Display

	; __:_X:__
	GoSub GetIR
	mins = mins + InfraRed
	If mins > 60 then MINUTES
	DispFlag = 2 : GoSub Display

	SECONDS:
	; __:__:X_
	GoSub GetIR
	secs = InfraRed * 10
	If secs > 50 then SECONDS
	GoSub Display

	; __:__:_X
	GoSub GetIR
	secs = secs + InfraRed
	If secs > 60 then SECONDS
	GoSub Display

	ISset = 1
	GoTo Main
}

GetIR:      ; Read "Sony" compatible IR remote control for each digit: HH:MM:SS
{
	IRIN IRinput, InfraRed
	
	Pause 1000 ; Change this to make yourself happy and avoid repeat inputs...

	If InfraRed < 9 then
		INC InfraRed
	else
		InfraRed = 0
	EndIf

	Return
}
Entire 20X2 code here: http://www.picaxeforum.co.uk/entry.php?46-Hack-OLED-AXE133Y-to-upgrade-18M2-to-a-20X2-PICAXE


- Ray
 
Top