Searching \ for 'xtal for 1 second timebase interrupt' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.com/techref/microchip/ints.htm?key=interrupt
Search entire site for: 'xtal for 1 second timebase interrupt'.

Truncated match.
PICList Thread
'xtal for 1 second timebase interrupt'
1999\08\13@125323 by Harrison Cooper

flavicon
face
I have a 16C54 design that I just fed into an input port the secondary side
of a 6VAC transformer (yes, thru a resistor) so I can get either a 60 Hz or
50 Hz signal (depending on where in the world it is), and use the TMR0 and
prescaler to count the pulses to get a 1 second 'interupt', that is
basically a free running clock so I can generate delays and such.

I've found every now and then, noisy power will cause my counters to
misbehave, so rather than fight that, I'll just add a crystal.  Now, from my
calculations, if I use a 32.768KHz source, set the prescaler to 128, the
TMR0 will roll over every second.  So my delay loop, which counts seconds,
simply polls for TMR0 to overflow, then I reset it, and go one..

Do I have this right?

1999\08\13@161148 by Harold Hallikainen

picon face
On Fri, 13 Aug 1999 10:53:04 -0600 Harrison Cooper <spam_OUThcooperTakeThisOuTspamES.COM>
writes:
>I have a 16C54 design that I just fed into an input port the secondary
>side
>of a 6VAC transformer (yes, thru a resistor) so I can get either a 60
>Hz or
>50 Hz signal (depending on where in the world it is), and use the TMR0
>and
>prescaler to count the pulses to get a 1 second 'interupt', that is
>basically a free running clock so I can generate delays and such.
>
>I've found every now and then, noisy power will cause my counters to
>misbehave, so rather than fight that, I'll just add a crystal.

       I had a similar problem with a noisey power line.  A realtime
clock circuit (that generated DMX) would work great here in California,
but would run fast in New York.   After the equipment made a few trips
across the country, I added a capacitor to ground so the current limit
resistor and the capacitor formed a 60 Hz low pass filter.  The system
has now been working fine for a couple years.
       I also used this trick in another project, but then the client
wanted a univeral input power supply.  So we went with a switching power
supply module to get the universal input and used a timer interrupt and
counter to simulate the 60 Hz interrupt the code previously used
(decrementing a "jiffy" counter until a second has gone by).
       So...  I've had both ways (60 Hz and timer interrupt) work...

Harold


Harold



Harold Hallikainen
.....haroldKILLspamspam@spam@hallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm

___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.

1999\08\13@173820 by paulb

flavicon
face
Harrison Cooper wrote:

> I've found every now and then, noisy power will cause my counters to
> misbehave, so rather than fight that, I'll just add a crystal.

 My inclination would be to "fight it" in the spirit of making software
do what software can do.  You imply that you are using an R-C
oscillator.  This can most probably be made sufficiently accurate to
distinguish 50 Hz from 60 Hz, so it should be able to "auto-seek" the
line frequency.

 http://www.elmelectronics.com/Products/EBench/EBench.htm#ELM440 does
something like this using the 12C508 and its internal oscillator.

 I'd look at starting up a counter to determine an approximate second
and count transitions over this period.  If you have more than 55, it's
a 60 Hz system.  This of course could represent spurious counting on
noise but you should pre-condition the mains transitions with a 5 ms
software "debounce".  This is readily implemented with a(n approximate)
1 ms clock "tick" derived from TMR0 overflows (you have to make your
own overflow flag on teh 16C54, but that's not hard).

 5 successive same-state reads of the input and it's presumed to be
stable; this is the software version of the resistor-capacitor
suggested.

 Having guessed at which frequency to operate the Phase Lock Loop, this
is set up as a software counter (a resolution better than 1 ms may be
advisable here) and its rollovers divided by 50 or 60 as previously
determined to derive the 1 Hz output.  Debounced transitions from the
mains input are now compared to the loop count at which they occur with
five (perhaps) "windows"; "early", "very early", "very late" "late" and
"spot on".

 An error accumulator is incremented or decremented accordingly, by
one for a simple error and three for "very".  When it reaches a certain
threshold (e.g. 10) in either direction, the loop count is "bumped" in
the appropriate direction and the error count cleared.

 This much implements a *phase*-locked loop and would suit nicely for
an already accurate crystal oscillator-locked loop, but where the
oscillator is inaccurate to start, a second-order *frequency* lock can
be implemented by accumulating the phase corrections in a FIR algorithm
by which exceeding the dilution factor results in a correction of the
loop period (rather than the count).

 I venture to say this all codes cleaner than it sounds, and I haven't
tried it.  Mind you, if I had, I'd probably be *selling* it like ELM!

Harrison continued:

>  Now, from my calculations, if I use a 32.768KHz source, set the
> prescaler to 128, the TMR0 will roll over every second.  So my delay
> loop, which counts seconds, simply polls for TMR0 to overflow, then I
> reset it, and go one..

> Do I have this right?

 Sounds correct to me.
--
 Cheers,
       Paul B.

1999\08\13@180116 by Harrison Cooper

flavicon
face
Paul....on another subject....I haven;t forgotten your parts, if my &^%$ rep
would just get them to me!!

Basically, thats what I have done, in polling for a 50 or 60 Hz system.
What I am finding is there is noise in the powerline causing grief on the
count input.  I'm going to look at the suggestion of the low pass filter.
On the bench, the circuit works great, its just when installed with noisy
power, it fails at times.

All I need now is a DeviceNet interface on it... :-)


 My inclination would be to "fight it" in the spirit of making software
do what software can do.  You imply that you are using an R-C
oscillator.  This can most probably be made sufficiently accurate to
distinguish 50 Hz from 60 Hz, so it should be able to "auto-seek" the
line frequency.

1999\08\14@082911 by paulb

flavicon
face
Hello Harrison.

> Paul....on another subject....I haven't forgotten your parts, if my
> &^%$ rep would just get them to me!!

 Mmmm.  *I* had, but I'll see what comes.

> Basically, thats what I have done, in polling for a 50 or 60 Hz
> system.  What I am finding is there is noise in the powerline causing
> grief on the count input.  I'm going to look at the suggestion of the
> low pass filter.

 What about the *software* low-pass filter?  I think my overall
proposal would be the way to go, just that I can't _quite_ justify the
time to code it all "just now"!  However, if you give me a few details/
parameters of what you are doing, I could perhaps look into it.  Nature
of oscillator, what sort of output, what else it does, why not a 12C508,
etc...

> On the bench, the circuit works great, its just when installed with
> noisy power, it fails at times.

 Of course.

> All I need now is a DeviceNet interface on it... :-)

 1 Hz interrupts off the Net?
--
 Cheers,
       Paul B.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...