how to determine the difference between 60 / 50 hz in C

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Can anyone explain how this is done? I have the ability to detect zero
crossing of the sine wave. Thanks...



Re: how to determine the difference between 60 / 50 hz in C
Quoted text here. Click to load it

Is this a troll?  You will have twice as many
zero crossings as the frequency.  If you have
a timer tick or some sort of clock, just count
the zero crossings over some time constant.




Re: how to determine the difference between 60 / 50 hz in C
Las said...

Quoted text here. Click to load it

Uh... count the zero crossings in a second and divide by two.  
Should get around 50 or 60, right?


Casey

Re: how to determine the difference between 60 / 50 hz in C
Quoted text here. Click to load it

  Kinda need to know what platform you're working on, or more
usefully, what kind of function calls for timing things are in
the C libraries you're working with.

  If you have POSIX around, just do "alarm(1)" and then go into
a while loop that counts zero crossings. The trigger to get
out of the while loop is a module variable that is set/cleared/however
you want to do it by the function that catches SIG_ALRM - which is
what will get called when the one second alarm() expires.

  Then count the zero crossings. If it's closer to 120, you
have 60Hz. If it's closer to 100, you have 50Hz.

  If you don't have alarm(), you can do a similiar thing just
by doing a while() loop with an internal call to a gettime()
or similiar function. Basically, you make note of the current time
just before entering the loop, then keep looking at the time
and counting zero crossings until it's a second later - however
"second" is defined for you particular version of gettime().


  Vague answer, I know, but you asked a vague question, so...


          -Ben
--
I am Ben Cantrick. I still think the AnimEigo BGC dubs suck.
To foil spammers, no e-mail adress will be given here. (Spammers also suck.)
We've slightly trimmed the long signature. Click to see the full one.
Re: how to determine the difference between 60 / 50 hz in C
Quoted text here. Click to load it
Sorry....I'm kinda new at this....The C library doesn't have a function for
timing that I can tell...What I do know is that the chip is a Z8...that's
right, not the newest version of zilog....I have a 12 MHz crystal; a
prescaler from 1 - 64 and a timer that can be set from 1 to 256 that calls
an interrupt when the value in the interrupt is reached. I have an interrupt
fired at both zero crossings.



Re: how to determine the difference between 60 / 50 hz in C

Quoted text here. Click to load it
Well I'm making a few assumptions about the way the timer works here-
never used the Z8. But if you set the timer to alternate values of 187
and 188 (less a bit for the btime it takes to get into the interrupt?)
you will get (on average) a 1ms interrupt rate. Zero a counter on the
first input edge, increment it in the 1ms interrupt, and latch the value
on the next input edge. You should get a value of 25 (or so) which can
be distinguished from a value of 30 (or so). The difference will be
bigger if you only use one direction of crossing, so a bit more reliable.

Or forget the pfaff of setting alternate values, choose one of them and
have a slightly off-millisecond interrupt rate, you will still get
recognisably different values but not so obviously related to 50/60Hz.

Paul Burke


Re: how to determine the difference between 60 / 50 hz in C
Quoted text here. Click to load it

Hi, can't help you in C but on the Z8 one way I would do it would be
have the timers set up to run a milisecond interrupt.  Put the AC
input signal into a port 3 pin that can trigger an interrupt.  Count
the milliseconds between interrupts. 50hz= 1/50= 20mS, 20/2= 10mS
between zero crossings.  60hz= 1/60= 16.6mS, 16.6/2= 8.3mS between
zero crossings.

Another way might be to set up your timers to run a milisecond
interrupt then scale that to 1 second resolution in software. Set the
ac signal to come into a port 3 interrupt and count the number of zero
crossings in 1 second.  This is similar to what Ben
( snipped-for-privacy@rhinokaosol.net) said.

Hope this helps.  If you want more information you might try
alt.microcontrollers.8bit or http://groups.yahoo.com/group/z8encore
which is a Z8 Encore group.

Bradley

Re: how to determine the difference between 60 / 50 hz in C

Quoted text here. Click to load it

The difference is 10 Hz.

--
========================================================================
          Michael Kesti            |  "And like, one and one don't make
We've slightly trimmed the long signature. Click to see the full one.
Re: how to determine the difference between 60 / 50 hz in C
Quoted text here. Click to load it


Thats a funny one!

Re: how to determine the difference between 60 / 50 hz in C
My problem was more elementary than I had first figured. The system crystal
runs at 12MHz divided down to 1.5MHz. From there the prescaler which is set
to 63 (a down counter) gives me a clock value of 42us. With this and a timer
set to 255, the timer will be deincremented each 42us to give me a value of
198 for 60Hz and 238 for 50Hz. The area I was having difficulty
understanding was the value of the clock. 12MHz = .0000000833333333 per
cycle; and this being divided down to the counter value of 42us. After the
light bulb went on, everything else was easier.....thanks everyone for your
help......



Site Timeline