Propeller Real Time Clock
william chan
Posts: 1,326
Can I use one cog to keep track of real time and calendar?
How accurate will the clock be using the 5Mhz crystal and running at 80Mhz?
Will the accuracy be comparable to using a 32Khz clock crystal?
Has anybody created a real time clock and calendar driver yet?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
How accurate will the clock be using the 5Mhz crystal and running at 80Mhz?
Will the accuracy be comparable to using a 32Khz clock crystal?
Has anybody created a real time clock and calendar driver yet?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
I know that using a cog to keep track of time would be a money/space saver, but having one that would keep track of time and calendar would be a bit tricky, hence why I looked into the DS1302. It does seconds, minutes, hours (12 or 24 hour modes), date, month, year and the day (Monday, Tuesday, Wednesday...)
Attached is the horribly ugly code that I am known for... it may be a bit difficult to understand at first, but its actually really simple.
It is really plain, it displays the current time on a VGA monitor... it shows HH:MM:SS in 24-hour mode, then under it is the time in binary(it is in BCD though, because that is how the chip is designed). Two more lines down it shows the date in DD/MM/YYYY configuration, then under that I attempted to have it display the date again, only it would spell out the day (Friday for example) and then month. It also shows the date again, only with a "st", "nd", "rd" or "th" at the end of the number... but I realised that with my code, it only reads the 1's posistion, and therefore would add an "rd" to 13 for example.... which would be 13rd, haha.
Have fun.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you want more fiber, eat the package.· Not enough?· Eat the manual."········
There is a DS1307 (I2C) version in the propeller object exchange library.
http://ww1.parallax.com/Default.aspx?tabid=65
Accuracy of course is going to depend on the quality of your crystal. The lower the ppm (pulses per million) value the better
your accuracy is going to be. Suppose your 5MHz crystal was rated at ±50ppm. After dividing down the 5MHz crystal to 32.768kHz,
your effective ppm would be about ±.33 in this case. ((32.768kHz/5MHz)* ±50ppm) = ±.33ppm A typical 32.768kHz crystal would
have a ppm rating of ±20ppm.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
<note> these are back of the page calculations, I may be off on some numbers </note>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
715:715:715
I get the same thing with the 1302 disconnected.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
It is most likely a code error somewhere... I'll try to figure out what happened.
What do the other lines look like?
Are you using the Demo board?
Are you using pull-up resistors on the 1302?
Since it does the same thing without the 1302 in place, some registers may just be messing up somewhere... however, I do find it interesting that you are getting 3 charaters between the semicolons... the code is only supposed to write 2.
I like feedback, positive or negative!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)
715:715:715
11_1111 111_1111 111_1111
715/715/20175
,· 715th, 20715
The 1302 is OK - it runs fine with my Stamp.· Since the 1302 operates at 5VDC and the Prop at 3.3VDC, I have a 1.2K resistor in series with the three clock leads going to the Prop.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
The 1302 can be powered by as low as 2.0 volts, I just power mine at 3.3v - straight from the Vdd on the demo board.
Try pulling those series resistors out, and just power the 1302 at 3.3v. Let me know what happens!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)
I just hooked my 1302 up with series resistors and ran it at 5v on my demo board, and it ran fine. I pulled the chip out of the bread board, and my monitor did the 715 thing. So, I disconnected the /Rst, IO and Sclk pins one at a time, and when I disconnected the IO pin, it did the 715 thing again. With either of the other two pins disconnected, it displayed 0's instead. I even tried running it without the xtal across pins 2 and 3, and it just displayed the last time that was in it's registers and didn't continue to count.
So I'm quite certain that the IO pin is floating. I'm also using the same, unmodified program that I uploaded and I'm getting no errors. The only other thing that I can think of is possibly a wiring error? Check at the top of the spin file, it gives details on how to hook the 1302 up to the propeller.
DS1302 pin 5 (/Rst) -> Propeller P2
DS1302 pin 6 (I/O) -> Propeller P1
DS1302 pin 7 (Sclk) -> Propeller P0
Note that the "P0" through "P2" does not mean the pin, it is the actual IO port number.
You can hook the 1302 up to a different set of pins, however you must change the pin numbers in the CON block.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
00:00:NNNN where N may be any number from 0 to 5.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Thank you for the program.· Running it in OS makes a tremendous difference.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
I'm really glad to hear you got it working - although it is still strange that it would not run stand-alone.
Anyhow, there is a way to set the time through the program... like I said, the code is kinda dirty... didn't really clean it up a lot or make it really user-friendly before posting it.
Under the "init" routine (at the bottom) there should be 7 lines of syntax that are commented out:
'· WriteCmd($80, %0000_0000) 'Seconds
'· WriteCmd($82, %0000_0000) 'Minutes
'· WriteCmd($84, %0000_0000) 'Hours
'· WriteCmd($86, %0000_0000) 'Date
'· WriteCmd($88, %0000_0000) 'Month
'· WriteCmd($8A, %0000_0000) 'Day
'· WriteCmd($8C, %0000_0000) 'Year
You use the code by deleting the ' mark so that the tool will program it to the Prop.· The values are in BCD, so the upper/lower nibbles are the 10's and the 1's posistion for the numbers, respectively.
For example:
If you wanted to set the hour to 9 o'clock, the minutes to 32, and seconds to 46, you would do this:
WriteCmd($80, %0100_0110) 'Seconds
WriteCmd($82, %0011_0010) 'Minutes
WriteCmd($84, %0000_1001) 'Hours
Like I said, it is in BCD (Binary Encoded Decimal) so 32 dec = 0011_0010, NOT 0010_0000.
Also, be careful with the Seconds and Hours registers:· bit 7 in Seconds is the Clock Halt bit - setting this bit to a 1 will make the chip stop keeping time!· Also, the 7 bit in the Hours register will set it to 12/24 hour mode: Clearing the bit makes it 24-hour mode (which is what the program is designed to use), and setting it to 1 puts it in 12 hour mode.
Also, I noticed that you said you moved the chip to Prop pins 19-21.· I take it that you aren't using the Demo board?· I built the clock on my demo board... maybe that has something to do with it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)
I'll let you know how it works out.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
If you get that to work, that would be great. I used BCD because the spec sheet that I refrenced said everything was BCD.
I wrote those lines into the init routine because I wanted a quick-and-dirty way to do it while I was writing the code in the Main routine... and the code that you downloaded wasn't really inteded to be given out so soon. It just so happened that this topic came up when it did.
I am going to eventually alter the program such that you can use a PS/2 keyboard to type in the time, or just use an array of buttons to change the time (such as a normal clock!). This would have been done over a week ago, but school and work takes priority! (well, most of the time anyways)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
while alive = 1
wakeup
program(propeller)
eat(3)
sleep(7)