Using Pic as a digital clock/timer. How accurate?


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Los angeles
    Posts
    39

    Default Using Pic as a digital clock/timer. How accurate?

    Hello,
    I am trying to use the pic as a clock timer that displays the time hour and minutes but also i would like it to have a featured timer that the user can set. The timer will activate a motor.
    will the time be accurate enough?
    I am using the pic basic pro and the usb programmer.
    What's the easiest way to get this done? any suggestions is appreciated.
    Thanks

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Bottom line - It will only be as accurate as the oscillator used. The PIC is not the limiting factor.

    SteveB

  3. #3
    Join Date
    May 2006
    Location
    Kedah, Malaysia
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rocky79 View Post
    Hello,
    I am trying to use the pic as a clock timer that displays the time hour and minutes but also i would like it to have a featured timer that the user can set. The timer will activate a motor.
    will the time be accurate enough?
    I am using the pic basic pro and the usb programmer.
    What's the easiest way to get this done? any suggestions is appreciated.
    Thanks
    I give u example of simple timer and clock where user can set when they want to high certain port of the PIC. THere is only two buttons need to be used. First button to toggle from one menu to other menu. For example if we press this button then we can change from setting minute to the hour setting menu. Other button function is to set(increase) the value of second, minute, hour and etc. But how accurate this timer is depend on the oscillator u use as Steve B had said before. Attached herewith is the code: Please advise if you have some input on this code. Thanks.

    symbol second=2000
    symbol second2=1000

    second1 VAR BYTE
    minute VAR BYTE
    hour VAR BYTE
    day VAR BYTE
    time1 VAR BYTE
    time2 VAR BYTE

    second1=0
    minute=0
    hour=0
    day=0
    time1=0
    time2=0
    masa3=0


    hourset:
    Pause 200
    LCDOut $FE,1
    LCDOut "Set Hour"
    LCDOut $FE,$C0
    LCDOut "TIME:",DEC2 day,".",DEC2 hour,".",DEC2 minute,".",DEC2 second

    IF PORTB.5=1 Then GoSub addhour
    IF hour>23 Then hour=0
    IF PORTB.6=1 Then GoSub time1set
    GoTo hourset

    hour1set:
    Pause second2
    LCDOut $FE,1
    LCDOut "Set Time MotorOn1"
    LCDOut $FE,$C0
    LCDOut "Minute:",DEC2 time1

    IF PORTB.5=1 Then GoSub addtime1
    IF time1>59 Then time1=0
    IF PORTB.6=1 Then GoSub time2set
    GoTo time1set

    time2set:
    Pause second2
    LCDOut $FE,1
    LCDOut "Set Time MotorOn2"
    LCDOut $FE,$C0
    LCDOut "Day:",DEC2 time2

    IF PORTB.5=1 Then GoSub addtime2
    IF time4>99 Then time2=0
    IF PORTB.6=1 Then GoSub changeday
    GoTo time2set
    End

    addhour:
    IF PORTB.5=1 Then GoSub timer
    Return

    timer:
    second1=0
    minute=minute+1
    IF minute > 59 Then
    minute=0
    hour=hour+1
    IF hour >23 Then
    hour=0
    day=day+1
    IF day>30 Then
    dayi=0
    EndIF
    EndIF
    EndIF
    Pause 500
    Return

    addtime1
    IF PORTB.5=1 Then time1=time1+1
    Pause 500
    Return

    addtime2
    IF PORTB.5=1 Then time2=time2+1
    Pause 500
    Return

    changeday:
    IF PORTB.6=1 Then GoTo day


    day:
    Pause second
    saat=saat+1
    IF second1 >59 Then GoSub timer


    LCDOut $FE,2
    LCDOut "ON:",DEC2 time1,">",DEC2 time2,">"
    LCDOut $FE,$C0
    LCDOut "TIME:",DEC2 day,".",DEC2 hour,".",DEC2 minute,".",DEC2 second1


    IF (minute=time1 OR minute=time2) Then High PORTB.7
    IF (minute=time1+1 OR minute=time2+1) Then Low PORTB.7
    Goto day

  4. #4
    Join Date
    Aug 2005
    Location
    Los angeles
    Posts
    39


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks Fazan for the code but one thing i didn't understand is how do i get the actual seconds by simply counting? if you count from 1 to 60 does it mean its 1 to 60seconds? can you clarify how you convert from the simple execution time for the count to actual seconds.
    Thanks a lot

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Another Option - might help get you started
    http://www.picbasic.co.uk/forum/showthread.php?t=2129
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    May 2006
    Location
    Kedah, Malaysia
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rocky79 View Post
    Thanks Fazan for the code but one thing i didn't understand is how do i get the actual seconds by simply counting? if you count from 1 to 60 does it mean its 1 to 60seconds? can you clarify how you convert from the simple execution time for the count to actual seconds.
    Thanks a lot
    How accurate it is depend on the speed of oscillator that u use.

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


    Did you find this post helpful? Yes | No

    Default

    Also, the ambient temp is the most effective factor.

    You can get a slow running or fast running clock ticks depending on the temperature of the environment in which your PIC is running. (ambient temp)

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

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Have a happy new year, Rocky !!!

    Hi, Rocky

    I just built Thermo-baro-clock with a MS5534 sensor.( 16F876 ) the clock is driven by a 32.7... khz "clock crystal" connected to RC0,RC1 pins and using TMR1 ovf interrupt.

    The only way to adjust reading is to trim the TMR1 preset ( 32768 ...in theory ). an adjustable capacitor parallelled to one of the xtal load caps could also help a bit.

    Possible also to use two pushbuttons to inc/dec the TMR preset value, you then store in the EEPROM ... but do not forget to limit the trim range !!!

    But as always ... no simple automatic trimming.

    Absolute references will always be our main headaches ... cause there's none naturally existing !!!

    best regards
    Alain
    Last edited by Acetronics2; - 22nd January 2007 at 12:41.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Digital clock thermometer Calendar PIC 16F628
    By valdirdf in forum Code Examples
    Replies: 0
    Last Post: - 31st May 2009, 01:52
  2. PIC 18f4680 DIGITAL INPUTS
    By MegaADY in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2008, 07:34
  3. Digital Holter with PIC ?!
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th November 2007, 10:37
  4. Pic driven digital audio delay
    By skimask in forum Off Topic
    Replies: 12
    Last Post: - 19th April 2007, 20:42
  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