Power line timebase


Closed Thread
Results 1 to 15 of 15
  1. #1

    Default Power line timebase

    I thought I'd redo a pic stopwatch that I did and rather than crystal control, use the AC line frequency as a timebase. (It's not a portable stopwatch).

    I really would like some hints on what I can do.

    I keep thinking no matter what, I'm going to have to have an external chip to convert the 60hz to 1 hz (or whatever)....but do I?

    I really don't have much experience with what a PIC can do "in the background"...but it seems limited to it's own peripheral hardware (tmrs, usart, etc).

    Are there any creative ways that I could monitor the line frequency and yet still have the continuous program running doing all the math and led display functions etc. ?

    Like I say, I suppose a counter or 2 as an external timebase is probably where I will end up? (There was a chip CD4566 that was a 60hz to 1 hz timebase but no longer available).

    Any ideas?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yes it's possible and you can skip the additional external hardware. Just feed the 60Hz to a interruptible pin, a Timer CLK input or whatever else will do the trick

    What do you want to do exactly?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Ok, sure...I've never used the internal timer before and yes the clock input would be the way to go...it would always increment that internal timer and then
    I could look for a 1 second flag.

    The T0CK input, right?

    Right in front of me, yet like I said, have never used the timers before....forgot about that input pin.

    I suppose you choose that pin in a register and the default is that it's incremented by the PIC crystal.

    Great ! Thanks.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Just a matter of getting the 60hz sine wave squared up?

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you don't need to bother to much about that, use a simple resistor in serie (as current limiting) and look what's happen to the wave? Yeah, the PIC internal diode clamp it, most of the time, it's fair enough.

    I have to go, but i may do something to help you to start. Which PIC do you plan to use?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    I have some antique 16c65B's.

    Thanks Mr E, you put me on the right path...it'll be fun to learn about the timer modules and interrupts.

    Just though I'd take the 60hz off the secondary of my 6 volt transformer.

    My crystal based worked fine but I don't like the temperature variations.

  7. #7
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Cool

    Ahh, this brings back old memories. The first digital thingy i designed was a clock, driven from our 50Hz. It worked rather well ..... until the fridge started. Several minutes could flash by in a couple of seconds. I strongly suggest that you filter your 60Hz a little better than Steve suggests, if not you'll most likley see the same thing i did.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm good point, i'm wondering how big the glitch could be at the output of that transformer.

    And if you have few glitches a day... how much the accuracy will be when you divide it by 60 assuming you detect the rising edge...

    Worth to experiments few things here.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default I agree with MisterE

    Hi,

    As steve mentioned that glitches do get reduced at the secondary side. With simple filtering it should not be much of a problem. If using on an external interrupts a choice of rising/falling edge can be made. Dips or Spikes, can't avoid both. Why not test it out Michael ? After your DC rectifier (Bridge/CT) put an additional diode to the filter cap. Take your signal before the diode and feed it with a 10-20K to the PIC. Posssibily its a schmitt trigger input so don't worry about shaping the signal.
    Regards

    Sougata

  10. #10
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    If i were to do it again, i'd try a RCfilter and an OP(comparator) connected as a schmittrigger with as big hysteresis i possibly could get away with. Actually i'd choose a pic with comparators onboard. This was not an option for my old clock, pics weren't around back then. Ahhhhh, the good old times ..... NOT. Pics make life much easier, atleast when compared to using 74 and/or 4000 chips.

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink if there's room enough ...

    Hi,

    To get rid of all glitches and spikes ... the use of a radio clock ( here in Europe, it's DCF 77 ) signal could be good. small modules are so cheap nowadays ... say 2$ unit price !!!

    And that would correct automatically ... if mains failure !!!

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Yeah, I thought on the secondary side the noise level would be down quite a bit...plus just a simple 1N4003 in series with a good resistance 10k, 47k something like that. Some high freq filtering perhaps.

    I'll look at it on a scope and create some noise myself....grab my power drill or something.

    I think only something like a refrig would be a problem and it would depend on it's design as well.....and if it was on the same circuit.

    For you real software gurus, I suppose I could maybe even just look for the 1 second during a shorter window of time? (and ignore everything else)?

    ...Hmmm

  13. #13


    Did you find this post helpful? Yes | No

    Default

    That didn't make sense...getting carried away.

    It's the count that could get corrupt, so "when" I read it wouldn't make a difference.

    (I have to be careful with this brain of mine...it's a loose cannon).

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Michael View Post
    Yeah, I thought on the secondary side the noise level would be down quite a bit...plus just a simple 1N4003 in series with a good resistance 10k, 47k something like that. Some high freq filtering perhaps.

    I'll look at it on a scope and create some noise myself....grab my power drill or something.

    I think only something like a refrig would be a problem and it would depend on it's design as well.....and if it was on the same circuit.

    For you real software gurus, I suppose I could maybe even just look for the 1 second during a shorter window of time? (and ignore everything else)?

    ...Hmmm
    Why not combine old and new technologies for a solid timebase.

    Have a PIC triggered off the mains freq, and to keep it from false-triggering due to a fridge kicking in or something, have the PIC wait at least 16ms (at 60hz) before it'll even think about accepting a new trigger...or something along those lines...

  15. #15
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Default

    I suspect that the worst possible things would be old refridgerators and heaters(radiators) with mechanical thermostats. Loads of contactbounces. I remeber having problems with our fridge and it wasn't even on the same phase.

    Digital filtering like Skimask suggests would improve but never get rid of the problem completley. Your clock will always be "fast" unless you do this right.

    I also remeber that the mainsfrequency was considerably lower during daytime and higher at nighttime. The electrical producers compensated for the high load at daytime by increasing frequency at night. Over a 24 hour timeperiod there should be almost no error atall. Thought i'd mention it since you didn't like drift due to temperature.

    You also have the option of a temperaturecompensated oscillator, Dallas(now Maxim) makes many but this one should probably be good enough ..... http://datasheets.maxim-ic.com/en/ds...z-DS32KHZS.pdf
    ...... not cheap but it solves most timekeeping problems.

Similar Threads

  1. Replies: 3
    Last Post: - 29th April 2009, 00:45
  2. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22
  5. Power Line loging.
    By jcon777 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th July 2004, 15:08

Members who have read this thread : 1

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