Hi,
I've hit a headscrather with my latest project. What I'm trying to do, is to measure the perioid of an AC voltage, to get the rotating speed of a windmill generator. The hardware for this is very simple, I just have an optocoupler connected with 2x 470k resistors in series and a reverse diode to the AC voltage. On the secondary side I have a 470k pullup resistor to +5V. The signal on the input pin looks nice, not square wave but should be good enough.
On the software I have an interrupt driver counting for the perioid. The timer is set for 512µS preload. I have 2 interrupts, one for low going edge and one for high going edge. The timer value is recorded and reset to 0 only on high going edge, so that the un-symmetrical triggering of the input should not matter.
I have this hardware plugged to 50Hz mains(with isolating transformer), but instead of the ~40 counts between high going edges i only get 31-32.
To add more to the confusion, I also tested the same thing with my MPPT controller hardware. It is essentially the same, but with lower value resistors connected to the optocoupler to make it work with my 12V rated wind turbine.
I hooked it up to the function generator, and sure enough, on small frequencies it seems to give values 20% too small. But between 60-80Hz something magical happens, and the error disappears. On 100Hz i get 19-20 counts, and on 150 i get 13-14, like I would expect. I also tried feeding the optocoupler with square wave to make for even better waveform, but it didn't do any good. I also tried removing the scratchpad averaging function, and inserted a pause between display updates, to make it readable. Same thing still.
The code snippet for the interrupt and timer setup;
Also, the full program code is attached below.
The picaxe in the "mains" version is 28x1 v6, and on the mppt hardware 40x1 v3.
Any help is appreciated.
I've hit a headscrather with my latest project. What I'm trying to do, is to measure the perioid of an AC voltage, to get the rotating speed of a windmill generator. The hardware for this is very simple, I just have an optocoupler connected with 2x 470k resistors in series and a reverse diode to the AC voltage. On the secondary side I have a 470k pullup resistor to +5V. The signal on the input pin looks nice, not square wave but should be good enough.
On the software I have an interrupt driver counting for the perioid. The timer is set for 512µS preload. I have 2 interrupts, one for low going edge and one for high going edge. The timer value is recorded and reset to 0 only on high going edge, so that the un-symmetrical triggering of the input should not matter.
I have this hardware plugged to 50Hz mains(with isolating transformer), but instead of the ~40 counts between high going edges i only get 31-32.
To add more to the confusion, I also tested the same thing with my MPPT controller hardware. It is essentially the same, but with lower value resistors connected to the optocoupler to make it work with my 12V rated wind turbine.
I hooked it up to the function generator, and sure enough, on small frequencies it seems to give values 20% too small. But between 60-80Hz something magical happens, and the error disappears. On 100Hz i get 19-20 counts, and on 150 i get 13-14, like I would expect. I also tried feeding the optocoupler with square wave to make for even better waveform, but it didn't do any good. I also tried removing the scratchpad averaging function, and inserted a pause between display updates, to make it readable. Same thing still.
The code snippet for the interrupt and timer setup;
Code:
#picaxe 28x1
SETFREQ EM16
INTFLAG = INTONRISE
SETINT INTFLAG,INTMASK 'set interrupt on pin 2 being high
SETTIMER 65504 'set timer with 512µs preload
.
.
.
main function is used in the test just to update the LCD display to show the perioid
.
.
.
INTERRUPT: 'interrupt is used for calculating the time between zero crossings
IF INTFLAG = INTONFALL THEN 'this routine causes every other interrupt just to set the int again and return
'triggered on the falling edge of the signal
INTFLAG = INTONRISE
SETINT INTFLAG,INTMASK 'set interrupt for raising edge again
RETURN
ENDIF
IF TIMER > 255 THEN
@PTR = 255
ELSE
@ptr = timer 'AVERAGE WITH SCRATCHPAD
ENDIF
TIMER = 0
ptr = ptr - 6
tempw2 = @ptrinc + @ptrinc + @ptrinc + @ptrinc + @ptrinc + @ptrinc + @ptrinc / 7
PERIOD = TEMPW2 MAX 255
INTFLAG = INTONFALL
SETINT INTFLAG,INTMASK 'ENABLE INTERRUPT AGAIN, THIS TIME ON LOW GOING EDGE
RETURN
The picaxe in the "mains" version is 28x1 v6, and on the mppt hardware 40x1 v3.
Any help is appreciated.
Attachments
-
8 KB Views: 7