Submitted by Michael Gold (not verified) on Fri, 08/07/2009 - 08:01.
It does help. Thanks!
My samples ( http://www.flickr.com/photos/41200830@N02/sets/72157621968166756/ ) are based on voltage divider where RA is 2.2K and RB is 2.2M. There is a fair amount of oscillation, which would explain the frequency changes, and would also explain the change in frequency with the addition/removal of devices-under-test.
In another project I used a low-pass filter to smooth the inbound data. (Accelerometer data from iPhone or Wiimote to control a R/C car) Would a low-pass filter be useful here?
Maybe the bigger question is this: Given the oscillation, is zero the ideal threshold by which to measure frequency?
I have found a few hardware approaches for frequency measurement. For example, I recently came across an implementation (http://www.phzmonitor.com/) that connects an AC to AC transformer adapter to an op amp. From the incoming sine wave, the op amp creates a square wave, and a PIC microcontroller then counts the number of clock cycles between the leading edges of the square wave.
I recently breadboarded something somewhat along those lines, AC to AC transformer to a diode (half wave rectifier) to a voltage divider, then to an analog pin on the Arduino. Using the comparator built into the Atmel chip on the Arduino, the sketch compares the sampled voltage to the Atmel's bandgap voltage, and measures frequency based on how long it takes in milliseconds between 120 transitions of the sampled voltage above/below the bandgap voltage (120 transitions for 60Hz). The sketch is based on this: http://news.jeelabs.org/2009/05/28/measuring-the-ac-line-frequency/ .
I get what seems to be decent results using this approach, but the results are different from the square-wave leading-edge approach used above (they have a live stream of grid frequencies which I used to compare results).
Not sure which of the two approaches is best, (or if neither are). In both of the cases, though, the oscillation seems to be factored out because of the comparison to a voltage reference.
By the way, the optoisolators work as advertised. In miswiring my voltage divider I just fried them (and not my microcontroller, or myself). Quite a spark indeed. Always a good reminder to treat mains electricity with care.
Re: delayMicroseconds in power logger sketch
It does help. Thanks!
My samples ( http://www.flickr.com/photos/41200830@N02/sets/72157621968166756/ ) are based on voltage divider where RA is 2.2K and RB is 2.2M. There is a fair amount of oscillation, which would explain the frequency changes, and would also explain the change in frequency with the addition/removal of devices-under-test.
In another project I used a low-pass filter to smooth the inbound data. (Accelerometer data from iPhone or Wiimote to control a R/C car) Would a low-pass filter be useful here?
Maybe the bigger question is this: Given the oscillation, is zero the ideal threshold by which to measure frequency?
I have found a few hardware approaches for frequency measurement. For example, I recently came across an implementation (http://www.phzmonitor.com/) that connects an AC to AC transformer adapter to an op amp. From the incoming sine wave, the op amp creates a square wave, and a PIC microcontroller then counts the number of clock cycles between the leading edges of the square wave.
I recently breadboarded something somewhat along those lines, AC to AC transformer to a diode (half wave rectifier) to a voltage divider, then to an analog pin on the Arduino. Using the comparator built into the Atmel chip on the Arduino, the sketch compares the sampled voltage to the Atmel's bandgap voltage, and measures frequency based on how long it takes in milliseconds between 120 transitions of the sampled voltage above/below the bandgap voltage (120 transitions for 60Hz). The sketch is based on this: http://news.jeelabs.org/2009/05/28/measuring-the-ac-line-frequency/ .
I get what seems to be decent results using this approach, but the results are different from the square-wave leading-edge approach used above (they have a live stream of grid frequencies which I used to compare results).
Not sure which of the two approaches is best, (or if neither are). In both of the cases, though, the oscillation seems to be factored out because of the comparison to a voltage reference.
By the way, the optoisolators work as advertised. In miswiring my voltage divider I just fried them (and not my microcontroller, or myself). Quite a spark indeed. Always a good reminder to treat mains electricity with care.
Now, to order more optoisolators...
Michael