// Short D11 + D12
analogWrite(D11, 0.0015, {freq:200});
//analogWrite(D11, 0.1, {freq:200}); // works fine even with low accuracy
n=0;
setWatch(() => n++, D12, {repeat:true,edge:"falling"});
setInterval(function() {
print(n);
n=0;
}, 1000);
In the Nordic chips, you can watch a pin either in a Low Power or a High Performance mode. In Espruino 2v09 I moved to using the Low Power mode as it uses substantially less power when the device is idle. What I didn't realise is that the Low Power mode isn't just less accurate, it just doesn't seem to be able to register any pulse that's faster than around 25us.
So, as a fix I just committed code that allows you to enable the high speed mode using hispeed:true for the watch:
This'll allow you to watch faster pin state changes on Nordic chipsets. However the pin 'state' may still be wrong - the pin state is still read in software (it's not reported by the hardware) when the IRQ is executed (which may not be immediately) so as a result a very small positive pulse may instead produce a state=false event because by the time the IRQ has read the pin state the signal has already gone back to 0.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok, so I managed to reproduce the issue with:
In the Nordic chips, you can watch a pin either in a Low Power or a High Performance mode. In Espruino 2v09 I moved to using the Low Power mode as it uses substantially less power when the device is idle. What I didn't realise is that the Low Power mode isn't just less accurate, it just doesn't seem to be able to register any pulse that's faster than around 25us.
So, as a fix I just committed code that allows you to enable the high speed mode using
hispeed:true
for the watch:This'll allow you to watch faster pin state changes on Nordic chipsets. However the pin 'state' may still be wrong - the pin state is still read in software (it's not reported by the hardware) when the IRQ is executed (which may not be immediately) so as a result a very small positive pulse may instead produce a state=false event because by the time the IRQ has read the pin state the signal has already gone back to 0.