PDA

View Full Version : Power line timebase



Michael
- 4th March 2007, 16:27
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?

mister_e
- 4th March 2007, 17:16
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?

Michael
- 4th March 2007, 19:59
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.

Michael
- 4th March 2007, 20:01
Just a matter of getting the 60hz sine wave squared up?

mister_e
- 4th March 2007, 20:08
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?

Michael
- 5th March 2007, 12:00
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.

Ingvar
- 5th March 2007, 16:09
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.

mister_e
- 5th March 2007, 22:46
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.

sougata
- 6th March 2007, 05:44
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.

Ingvar
- 6th March 2007, 12:17
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.

Acetronics2
- 6th March 2007, 12:58
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

Michael
- 6th March 2007, 13:52
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

Michael
- 6th March 2007, 13:54
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).

skimask
- 6th March 2007, 13:55
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...

Ingvar
- 6th March 2007, 16:13
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/DS32kHz-DS32KHZS.pdf
...... not cheap but it solves most timekeeping problems.