Shop OBEX P1 Docs P2 Docs Learn Events
RTC - Philips PCF8583 — Parallax Forums

RTC - Philips PCF8583

parskoparsko Posts: 501
edited 2007-03-26 22:39 in Propeller 1
Hello all,

I built a PCF8583 RTC this weekend and got it going. I used James' I2C object to drive it. Got it going with the exception of one problem.

When I read the time in, via the "ReadTime" routine in "RTC_8583_SPIN_A_002", I have a problem with the results. On screen, the output with be, regarless of the loop time (waitcnt) at the end:

Correct time
"99 99 99 99"
Correct time
"99 99 99 99"
...

The correct time, is obviously, the correct time at that moment. The "99 99 99 99" is a result of me limiting all values of the BCD format to 9 (instead of 15, which is what b1111 is).

So, I have deduced that every other loop read, the SDA line is held high, yielding all 1's. I countered this by adding an additional read, so that my output does not ever show the "99 99 99 99", since it basically skips outputting this.

I played around with this "extra" read in the "ReadTime" routine. I tried removing it, then enabling it. The results were inconsistent. Meaning, sometimes it would ONLY output "99 99 99 99", and never the right time. While sometimes it would output the correct time, and never the "99 99 99 99". So, I concluded that it had something to do with how/when it would start reading the data, but can't deduce where my "scheme" is failing.

I would eventually like to do this with a high spead assy-only driver, but first I need to get the thing robust in SPIN.

Any thoughts?

Thanks,

-Parsko

PS - I included the PCF8583 datasheet in the attached archive.

PPS - There is supposed to be a trimmer capacitor on the crystal. I do not have one. I am not too concerned with being within 5 seconds accuracy per year. Is this the only reason for it, or would I be okay leaving it off?

PPPS - One of the reasons why I did this was to have the clock working with the back-up battery. Between the battery and RTC, there is a diode. I keep seeing a resistor either before or after the diode. Is this required? If so, before or after the diode, and why? Trying to learn something new with this question...

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-26 13:56
    Have a look at the I2C routines used in FemtoBasic (OS_i2cSpiInit) and the Propeller OS (OS_loaderInit). Both are in assembly and should work fine with the PCF8583. There's a pause constant (i2cPause) that sets the time the routines wait before checking for a new I/O request. It's set to 10us and limits the speed the routines can respond to successive I/O requests. You could make it smaller if you want (like 1us ... see the start routine in OS_i2cSpiInit).

    The spec sheet shows the minimum trimmer capacitance is 5pF. it's probably considered part of the load capacitance for the crystal. You might want to have some fixed capacitance like 10pf.

    Off hand, I can't see why you'd need a resistor in the back-up battery circuit. If a rechargable battery is used for backup, there would be a resistor as part of the charging circuitry, but not if a lithium coin cell were used. Post the circuit if you're concerned.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-03-26 14:13
    I just had a very quick look at your code. The last byte read should be with the ackbit set to 1, try that and see if that helps.

    The series resistor (series is series, it does not matter where) is mandatory for production equipment when batteries are used in case of a short that might cause the battery to meltdown. A value of 1K is typical. The resistor is of course used for current limiting rechargeable cells and supercaps when they are used.

    Oh, and I have seen tiny little button cells short out and melt the casing of one of those pendant FM radios smhair.gif

    *Peter*
  • mahjonggmahjongg Posts: 141
    edited 2007-03-26 14:17
    A diode is normally only used between the normal power supply (VCC) and the battery (normally with a resistor in series).
    It's use is to either power the RTC (instead of from the battery) when power is available, or to "trickle charge" the battery when power is available, but the latter is not needed (possible) when using a lithium coin cell, as Mike explained.
    In either case the diode is there to prevent the battery from draining out through the unpowered circuitry in case of a power failure, or if power is simply turned off.

    However, the exact configuration of these components depends on the battery used (trickle chargable or not), and the RTC. Some RTC chips have a single power pin for both normal, VCC powered, and battery backup powered states, other have a seperate battery power input pin.

    also, in many countries there are regulations that state that you need to have sufficient components (in series with the battery) so that no single component that fails (shorts out) can damage the battery, by either shorting it or by allowing in too much current from a too high voltage. Thats why you often see both a diode and a series resistor, or even two resistors in series. Also a capacitor directly across the battery terminals (without a series resistor) is also "forbidden" for the same reason. All this is to prevent the battery from exploding, when a component fails.

    Mahjongg.
  • parskoparsko Posts: 501
    edited 2007-03-26 14:33
    www.mikroe.com/pdf/rtc_board_schematic.pdf

    Thanks for your replies guys. I am about to go home and take another closer look at my setup. I used nearly the same identical setup as the schematic, less the trimming cap and in-line resistor mentioned.

    I keep thinking my issue with the "99 99 99 99" value might be in how the RTC starts up. I might need to read once, before I start my loop. I'm not sure. I have a loop in there that sets the time, then, once set, I "note" it out so only the loop then runs at next code download.

    Also, I seem to recall from last night that I originally had the resitor in there, but the RTC lost power when I removed the main power, so I removed it. I will confirm this shortly.

    I'm using a standard issue CR2032 I removed from a scrap motherboard I bought for 2euro. I know it's working, as I said earlier, cause I lit it up this morning, and the time was still correct.

    The "99 99 99 99" thing is killing me right now, must go home and play....

    -Luke

    PS - The schematic above is the first schematic that I have searched for that was exactly what I needed, and had parts for, ever. I'm only into this hobby for two years now, and that has never happened before. I've always had to either find the right parts, or adjust something to work with something else. It had never been this easy...
  • parskoparsko Posts: 501
    edited 2007-03-26 22:00
    I think I have solved the riddle.

    So, it seems to require that the 8th byte be read. If you want more detail than the 8th bit, for instance, seconds resolution, you'll need to read all the bits before it (in the case of seconds, you would need to read from the seconds byte up to and include the alarm control byte. But, once you ask to read a memory location above the alarm control byte, you can read as many as you want. This all implies that one cannot read the seconds byte only, or any other byte only (except the alarm control byte).

    Anyway, RTC's are new to me, so it was a learning experience. I haven't tried doing the hardware changes yet. But, I will and update if it makes a difference. Mike, I did spend a bit of time perusing OS_loaderInit. Now, for some reason, it makes more sense to me than it did many moons ago when I went through it. I may PM you with a few questions at some point, probably not in the too near future (expecting my first in <1wk)... smilewinkgrin.gif

    So, attached is the bulletproof code, outputing HH MM SS ss.

    Need sleep, fading.......away..................

    Thanks for the help!

    -Luke
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-03-26 22:39
    The RTC needs to latch the current time when you do a read, that is why the last byte read is not ack'd. Did you try it? (Just do a dummy read after the loop).

    The reason that capacitors are not allowed directly across the battery is that they can breakdown and short especially in the case of smoking tantalums. All capacitors really are just two contacts screaming to short out but being kept apart by that pesky thin dielectric smile.gif

    *Peter*
Sign In or Register to comment.