-
• #2
Not sure I understand - what lengths should it be reporting back? What if you attach it to something like a PWM output that you know the frequency of?
Also, is this the Espruino Board, or the Pico?
Just tried this on the Pico:
// short B3 and B4 var d = 0; analogWrite(B3,0.5,{freq:1000}); setWatch(function (e) {d=d*0.9+(e.time-e.lastTime)*0.1;}, "B4", { repeat:true, edge:'both' });
and
d
is0.00043812713
on one board and0.00047730952
on the other. I think it's because the board is using the internal RC oscillator, which is supposed to be 40kHz but seems to be pretty inaccurate on the F401 chips.In fact you can check, because if you warm the chip up that number changes drastically.
I think the only solution is to actually 'trim' the internal RC oscillator based on the external high speed crystal (which is relatively accurate) - I just haven't got around to adding the code for that yet.
-
• #3
It's the Pico.
It should be reporting back lengths of around 0.00055 and 0.0003. So it's off by ~50%, plus a ton of jitter...
Instead, well, look at the values it's reporting - all those numbers above the two parserx outputs (where it gets a packet that doesn't match what was sent) are bits! Consistently smaller, and the longest reported lengths for zeros are longer than the shortest reported lengths of the ones.
(bitstream should be 1FE10018 - the last nybble is the checksum, which the arduino receiver filters out)
00011111 11101000 00000000 00011000
On arduino based receiver, I count 0.12-0.40 ms as 0, 0.45-0.75 as 1.
I wonder if this is responsible for the problem that guy recently had with HC-SR04 reading consistently low?
-
• #4
Hmm... That is particularly far out - I wouldn't have thought the oscillator would be that bad!
You're doing
setWatch(... {repeat:true,edge:"falling"})
? I just wonder if it's reporting back the gap length, or something dumb.Depending on the signal, it could also be reporting differently because it'll be running with 3.3v logic levels, and Arduino with 5v ones.
Might be interesting to try the code I posted above though (or similar)? Just to get an idea of how far off the oscillator really is.
Right now, the times reported for things in events are... uh.... wrong.
On an Arduino, clocked off a crystal, I can constrain the 1 and 0 lengths like so:
The Arduino receiver happily takes the transmission and yields the correct result. With no interrupts or hardware timing more advanced than micros():
+1FE10001
Now, let's look at what lengths we get for those under Espruino:
Note how the numbers are all WAY LOWER than they should be. Those decoding results are after I lowered the threshold for 0 vs 1 down to 0.000295, in an attempt to get everything out of the 0 range, and widened the threshold for accepting, ie:
This is with analog squelching, by the way - it works splendidly. I can still receive without it - and it doesn't change the fact that the times are all over the place and consistently way under what they should be.