Digital Hourmeter


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Digital Hourmeter

    Hi Gang,

    I have a little project that I'm fooling around with.
    I need to create a 99,000.0 hour hourmeter using six, 7 seg led displays. It needs to retain the counted time in eeprom when the power is off to restart from where it stopped.
    My thoughts are to use the 60hz from the mains, drop it and put it into the base of a transistor and pull high an i/p pin 60 times a second. I can then count that and when I get a total of 21600 counts, I can increment a counter by 1 and display it on the 7 seg's. (21600 = 60hz x 60 sec x 6min = 1/10th hour)

    Heres how I think it should flow....

    Power up
    read eeprom
    if eeprom = 0 set display to 0
    if eeprom any other value, start display at that value

    Start counter
    when counter = 21600 increment display by 1
    write display to eeprom.

    I'll be using a 16f88, multiplexing the segments and using just the 1 i/p to measure the pulses.

    Problem is, pulsein measures the pulsewidth and count measures a number of counts in a specified time, ie 1 second. I need to continually measure the pulses coming in and send an advance when we reach 21600 pulses. So how do I do that??

  2. #2
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    See PIC16F87/88 Data Sheet:
    TIMER1 MODULE /Timer1 Counter Operation

    Circuit to extract the 60Hz clock from the power line:
    http://www.maxim-ic.com/appnotes.cfm...te_number/1994

    Luciano

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    If I'm reading correctly what I'm seeing, tmr1 counts backwards?

    tmr1 starts at $FFFF (65535) and overflows at $0000 (0) So if I need to set a flag every 21600 pulses, I need to preload the counter, or start the counter, at $AB9F (43935) and count down to 0 from there?

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


    Did you find this post helpful? Yes | No

    Default

    No, the Timer Count UP from $0000 to $FFFF and then sets a flag (or interrupt) as it rolls from $FFFF (maximum count) and starts again from $0000.

    Have a look at this thread for presetting a 10mS example.

    http://www.picbasic.co.uk/forum/showthread.php?t=632

  5. #5
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    SetTimer:
    T1CON.0=0 ' Stop the Clock
    TMR1RunOn.Highbyte=TMR1H ' Load the Run-On (Over-Run) value (if any)
    TMR1RunOn.Lowbyte=TMR1L
    TMR1RunOn=TMR1Preset+TMR1RunOn ' Calculate the New (adjusted) value for TMR1
    If TMR1CalAR=0 then ' Calibration ADVANCE (add) or RETARD (subtract)
    TMR1RunOn=TMR1RunOn+TMR1Cal
    else
    TMR1RunOn=TMR1RunOn-TMR1Cal
    endif
    TMR1H=TMR1RunOn.Highbyte ' Save new values to TMR1
    TMR1L=TMR1RunOn.Lowbyte
    T1CON.0=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interupt Flag
    Return


    Ok, code killing aside.... forgive my noobness.

    If I strip out the calibration aspect as I dont think i need it. (1sec/60hz = 1 pulse every 16.667ms) should be enough time.....


    SetTimer:
    T1CON.0=0 ' Stop the Clock
    TMR1.Highbyte=TMR1H ' Load the high timer start point
    TMR1.Lowbyte=TMR1L ' Load the low timer start point
    TMR1.Highbyte= $AB ' Save new values to TMR1 (65535 - 21600 = 43935 = AB9F)
    TMR1.Lowbyte= $9F
    T1CON.0=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interupt Flag
    Return


    This should reset the timer everytime with 43935 as a starting point, leaving 21600 pulses until a rollover and the interupt flag is set, upon which the program needs to increment a counter by 1, store the result in eeprom and reset the counter to start again. Oh, and increment the display aswell ;-)
    Last edited by jmgelba; - 12th April 2005 at 21:08.

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


    Did you find this post helpful? Yes | No

    Default

    Hmmm... don't quite understand your figures...

    1/60=16667uS = $411B based on 1uS tick time (4MHz clock)

    $0000-$411B=$BEE5

    Use Microsofts Calculator in Scientific mode... you cant do 0-411B in hex directly, so instead do FFFF-411B and just add 1 to your answer.

    Setting the clock for a 16667uS count would be...

    T1CON.0=0 ' Stop the Clock
    TMR1H=$BE ' Set Timer Highbyte
    TMR1L=$E5 ' Set Timer Lowbyte
    T1CON.1=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interrupt Flag

    If you're returning from an Interrupt then use RESUME otherwise if it's from a subroutine use RETURN.

    You may have to adjust the $E5 value slightly to trim your time accurately to account for instruction cycle time in setting the clock etc.

Similar Threads

  1. Replies: 5
    Last Post: - 16th October 2009, 18:29
  2. Digital Out on an A/D pin safe ?
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st January 2009, 22:48
  3. analog and digital
    By lerameur in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2008, 02:40
  4. Replies: 4
    Last Post: - 24th January 2007, 22:20
  5. Digital IC Tester
    By precision in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th September 2006, 03:38

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