[ELECTRON] Arduino project help.

Gordon JC Pearce gordonjcp at gjcp.net
Tue Jan 25 22:31:55 UTC 2011


On Tue, 2011-01-25 at 22:10 +0000, Andrew Back wrote:
> Hello,
> 
> So, I'm hoping that a seasoned Arduino expert might be able to offer advice
> in connection with a project that I'm working on and where I'm encountering
> a frustrating bug. Furthermore, where I'm not certain whether it's hardware
> or software related, although I suspect the latter.
> 
> It's essentially a mains frequency meter, mostly copied cargo cult fashion
> from:
> 
> http://jeelabs.org/2009/05/28/measuring-the-ac-line-frequency/#comments
> 
> The circuit I've built simply takes the mains and outputs half-wave
> rectified AC (top half of the sine wave) at 5v peak. For what the Arduino
> does with this see the above link. The schematic is at:
> 
> https://github.com/9600/timefortea/raw/master/Time_for_Tea_1_0.png
> 
> And my code, which is the pretty much the Jeelabs code with the addition of
> a PWM output to drive a moving coil meter:
> 
> https://github.com/9600/timefortea/blob/master/Time_for_Tea/Time_for_Tea.pde
> 
> Now, what I don't understand is why periodically I get a totally erroneous
> reading. The meter needle bounces across and then back at the subsequent
> reading. Sometimes these events are some time apart and sometimes the thing
> seems to get caught in a brief frenzy of them. I *think* there is always at
> least one correct reading after every bad one, so I could maybe say if delta
> greater than N then use last reading, or something. But this would be a bit
> of a fudge. 

The thing that switches the reading between positive and negative looks
a bit hairy.  Have you considered just using a single PWM output, and
making it "idle" at 127?

I'd also be slightly wary of counting microseconds like that; I'd be
more inclined to take a moving average of the last ten readings every
time the comparator interrupt fires.

Gordon MM0YEQ




More information about the members mailing list