60Hz timebase clock


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Posts
    41

    Default 60Hz timebase clock

    Hello all, I am in the planning stages for a simple clock that uses numitron tubes for the display. That part is pretty much worked out. I decided against using a realtime clock chip as they do need an initial date setting and battery backup. My idea is to base it from the 60Hz power. For isolation and protection against spikes I plan to drive the LED side of an optic isolator using a small step down transformer. That should give nice clean 60Hz pulses on the output side. So far so good.

    Now for the timekeeping part. How about preloading an 8 bit counter with 195 so it will overflow on the 60th pulse? Then the interrupt goes to the timekeeping code where each overflow is counted as a second. The time between these periods should be plenty for the necessary math and writing to the display.

    Any comments appreciated.


    Adam

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 60Hz timebase clock

    If you have a logic probe like this one:
    http://www.saleae.com/logic
    then it simplifies testing radically.

    You get to measure hertzes down to 4 decimal places, as well as view several communication protocols like I2C, SPI, 1-wire, CAN, etc. I used it to get LEDs blinking at 120Hz and I have to say it works great (wish I could afford to upgrade to Logic 16).

    About the preloading, that's what I did using Darrel's template. Details here:
    http://www.darreltaylor.com/DT_INTS-...rTemplate.html

    The only limitation I found with the template is the 16 MHz cap, other than that it was easy to set up. It's too bad 'cause I was running the 18F44K22 at 64MHz until now. I wished I knew enough about interrupts to go without the template, but hey, it's the price I have to pay to be me.

    Robert
    Last edited by Demon; - 10th January 2014 at 23:29.

  3. #3
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: 60Hz timebase clock

    I don't have to measure the accuracy of my timebase, just count 60 pulses to give one second ticks. The power company makes small frequency adjustments over a 24 hour time so it always averages to 60Hz. Some quick testing with a transformer and a 4N25 optic isolator gave me a decent 60Hz square wave output. Not a 50% duty cycle but more like 60% on 40% off. Setting TMR0 to 195 and then having an interrupt when it rolls over looks like it will work.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 60Hz timebase clock

    Quote Originally Posted by astouffer View Post
    ... The power company makes small frequency adjustments over a 24 hour time so it always averages to 60Hz...
    I didn't know they bothered.


    If you're only interested in triggering an event every 60 Hz, have you looked at Darrel's interrupt I posted above? You can control the exact hertz you want a trigger without external parts. If you're not going faster than 16 MHz it's perfect for you.

    Robert

  5. #5
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: 60Hz timebase clock

    Well, since you promised to appreciate any comments...

    I'd use an RTC anyway. Some of the DS series are cheap, do not require a backup battery (actually, even those that make the option available need not have it to run) and provide a 1 Hz output without setting the time explicitly. Not sure why you wouldn't want to have a battery backed up time at your disposal, but if you don't... [shrug] ... you don't have to use it.

    There's also a good article here somewhere about making a very accurate 1 second timer with no other time base than an external crystal... that would be my second choice.

    On the other hand, Robert's suggestions are valid - as are your own.
    Last edited by Amoque; - 13th January 2014 at 01:38. Reason: Found link.

  6. #6
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: 60Hz timebase clock

    Amoque: Using the 60Hz power for a source will give me more accuracy than an RTC chip and be cheaper. I actually built a large clock based on the link you posted. It worked great but requires long term tweaking for accuracy. Even a 20ppm crystal it still gained a minute or two every month. Here is me testing one of the digits

    This code runs on a 16F684 and blinks an LED on pin 10 at 1Hz when fed a 60Hz input on pin 11. Of course the final version will be doing much more than blinking an led. I plan to use four IV-9 numitron tubes for the digits. http://hackadaycom.files.wordpress.c...2/numitron.jpg

    Code:
    @	__CONFIG _FOSC_INTOSCIO & _WDTE_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF
    
    
    OSCCON = %01110101			'Internal OSC 8MHz
    DEFINE OSC 8				'8MHz
    PORTA = 0					'All low
    TRISA = %00000100			'Porta.2 input
    ANSEL = 0					'No analog
    WPUA = 0					'Weak pull up off
    CMCON0 = %00000111			'Comparators off and I/O is digital
    ADCON0 = 0					'A/D is off
    CCP1CON = 0					'PWM and CCP off
    OPTION_REG = %11111000		'Timer0 on
    TMR0 = 195					'Preload so it rolls over on the 60th pulse
    INTCON = %11100000			'INTCON.2 overflow bit
    
    on interrupt goto blink
    
    main:
    	@ NOP
    	goto main
    
    disable
    
    blink:
    toggle portc.0
    TMR0=195
    INTCON.2 = 0
    resume
    enable
    
    end
    Almost forgot the basic schematic. Use a scope to see what resistor values give you the best output. My meter read 3mA going into a 4N25 optic isolator. http://i.imgur.com/fHWGJHr.jpg
    Last edited by astouffer; - 15th January 2014 at 03:22.

Similar Threads

  1. Replies: 14
    Last Post: - 8th March 2012, 02:04
  2. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 17:44
  3. Clock
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st February 2008, 02:23
  4. Power line timebase
    By Michael in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 6th March 2007, 16:13
  5. Xin & Xout Europe (50hz) vs US (60hz)
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd May 2005, 11:49

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