-
• #2
It could be that the signal is very noisy... The odd values happen when Espruino is interrupted but the signal has changed so quickly that when it checks what the state is, it isn't what you'd expect.
Try adding
debounce: 1.
to the end of the setwatch statement. .. That should help... -
• #3
I've noticed this kind of behavior as well.
Look at your data more closely - you're getting spurious callbacks while it's false... But when the signal goes high (which consistently happens every 20ms, just like it should for a 50hz signal), it is consistently followed by a record with the signal going low about 1ms (ie, 0.9 and a margin of error) later.
Why not record the state of the last call, and discard any call that has the same state as the last one?
(Edit: Oops - meant to just make that a normal post, not "in reply to...")
-
• #4
Guys
Thanks... this isn't really a problem for my current signal processing problem - when the signal is off, I get zero events, so it's fine.
Gordon - I tried debounce:0, but that had no effect. I'll try debounce:1
Martin
-
• #5
yes -
debounce:0
is the same as leaving debounce off, so it wouldn't have an effect.It might be worth checking the signal with an oscilloscope - it might be that putting a very small capacitor across it would be enough to stop any glitches.
-
• #6
I already tried the capacitor, but my electronics isn't quite good enough - it didn't help. Anyway, I don't actually need to solve the problem - I was just documenting it for others
Thanks for the help.
Hi
I'm using setWatch on an input that has 50hz pulses which are ~0.9ms wide. I was expecting to see two callbacks alternating true/false per pulse, one for each edge - but I actually see multiple successive true or false values. This seems strange.
My code
'''
var states=new Array();
var index=0;
function onpulse(e)
{
states.push(e);
if (index<100) index++;
}
setWatch(onpulse,C5,{repeat:true,edge:'both',debounce:0});
'''
I'm storing the state change data in an array to try to be sure I'm catching
all the events - I thought that printing them might cause some to be lost.
The output I get looks like this
'''
What's puzzling me is that there doesn't seem to be any pattern - I was
expecting true,false, true, false...
Any ideas?
Martin