Real time clock ICs


Closed Thread
Results 1 to 40 of 67

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hello Eng444,

    What's the problem? This forum has many examples of using RTC's including one back in Oct 2004 by Tonigalea that uses a DS1337. Paul Borgmier (sp? sorry) put 2 really nice RTC programs on this site last year that don't even use a separate RTC chip. I have tried them and they work very nice. They even have an alarm time example in them. I am on my 3rd project now using the DS1337 RTC. I use this as my projects need to keep accurate timing with a battery backup. I have even done routines to handle daylight savings time. I have used this RTC with a 16F88, 16F877A, and a 18F452. They are easy to work with but with everything else in life there is a learning curve. I found it very worth the time I invested.

    There are also several examples of elapsed time counters here on this site from Darrel Tayor. Melanie has given us the Olympic Timer based on the 1302 RTC. She also has a clock program posted on the MELabs website.

    Your post did not say specifically what your problem is. Some RTC's require converting data from the RTC from BCD to decimal. Paul Borgmier's clocks don't use this conversion. Tonigalea's DS1337 program doesn't use it.

    Read through the posts here on this site and try a few things. Let us know more about the problem so we can help you! The people here are great and willing to help!

    BobK.

  2. #2
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Exclamation Thank you BobK

    I am working on a certain project and do not have any knowledge in RTC, nor how to program them. In fact, i just learned PicBasic Pro...

    I have Pic16F876A and i am trying to manage to make my DS1307 work.

    I Have read all the examples but as i am new to this thing, i didn't understand them...

    i do not need alarms...etc etc i do not need it sophisticated at all. i am to calculate Energie which is given by: Energy = Power * time.

    i already got power in a certain variable and now, i need to get the time elapsed in order to multiply by power...

    any help?

  3. #3
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Eng 4444,

    If you aren't looking for a "time stamp" of time and date then what you should try is Darrel Taylor's "Elapsed Timer" program on this site. Your program can control when to start timing and when to stop timing. Melanie's "Olympic Timer" is another example of a start and stop timer. You should look at these two programs. Both of them output the result to an LCD display. Both of these programs use a background timer using the PIC's timers. You can have your PIC do the calculations based on the inputs and then display the results.

    The May 2006 issue of Nuts and Volts magazine has a nice tutorial on using PIC timers including a sample program that should help you out understanding how these timers are used. I believe this forum also has numerous posts relating to using PIC timers. I personally am just starting to use them so I wouldn't be much help in the actual design of one at this point. I just have a basic understanding of how they work.

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


    Did you find this post helpful? Yes | No

    Lightbulb

    Also as BobK pointed in right direction, have the followings into consideration.

    If you use RTC to calculate the elapsed time, you will have difficulties when time passes from one minute to other, or from one hour to other. You will be lost in HEX conversions to come with elapsed time.

    I highly recommend using Melanie’s Olympic timer. It is already a timer just as you need, it is not an RTC.

    It is quite easy to implement it into your PIC; even if you can’t use it with your PIC, have your energy calculation in your PIC by getting a signal from a separate PIC in which the Olympic timer is implemented.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by BobK
    Hi Eng 4444,

    should try is Darrel Taylor's "Elapsed Timer" program on this site. Your program can control when to start timing and when to stop timing. Melanie's "Olympic Timer" is another example of a start and stop timer. You should look at these two programs.
    __________________________________________________ ______________

    Sorry but where to find those 2 programs on this website? in which section?

  6. #6
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Eng4444,

    From this forum's main menu select CODE EXAMPLES. There you will find the following items:

    1) Olympic Timer
    2) Easy & Accurate Clocks without RTC ICs
    3) Elapsed Timer Demo

    Of the three, #2 is the only one that I personally have tried. But you should look at all three programs and decide which one you want to use. They are all easy to understand.

    BobK

  7. #7
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Just checking

    Hi,

    If you dont use a backup battery for the 1307 make sure that the un-used leg for the backup function is tied to ground. You can find this in the datasheet but if this is not done the chip will not work properly (sometimes it doesn't, other times it does but never when you want it to).

    We are using the 1307 and it is doing fine.


    TRIS? = %00000000 ' all pins to output just replace ? with port name

    SDA var Port?.? 'define port for I2C communication replace ?.? with pin
    SCL var Port?.?

    Hours var Byte
    Minutes var Byte
    Seconds var Byte
    RTC var Byte
    I2C_Adr_B var byte


    RTC = % 11010000 ' Device adress on I2C bus
    I2C_Adr_B=0

    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

    Start_RTC:
    I2C_Adr_B=0
    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
    return

    RTC_Read:
    I2C_Adr_B=0
    I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code
    return

    call each part with a GOSUB

    Good luck and enjoy
    Last edited by Jumper; - 1st June 2006 at 16:16.

  8. #8
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Thumbs up You are an excellent person!:-)

    Quote Originally Posted by Jumper
    Hi,

    If you dont use a backup battery for the 1307 make sure that the un-used leg for the backup function is tied to ground. You can find this in the datasheet but if this is not done the chip will not work properly (sometimes it doesn't, other times it does but never when you want it to).

    We are using the 1307 and it is doing fine.


    TRIS? = %00000000 ' all pins to output just replace ? with port name

    SDA var Port?.? 'define port for I2C communication replace ?.? with pin
    SCL var Port?.?

    Hours var Byte
    Minutes var Byte
    Seconds var Byte
    RTC var Byte
    I2C_Adr_B var byte


    RTC = % 11010000 ' Device adress on I2C bus
    I2C_Adr_B=0

    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

    Start_RTC:
    I2C_Adr_B=0
    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
    return

    RTC_Read:
    I2C_Adr_B=0
    I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code
    return

    call each part with a GOSUB

    Good luck and enjoy
    __________________________________________________ _____________

    i wouldl ike to thank you so much! but now i returned home and far from my Lab. I will try it tomorrow. is it suitable for PIC16F876A? and by the way, how to set the date and time to: "10:15:30 01-06-2006 "? can you tell me how and in which part of your program?

    thank you again....

  9. #9
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Eng4444,

    The simplest way is to set those values as the variables for hours, minutes, seconds, month, date, year and then write them into the RTC. Obviously the minutes setting should be a few minutes ahead of the actual start time to allow you time to program the PIC and then put it into your board and start the board up. That's what I do to start the clock on my boards.

    BobK

  10. #10
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default some more checking

    Hi,

    Just to be really sure. Don't forget to put pullup resistors 4k7 between [SDA --> 5V] and [SCL --> 5V].

    Another thing we have seen is that adding "DEFINE I2C_SCLOUT 1" (this makes the SCL line bipolar) can help if there is a lot of noice in your set up. This is not the solution for a bad design just a way to try to get the best possible chance to communicate with the 1307.

    I am sure that as soon as you get the chip to respond your learning curve will go thru the roof.

  11. #11
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Lightbulb Thanks again:-)

    I'll try all of this in 4 hours... i really hope it will work!!

  12. #12
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Arrow Assistance please..

    Quote Originally Posted by Jumper
    call each part with a GOSUB

    Good luck and enjoy
    ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++

    What do you mean by this?

    could anyone explain to me?

    of course i need it to show constantly the time and keep on incrementing seconds, minutes, hours, days...

    so what is this GOSUB? and how to use it?
    One more things, what to do if i want to set time and date as:
    02:10:00 3-6-2006?

    where to write them?in which sentence?

    urgent help is needed because i am working right now on this...

  13. #13
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi ENG4444,

    What Jumper is referring to with the GOSUB is that the routines "Start_RTC" and "RTC_Read" are called from your main program. Read the PBP manual referring to the word "GOSUB" for a further explanation.

    The clock setting portion is, as I stated in an earlier reply, is handled in the setup of the clock. You put these values in the variables for the clock, meaning "seconds", "minutes", "hours", etc then write them into the RTC.

    It really sounds to me that you are in such a panic to get this project done by 9am Monday morning that you can't slow down and pay attention to what we are trying to say to you. You have posted on several sections of this forum with different requests. One request is for an RTC for a clock. Another post says you need elapsed time. Several of us have provided you with the information you requested. So now what do you want? We are here to help you but from your ongoing statements you aren't learning anything or really don't understand what is being given to you.

    Sit back and put your feet up in the air and relax for a few minutes. Re-look at the information we have provided. Try a few of the example programs that have been provided to you and see what they may or may not do for you.

    Maybe you should post some of the code you have so far and give us a schematic to look at. I can feel the panic in your requests. We want to help but can only go so far here!

    BobK

    The example programs are documented as to what each portion of the program is doing. Look at them and they will show you where to enter the values for setting the clock.

  14. #14
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Default you guessed right..i'm so squeezed by time..

    Quote Originally Posted by BobK

    Maybe you should post some of the code you have so far and give us a schematic to look at. I can feel the panic in your requests. We want to help but can only go so far here!
    __________________________________________________ _______________

    To tell you the truth, i have right now 15 programs related to real time clock and elapsed time and i'm not able to use any of them...

    as i said before, i don't know anything about PicBasic Pro, nor PIC, nor RTC. I just got stuck with this situation and should make it pass.. i'm simply a biomedical engineer..

    so for example, i'll tell you what i did yesterdsay night. This is a program from Melanie (thanks Melanie for providint such important program) :

    http://www.melabs.com/resources/samp...ted/MN1307.txt

    i will not paste it here because it's too long...
    but she's using PIC16F628. For me, i didn't find it; i found 16F628A which must be similar.... right?

    i did the circuit as she was saying (bought 2 Lines LCD), connetions to PIC and for DS1307, there was a suspicious part in some lines she wrote:

    ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++
    " ' 10K Resistors required from PORTB.1 and PORTB.2 to Vdd
    ' PORTB.0 relies on weak pull-up's (for future use)
    '
    SQWpin var PORTB.0
    ' You don't actually need to wire this pin... but...
    ' If you're observant, you'll notice I've wired the DS1307's
    ' SQW to RB0. Rather than 'poll' and display the time/date
    ' as in this example code, you can have an interrupt
    ' on RB0 each second to do this. In fact if you look at
    ' my code for setting the DS1307 you'll see I've already
    ' programmed it for a 1 second 'Tick' for exactly this
    ' purpose...
    SCLpin var PORTB.1
    SDApin var PORTB.2
    '
    ' Setting Buttons
    ' ---------------
    ' Buttons are connected between PORTB.4, 5 & 6 down to Vss
    ' No Resistors required - we're using weak pull-up's
    '
    DecButton var PORTB.4 ' Press to Decrement Button
    SetButton var PORTB.5 ' Press to Set/memorise Button
    IncButton var PORTB.6 ' Press to Increment Button
    "

    ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++

    so i just "connected": SQWpin of DS to PORTB.0
    SCLpin to PORTB.1
    SDApin to PORTB.2
    and for ports B.4 ,B.5 and B.6, i have put "push buttons" to ground.
    and also i have put 10K resistors as she said.

    so i got the same unused ports that she mentioned and was happy because i felt that it will work!

    now the programming section came....

    i just copied and pasted the whole program on PicBasic Pro, compiled it, things were fine.

    Then, using the programmer (i'm using ICPROG), i put the PIC, chose 16F862A and programmed but it gave:
    "verify error at location 0000xH"

    so i retuend to the program and paid attention to some sentences Melanie wrote in the beginning:
    ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++
    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE pic16F628, PROTECT_OFF
    ' Program Code Protection
    ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
    i tried to add "A" near each "8" but didn't work... so i noticed that i am already doing these setting from ICPROG (by checking what i need) so i removed all this section and programmed without it. It worked.

    it was time to test..

    LCD is just giving black rectangles.. nothing else :-( :-( !!!!

    i don't know what to do... i downloaded all this program to PIC... we do not program DS1307 also? no program should be inserted inside it?

    i also used a crystal for it... 32.768 as i remember...

    so here it is, i explained one case...and i previously fell in many previous similar cases... no one here around me is ready to help so i just thought that maybe i can find help on the internet. This is why i am sending many posts.... i should finish this whole work by next friday... i'm working on the biomedical part and do not have too much time to sit, read manual, try exercises, build more circuits and test.... i can't lay my legs Bob! i'm working on this project 20 hours a day since 3 months! can you beleive it? so i "really" cannot sit and just be in the mood to learn PicBasic Pro and I2c and RTC.....

    in case someone would be able to help i'll be grateful..

  15. #15
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Exclamation By the way BobK,

    you said:

    "
    "What Jumper is referring to with the GOSUB is that the routines "Start_RTC" and "RTC_Read" are called from your main program. Read the PBP manual referring to the word "GOSUB" for a further explanation.

    The clock setting portion is, as I stated in an earlier reply, is handled in the setup of the clock. You put these values in the variables for the clock, meaning "seconds", "minutes", "hours", etc then write them into the RTC. "
    __________________________________________________ ______________

    So do you mean that i should write all the program:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    TRIS? = %00000000 ' all pins to output just replace ? with port name

    SDA var Port?.? 'define port for I2C communication replace ?.? with pin
    SCL var Port?.?

    Hours var Byte
    Minutes var Byte
    Seconds var Byte
    RTC var Byte
    I2C_Adr_B var byte


    RTC = % 11010000 ' Device adress on I2C bus
    I2C_Adr_B=0

    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

    Start_RTC:
    I2C_Adr_B=0
    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
    return

    RTC_Read:
    I2C_Adr_B=0
    I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    in the PIC16F876A directly and it works?

    let's say i want to chose port B and pin 22 which is RB1
    23 which is RB2
    so i write:
    TRISB = %00000000
    SDA var PortB.1
    SCL var PortB.2
    true?
    and i wire b.1 to sda of DS, B.2 to SCL DS.... right?



    Now tell me, if i just connect PIC16F876A to this DS1307 and a 4 lines LCD (or 2 lines). and let's say i just want to use this whole PIC just for the DS (it's stupidity i know but let's say i will keep all ports not used) would this program, as he gave it to me, be enough to begin displaying time and date on LCD? or i should write more things that he didn't write thinking that i should know them..... ?

  16. #16
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eng4444
    LCD is just giving black rectangles.. nothing else :-( :-( !!!!
    Have you adjusted the contrast correctly.

    At one extreme it will display nothing, at the other extreme it will display black rectangles. Somewhere inbetween it will display the characters correctly.
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 13:13
  2. Real Time Clock
    By in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd June 2012, 05:52
  3. real time clock - PCF8583
    By maria in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th April 2010, 16:41
  4. Real Time Clock
    By savnik in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th December 2006, 03:02
  5. Real time clock... what a headache!
    By Eng4444 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 8th June 2006, 22:56

Members who have read this thread : 2

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