RTC chip or PIC?


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938

    Default RTC chip or PIC?

    Hello,

    I was asking myself why one would prefer to use an particular RTC chip instead of using a PIC running a 32,768kHz crystal?

    Unfortunately, I don't have such a crystal in my drawer and can't make any tests but is there anything "obvious" making a big difference I do not see?
    Roger

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I like RTC because of all of the built in stuff. Date, time, alarms etc. Save alot of programming and code space. Always running, check it when needed.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    ... why one would prefer to use an particular RTC chip ...
    I prefer the ST M41T81. In addition to macrackit's points, it survives power cycles (even recording the time power was lost), can generate a squarewave of several frequencies and battery life is >10 years. I suppose one could duplicate all that with a small PIC but there's no cost saving.
    Last edited by dhouston; - 27th July 2009 at 16:14.

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I prefer the ST M41T81
    Good product, unfortunatly sold only in 8-pin SOIC package.

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default How to trigger the "second" increment?

    I have started some trials with a DS1307.

    Since the smallest "common" change in RTC are seconds, I assume there is no use for the PIC to query constantly the RTC; every second should be enough.

    How do I achieve this? I couldn't find a clue in either datasheets
    http://www.datasheetcatalog.org/data...xim/DS1307.pdf
    http://www.datasheetcatalog.org/data...onics/7529.pdf

    Maybe, I should rather use a RTC chip with alarm such as a DS1678
    http://datasheets.maxim-ic.com/en/ds/DS1678.pdf
    Last edited by flotulopex; - 28th July 2009 at 10:49. Reason: adds
    Roger

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is what I do with the DS1337. I have not used the one you have.
    Setup:
    Code:
    SecReg CON $00
    DS_SCL	VAR	PORTD.1
    DS_SDA	VAR	PORTD.0
    RTC	CON	%11010000
    sec VAR BYTE ' seconds
    MINs VAR BYTE ' minutes
    hr VAR BYTE ' hours
    day VAR BYTE ' day
    date VAR BYTE ' date
    mon VAR BYTE ' month
    yr VAR BYTE ' year
    Then when I want to read the RTC:
    Code:
    I2CRead DS_SDA, DS_SCL, RTC, SecReg, [sec,MINs,hr,day,date,mon,yr] 
    PAUSE 100
    Serout2 PORTC.6, 16572, [ "TIME ", HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec,$d, $a]
    Serout2 PORTC.6, 16572, [ "DATE ", HEX2 mon,"-",HEX2 date,"-",HEX2 yr,$d, $a]
    Maybe this can be adapted to yours.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Here are two types:

    RV-3029-C2 : Extremely Accurate RTC Module with embedded Xtal.

    * Offers temperature compensated time (very high time-accuracy of ± 6ppm from -40°C to +85°C and ± 8ppm from -40°C to +125°C.)

    * Integrated Temperature Sensor with digital-output and offers 8 Bytes
    RAM and 2 Bytes EEPROM for customer's application.


    Here is another one:
    RTC-4553
    • Built-in crystal unit.
    • Builtin 30 x 4-bit S-RAM.
    • Reference pulse output. (1024 Hz, 1/10 Hz)
    etc.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Trigger the time (seconds) change

    Thanks mackrackit,

    My question was more about to understand how to trigger the time (seconds) change to start a display update or refresh.

    I was thinking about putting the PIC in low-power mode until the next second change happens; how to achieve this the best way?

    So is there any particular specification of RTC chips that will allow one to find a modell having, for example, a functionality setting a bit or a flag telling the second has changed?

    BTW, here is the code (multiple sources - thanks to All of them) I work on now for my tests:
    Code:
    <html><head></head><body><!--StartFragment--><pre><code><font color="#000080"><i>' PIC16F630 Fuses
    </i></font><font color="#008000">@ DEVICE BOD_OFF
    @ DEVICE CPD_OFF
    @ DEVICE PROTECT_OFF
    @ DEVICE MCLR_OFF
    @ DEVICE PWRT_OFF
    @ DEVICE WDT_OFF
    @ DEVICE INTRC_OSC_NOCLKOUT
    
    </font><font color="#000080"><i>'-------------------------------------------------------------------------------
    ' Registers   76543210
    </i></font>WPUA       = %00110000 <font color="#000080"><i>'Weak Pull-up of PORTA for SCL and SDA on DS1307
    </i></font>INTCON     = %00000000 <font color="#000080"><i>'Interrupts
    </i></font>OSCCAL     = %01100000 <font color="#000080"><i>'Oscillator Calibration when Internal RC set to 4MHz
    </i></font>OPTION_REG = %10000000 <font color="#000080"><i>'PORTA Pull-Ups/TMR0/Prescaler
    </i></font>CMCON      = %00000111 <font color="#000080"><i>'Comparator Module is OFF
    </i></font>TRISA      = %00000000 <font color="#000080"><i>'Set Input/Output
    </i></font>PORTA      = %00000000 <font color="#000080"><i>'Ports High/Low
    </i></font>TRISC      = %00000000 <font color="#000080"><i>'Set Input/Output
    </i></font>PORTC      = %00000000 <font color="#000080"><i>'Ports High/Low
    
    '-------------------------------------------------------------------------------
    'PORTA.0 = ICSP Data
    'PORTA.1 = ICSP Clock
    'PORTA.2
    'PORTA.3 = MCLR
    'PORTA.4 = SDA
    'PORTA.5 = SCL
    'PORTC.0 = LCD-DB4
    'PORTC.1 = LCD-DB5
    'PORTC.2 = LCD-DB6
    'PORTC.3 = LCD-DB7
    'PORTC.4 = LCD-E
    'PORTC.5 = LCD-RS
    
    '-------------------------------------------------------------------------------
    ' LCD cabling
    '-       ( 1) Vss - GND
    '-	 ( 2) Vdd / Vcc +5V
    '-	 ( 3) Vee / Vo / Contrast adjust / Pot 4k7(1-2-W3) or R2k2 (GND-3)
    'PORTC.5 ( 4) RS
    '-	 ( 5) R/W -&gt; to Vss
    'PORTC.4 ( 6) E
    'PORTC.0 (11) DB4
    'PORTC.1 (12) DB5
    'PORTC.2 (13) DB6
    'PORTC.3 (14) DB7
    
    </i></font><b>DEFINE </b>LCD_DREG PORTC   <font color="#000080"><i>'LCD data port 
    </i></font><b>DEFINE </b>LCD_DBIT 0       <font color="#000080"><i>'LCD data starting PORT.bit (0 or 4)
    </i></font><b>DEFINE </b>LCD_RSREG PORTC  <font color="#000080"><i>'LCD register select port 
    </i></font><b>DEFINE </b>LCD_RSBIT 5      <font color="#000080"><i>'LCD register select bit 
    </i></font><b>DEFINE </b>LCD_EREG PORTC   <font color="#000080"><i>'LCD enable port 
    </i></font><b>DEFINE </b>LCD_EBIT 4       <font color="#000080"><i>'LCD enable bit 
    
    '-------------------------------------------------------------------------------
    ' Variables
    </i></font>SDA      <b>VAR </b>PORTA.4 <font color="#000080"><i>'DS1307 SDA pin #5
    </i></font>SCL      <b>VAR </b>PORTA.5 <font color="#000080"><i>'DS1307 SCL pin #6
    'SDOut    var PORTC.2
    </i></font>DB       <b>VAR BYTE</b>[8] <font color="#000080"><i>'Data byte array
    </i></font>RTCSec   <b>VAR </b>DB[0]   <font color="#000080"><i>'alias individual bytes in array
    </i></font>RTCMin   <b>VAR </b>DB[1]
    RTCHour  <b>VAR </b>DB[2]
    RTCDay   <b>VAR </b>DB[3]
    RTCDate  <b>VAR </b>DB[4]
    RTCMonth <b>VAR </b>DB[5]
    RTCYear  <b>VAR </b>DB[6]
    RTCCtrl  <b>VAR </b>DB[7]
    AMPM     <b>VAR BIT
    </b>A_Ctr    <b>VAR BYTE    </b><font color="#000080"><i>'counter
    </i></font>B_Ctr    <b>VAR BYTE    </b><font color="#000080"><i>'counter
    </i></font>Day_T    <b>VAR BYTE
    </b>Day      <b>VAR BYTE</b>[3]
    Day[0] = 0
    Day[1] = 0
    Day[2] = 0
    
    <font color="#000080"><i>'-------------------------------------------------------------------------------
    </i></font><b>PAUSE </b>1000        <font color="#000080"><i>'time for LCD to settle
    </i></font><b>LCDOUT </b>$FE, 1     <font color="#000080"><i>'Clear LCD
    </i></font><b>GOSUB </b>WRITE_1307  <font color="#000080"><i>'set the time or don't
    
    </i></font>MAIN:
       <b>GOSUB </b>READ_1307 <font color="#000080"><i>'Read the time &amp; date
       </i></font><b>GOSUB </b>LCD
       <b>PAUSE </b>1000
    <b>GOTO </b>MAIN:
    
    <font color="#000080"><i>'-------------------------------------------------------------------------------
    </i></font>LCD:
    
    <font color="#000080"><i>'Hour in &quot;hh:mm:ss&quot;
    </i></font><b>LCDOUT </b>$FE, 2, <b>DEC </b>(RTCHour&gt;&gt;4 &amp; $0F), <b>DEC</b>(RTCHour &amp; $0F),<font color="#FF0000">&quot;:&quot;</font>, _
                   <b>DEC</b>((RTCMin&gt;&gt;4)&amp; $0F), <b>DEC</b>(RTCMin &amp; $0F),<font color="#FF0000">&quot;:&quot;</font>, _
                   <b>DEC</b>((RTCSec&gt;&gt;4)&amp; $0F), <b>DEC</b>(RTCSec &amp; $0F)
    <font color="#000080"><i>'Day
    </i></font>B_Ctr = 0
    <b>FOR </b>A_Ctr = (((RTCDay &amp; $07)-1)*3) <b>TO </b>(((RTCDay &amp; $07)-1)*3)+2
      <b>LOOKUP </b>A_Ctr,[<font color="#FF0000">&quot;SunMonTueWedThuFriSat&quot;</font>],Day_T
      Day[B_Ctr] = Day_T
      B_Ctr = B_Ctr + 1
    <b>NEXT </b>A_Ctr
    <b>LCDOUT </b>$FE, 2, $FE, $C0, Day[0], Day[1], Day[2]
    
    <font color="#000080"><i>'Date in &quot;mm-dd-yyyy&quot;
    </i></font><b>LCDOUT </b>$FE, $C4, <b>DEC</b>((RTCDate&gt;&gt;4)&amp; $03), <b>DEC</b>(RTCDate &amp; $0F),<font color="#FF0000">&quot;-&quot;</font>, _
                     <b>DEC</b>((RTCMonth&gt;&gt;4)&amp; $01), <b>DEC</b>(RTCMonth &amp; $0F),<font color="#FF0000">&quot;-&quot;</font>, _
                     <b>DEC</b>(((RTCYear&gt;&gt;4)&amp; $0F)*100),<b>DEC</b>(RTCYear &amp; $0F)
    
    <b>RETURN    
        
    </b><font color="#000080"><i>'-------------------------------------------------------------------------------    
    </i></font>READ_1307:
    <font color="#000080"><i>' Read order is in Secs,Mins,Hours,Day,Date,Month,Year,Control
    </i></font><b>I2CREAD </b>SDA,SCL,$D0,$00,[<b>STR </b>DB\8] <font color="#000080"><i>' Read string of 8 bytes from DS1307
    </i></font><b>RETURN
    
    </b><font color="#000080"><i>'-------------------------------------------------------------------------------
    </i></font>WRITE_1307:
    <font color="#000080"><i>'Set time &amp; date to 23:59:55, Day 2, Date:Month:Year 27:08:2009
    </i></font><b>I2CWRITE </b>SDA,SCL,$D0,$00,[$55,$59,$23,$02,$27,$08,$29,$90] <font color="#000080"><i>' Write to DS1307
    
    </i></font><b>RETURN                  </b><font color="#000080"><i>' Sec Min Hr  Day D   M   Y   Control
    
    </i></font><b>END
    </b></code></pre><!--EndFragment--></body>
    </html>
    Roger

  9. #9
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Many output a square wave from (1Hz to 32kHz for the M41T81). You can monitor it. At 1Hz, a rising edge comes once per second.

  10. #10
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    Good product, unfortunatly sold only in 8-pin SOIC package.
    What package would you prefer?

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The DS1307 is good +/- a few minutes every year.

    A CR2032 Battery lasts many years. We've been shipping these for about seven years and haven't needed to change a Battery yet.

    Use I2CREAD and I2CWRITE... example...

    I2CWrite SDA,SCL,I2CAddress,DataB,[DataA]

    where...

    I2CAddress=$D0 (the BYTE value address for the device)

    DataB is the BYTE value address representing the Register you are writing (usually in the range $00-$07 - see DS1307 Datasheet for what each register contains)

    and DataA is the BYTE value that you are putting into the Register.

    4K7 pull-up's on SCL and SDA required... a lower value may be required if you have multiple devices on the Bus.

    You I2CREAD any time you feel like it... once a second, ten times a second... how ever often you feel like it. Note that you can program the DS1307 to output a pulse every second... you can use that to synchronise your PIC to read and display, or display on interrupt...

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think the DS1337's alarm can be set for one second. Probably doing the same thing as Dave mentioned with his.
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Voilà

    Okay.

    So I modified the code as this:
    Code:
    <html><head></head><body><!--StartFragment--><pre><code><font color="#000080"><i>' PIC16F630 Fuses
    </i></font><font color="#008000">@ DEVICE WDT_ON
    
    </font><font color="#000080"><i>'-------------------------------------------------------------------------------
    ' Registers   76543210
    </i></font>WPUA       = %00110100 <font color="#000080"><i>'Weak Pull-up of PORTA for SCL and SDA on DS1307
    </i></font>TRISA      = %00000100 <font color="#000080"><i>'Set Input/Output
    
    '-------------------------------------------------------------------------------
    ' Variables
    </i></font>DSOut    <b>VAR </b>PORTA.2 <font color="#000080"><i>'DS1307 SQW pin #7
    
    '-------------------------------------------------------------------------------
    </i></font>MAIN:
    <b>IF </b>DSOut = 0 <b>THEN
       GOSUB </b>Read_1307  <font color="#000080"><i>'Read the time &amp; date
       </i></font><b>GOSUB </b>lcd
       <font color="#000080"><i>'put PIC in low-power mode for 576+288+72=936ms
       </i></font><b>NAP </b>5
       <b>NAP </b>4
       <b>NAP </b>2
    <b>ENDIF
    GOTO </b>MAIN:
    <b>END
    </b></code></pre><!--EndFragment--></body>
    </html>
    Maybe it doesn't make a lot of sense to put the PIC in low-power mode. How is it done in the "industrial" life?
    Roger

  14. #14
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Also, you can now get PIC's with a built-in RTCC.

Similar Threads

  1. Camera with PIC chip
    By The Master in forum Off Topic
    Replies: 5
    Last Post: - 1st July 2008, 14:28
  2. PIC chip resetting. Very weird
    By The Master in forum Off Topic
    Replies: 0
    Last Post: - 28th October 2007, 17:07
  3. Help on coding/ selecting PIC chip for project
    By lovemeok in forum General
    Replies: 0
    Last Post: - 27th July 2006, 19:21
  4. Best PIC chip..?..
    By Delusional in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th February 2006, 03:17
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts