Hairy Animal
Member
Hi,
I note with interest plenty of really helpful stuff in this forum relating to the DS3231 RTC module, which I've used before in several applications and always found it to be incredibly good at keeping accurate time.
However, in a new project I'm currently trying to program, the time, as displayed via a simple 2-line LCD and an AXE133, seems to be losing about ten seconds a day. I'm reading multiple DS3231 registers more than once a second and I'm wondering if this might somehow be affecting its timekeeping?
Any suggestions as to what might be wrong would be welcome? I've checked the backup battery (the module was unpowered overnight and lost about five seconds) and it's good at 3.45V. I haven't checked anything like the Ageing Offset and/or temperature registers yet.
Time display prog below:
I note with interest plenty of really helpful stuff in this forum relating to the DS3231 RTC module, which I've used before in several applications and always found it to be incredibly good at keeping accurate time.
However, in a new project I'm currently trying to program, the time, as displayed via a simple 2-line LCD and an AXE133, seems to be losing about ten seconds a day. I'm reading multiple DS3231 registers more than once a second and I'm wondering if this might somehow be affecting its timekeeping?
Any suggestions as to what might be wrong would be welcome? I've checked the backup battery (the module was unpowered overnight and lost about five seconds) and it's good at 3.45V. I haven't checked anything like the Ageing Offset and/or temperature registers yet.
Time display prog below:
Code:
; View the clock on LCD
; 248/2048 bytes
; See_time_only.bas
; 12:00
; 21/02/2026
;
#REM
Messages available in the LCD:
EEPROM $00, ("The Hairy Animal") ; store msg 0 in the EEPROM memory
EEPROM $10, (" Auto Charger ") ; store msg 1 in the EEPROM memory
EEPROM $20, ("Wait > Sunday ") ; store msg 2 the EEPROM memory
EEPROM $30, ("Wait > Wednesday") ; store msg 3 in the EEPROM memory
EEPROM $40, ("Charging dc-dc ") ; store msg 4 in the EEPROM memory
EEPROM $50, ("Charging ac-dc ") ; store msg 5 in the EEPROM memory
EEPROM $60, ("Charge rem ") ; store msg 6 in the EEPROM memory
EEPROM $70, ("Time: ") ; store msg 7 in the EEPROM memory
EEPROM $80, ("Date: ") ; store msg 8 in the EEPROM memory
EEPROM $90, (" It's Sunday ") ; store msg 9 in the EEPROM memory
EEPROM $A0, (" It's Monday ") ; store msg 10 in the EEPROM memory
EEPROM $B0, (" It's Tuesday ") ; store msg 11 in the EEPROM memory
EEPROM $C0, (" It's Wednesday ") ; store msg 12 in the EEPROM memory
EEPROM $D0, (" It's Thurdday ") ; store msg 13 in the EEPROM memory
EEPROM $E0, (" It's Friday ") ; store msg 14 in the EEPROM memory
EEPROM $F0, (" It's Saturday ") ; store msg 15 in the EEPROM memory
#ENDREM
init:
#picaxe 20M2
#NO_DATA
; DoW data in display memory.
; Programming assumes that the RTC (DS3231) is correctly programmed
; with the time and that only the alarm and status/control registers
; need to be read & written.
;
SYMBOL dcdc_relay = B.0 ; Name for the fwd relay o/p pin.
SYMBOL acdc_relay = B.1 ; Name for the rvs relay o/p pin.
SYMBOL LED_1 = B.2 ; Name for the first LED o/p pin.
SYMBOL LED_2 = B.3 ; Name for the second LED o/p pin.
SYMBOL LED_3 = B.4 ; Name for the third LED o/p pin.
SYMBOL LCD_out = B.6 ; Serial line to LCD (AXE133 board
; with 18M2 & 16 chr x 2-line display).
;
SYMBOL PB_1 = C.0 ; Name for the first (RVS) button i/p pin.
SYMBOL PB_2 = C.1 ; Name for the second (STP) button i/p pin.
SYMBOL PB_3 = C.2 ; Name for the third (FWD) button i/p pin.
;
SYMBOL Analog_in = C.7 ; Name for the analog i/p pin.
;
; --------------------------------------------------------------------
LOW dcdc_relay : LOW acdc_relay : LOW LED_1 : LOW LED_2 : LOW LED_3
;
PAUSE 1500
;
HI2CSETUP i2cmaster, %11010000, i2cfast, i2cbyte
;default chip address
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Variables
;
SYMBOL Sundays = b1
SYMBOL xfer = b2
SYMBOL units = b3
SYMBOL tens = b4
SYMBOL status = b5 ; Status = 2, 3, 4 or 5 i.e.
; 2 = Wait > Sunday msg 2
; 3 = Wait > Wednesday msg 3
; 4 = Charging dc-dc msg 4
; 5 = Charging ac-dc msg 5
SYMBOL butt = b6
SYMBOL A1M1 = b10
SYMBOL A1M2 = b11
SYMBOL A1M3 = b12
SYMBOL A1M4 = b13
SYMBOL Control = b14
SYMBOL DoW = b15
SYMBOL hour = b16
SYMBOL hourval = b17
SYMBOL bcdVal = b18
SYMBOL BCD_calc = b19
SYMBOL Day_Addr = w10
SYMBOL Day_len = b22
SYMBOL xxx = b23
SYMBOL Day_chr = b24
;
SYMBOL mskLoNibble = %00001111
SYMBOL mskHiNibble = %11110000
;
SEROUT LCD_out,N2400,(254,1) ; clear the display.
PAUSE 500
SEROUT LCD_out,N2400,(254,192) ; move to second line
PAUSE 100
SEROUT LCD_out,N2400,(253,7) ; display predefined message 7, Time:
PAUSE 50
butt = 0
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Start:
GOSUB Show_Dow
;
;
GOSUB Show_time
;
PAUSE 750
;
GOTO Start
END
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Subroutines
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Show_Dow:
SEROUT LCD_out,N2400,(254,128) ; move to start of first line
PAUSE 10
HI2CIN 03, (xfer) ; Put the BCD DoW into xfer.
SELECT CASE xfer
CASE 1
SEROUT LCD_out,N2400,(253,9) ; display predefined message 9, Sunday
CASE 2
SEROUT LCD_out,N2400,(253,10) ; display predefined message 9, Monday
CASE 3
SEROUT LCD_out,N2400,(253,11) ; display predefined message 9, Tuesday
CASE 4
SEROUT LCD_out,N2400,(253,12) ; display predefined message 9, Wedsday
CASE 5
SEROUT LCD_out,N2400,(253,13) ; display predefined message 9, Thursday
CASE 6
SEROUT LCD_out,N2400,(253,14) ; display predefined message 9, Friday
CASE 7
SEROUT LCD_out,N2400,(253,15) ; display predefined message 9, Saturday
ENDSELECT
RETURN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Show_time:
; Display the time on the second row of the LCD.
HI2CIN 02, (xfer) ; Put the BCD hours into xfer.
; bcdVal = xfer : Gosub ShowBCD
BCDTOASCII xfer, tens, units ; Convert hours to ASCII for display.
;
SEROUT LCD_out,N2400,(254,192) ; move to second line
PAUSE 100
SEROUT LCD_out,N2400,(254,198) ; move to sixth posn on second line
PAUSE 10
SEROUT LCD_out,N2400,(tens, units,":") ; Display hours.
HI2CIN 01, (xfer) ; Put the BCD minutes into xfer.
BCDTOASCII xfer, tens, units ; Convert to ASCII for display.
SEROUT LCD_out,N2400,(tens, units,":") ; Display minutes.
HI2CIN 00, (xfer) ; Put the BCD seconds into xfer.
BCDTOASCII xfer, tens, units ; Convert to ASCII for display.
SEROUT LCD_out,N2400,(tens, units) ; Display seconds.
RETURN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End;