Real-Time Issue
Shadowcasterx4ffc
Posts: 13
We are having trouble keeping real time on our BS2 board. The clock is about 3 seconds off per minute. We also tried using the DS1302 chip, but that is also inaccurate. We're wondering if it's an issue with the code that we're using:
[noparse][[/noparse]code]second VAR Word
tree VAR Word
hour = 11
minute = 01
second = 00
SEROUT 13, 84, [noparse][[/noparse]22, 12]
DO
PAUSE 995
second = second + 1
PAUSE 5
SEROUT 13, 84, [noparse][[/noparse]22, 12]
SEROUT 13, 84, [noparse][[/noparse]"Automated Greenhouse", 13,
DEC2 hour, ":", DEC2 minute, ":", DEC2 second]
DEBUG HOME, DEC2 hour, ":", DEC2 minute, ":", DEC2 second, CR
IF second > 59 THEN
minute = minute + 1
second = 0
ENDIF
tree = 400
IF minute > 59 THEN
minute = 0
hour = hour + 1
ENDIF
tree = 800
IF hour > 24 THEN
hour = 1
ENDIF
tree = 1000
IF hour > 18 THEN
LOW 12
ELSEIF hour > 6 THEN
HIGH 12
ELSEIF hour < 7 THEN
LOW 12
ENDIF
tree = 2000
LOOP[noparse][[/noparse]/code]
The tree variable is just a placeholder, and does nothing in the program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greenhouse Project
[noparse][[/noparse]code]second VAR Word
tree VAR Word
hour = 11
minute = 01
second = 00
SEROUT 13, 84, [noparse][[/noparse]22, 12]
DO
PAUSE 995
second = second + 1
PAUSE 5
SEROUT 13, 84, [noparse][[/noparse]22, 12]
SEROUT 13, 84, [noparse][[/noparse]"Automated Greenhouse", 13,
DEC2 hour, ":", DEC2 minute, ":", DEC2 second]
DEBUG HOME, DEC2 hour, ":", DEC2 minute, ":", DEC2 second, CR
IF second > 59 THEN
minute = minute + 1
second = 0
ENDIF
tree = 400
IF minute > 59 THEN
minute = 0
hour = hour + 1
ENDIF
tree = 800
IF hour > 24 THEN
hour = 1
ENDIF
tree = 1000
IF hour > 18 THEN
LOW 12
ELSEIF hour > 6 THEN
HIGH 12
ELSEIF hour < 7 THEN
LOW 12
ENDIF
tree = 2000
LOOP[noparse][[/noparse]/code]
The tree variable is just a placeholder, and does nothing in the program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greenhouse Project
Comments
But really, an RTC such as the DS1302 or the DS1307 *is the way to go*. The Stamps are just not set up for this kind of time-base keeping.
I have found that these clocks are accurate to within a minute or so over many months, so I am curious why you say your DS3102· was inaccurate? The biggest factor in an inaccurate timebase from these clocks seems to be either mis-matched or improperly setup crystal. Noise or lack of ground plane or distance from the crystal to the chip can be factors (breadboards are not good for this --it is often better to solder the crystal right to the osc pins of the clock chip, or insert the pins with the clock itself into the socket). If you are soldering on a protoboard or the like, install the crystal right next to the osc pins and make sure to route other power/data with some distance from the crystal (if you can't do a real ground plane beneath it as detailed in the clock datasheets).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Best thing to do is to adjust the PAUSE time and change that when you remove the DEBUG statement. Run this for 24 hours and see how far off it gets, then fine tune the PAUSE time to compensate. Remember that the Stamp is not designed for long term timekeeping accuracy. For that, you'll have to use an external clock. The DS1302 is much better than just a Stamp, but you have to be careful with the board layout and follow the manufacturer's recommendations. All RTCs with external crystals are sensitive to board layout and all RTCs without temperature compensation are sensitive to ambient temperature.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greenhouse Project
Go to the main Parallax web page and select the Resources tab, then choose Nuts and Volts Columns.
http://forums.parallax.com/showthread.php?p=531080
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering