Faster Pulses with Spare Timers? #4061
Replies: 1 comment
-
Posted at 2022-07-08 by @gfwilliams Hi - did you consider using Also which firmware are you on? In 2v13 the accuracy improved a lot. But... yes, there is free hardware. What's used is shown at the top of https://github.com/espruino/Espruino/blob/master/targets/nrf5x/jshardware.c and there's actually an example of doing PWM using hardware timers (as part of a capacitive sense example) at: https://www.espruino.com/NRF52LL#hardware-capacitive-sense-on-two-pins Posted at 2022-07-08 by user135646 Thanks Gordon, all useful advice. I was on v2.12, but have updated to v2.14 and seen an improvement in timings, although there'll still be one or two long pulses in a second's worth and it still doesn't quite go down to 20us. But I agree it's much improved and if I get fed up with fiddling with timers it's probably good enough to work with. Thank you for the links re. hardware and examples, I'll have a read up on them. Posted at 2022-08-18 by user135646 Finally got around to this, and results are excellent. Getting <0.3us jitter. A working example is included below though that uses a button on D17 to start / stop a train of pulses.
edit - added 'var ll = require("NRF52LL");' at top of example |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-07-08 by user135646
Hi All,
Working on something that needs to produce accurate-ish (+/-20%) pulses down to 20us every 10ms for 1s. I'm currently using a combination of setInterval() and digitalPulse() (see snippet below if interested).
With a bit of dialling-in, the 1s duration is reliable enough, setInterval() is working great at 100Hz, and digitalPulse() gives good results at 200us and passable ones at around 140us.
digitalPulse can do 32us, but there's about +40/-0 us of variation in it so it's not ideal. For stuff around 100us things could be fudged so that the +40us sits as +/-20% around 100us, but it doesn't work once you get faster than that.
So the question is, what timers are free to use that don't interfere with Espruino? What timers (if any) does digitalPulse() use? Was thinking of using a one-shot timer triggered over and over by setInterval().
Beta Was this translation helpful? Give feedback.
All reactions