digitalPulse() jitter/offset #7116
Replies: 1 comment
-
Posted at 2018-11-06 by Robin Tue 2018.11.06 Although I'll agree the accuracy isn't specified, the implication is millisecond(s) wide pulses. Have you tried using an array of pulse values (see description in link above) and just a single Considering:
For a 2msec pulse 4%-8% error is rather odd. . . . Posted at 2018-11-06 by barbiani I understand that a single call to digitalPulse may have better accuracy between pulses.. but as the application will fire a pulse after another sensor decodes a pattern. The setInterval came from the test code I added to simulate the hardware. The question now is if the original espruino does better than the ESP32 port. Posted at 2018-11-12 by @gfwilliams
Yes - the official boards use an IRQ-based timer. Just tried this on a Pico and it's exactly 2ms to as near as I can measure on my digital scope (so well within 1%)... And if that's not good enough there's some documentation on how to use the timer peripherals in the device itself. There was a recent change in ESP8266 courtesy of @MaBecker that fixed the issues that has, and it does look like the ESP32 is using IRQs so I'm not sure why there would be the variance. I just had a quick look and @jumjum it could be that While the timer is accurate, it's set using the current time as a base - so if the timekeeping is 'grainy' it can screw things up. Posted at 2018-11-12 by Wilberforce We are using both timers as suggested: https://github.com/espruino/EspruinoBuildTools/blob/master/esp32/build/app/sdkconfig#L200 Posted at 2018-11-12 by barbiani Well... then their timer implementation is not good! I was hoping to see at most 4us jitter. The idf has a timer jobs linked list. Does espruino run another one on top of it? Posted at 2018-11-13 by @gfwilliams
Yes, but for something like Espruino's timer implementation could be improved (eg. for If you really want accurate timing without actually buying an official board it's possible there's some spare timer hardware on ESP32 that you could set up yourself with Posted at 2018-11-13 by Wilberforce If you set up a pwn output is the timing for this accurate? Posted at 2018-11-14 by barbiani analogWrite(D5,0.5, { freq : 3000 } ); is perfectly stable. Can not see jumps down to 5ns per division. Frequency reads 3003hz.
Posted at 2018-11-14 by Wilberforce I think this might be the issue here: If the timer is less than 30 - it's set the 30. @jumjum - can you recall why? Posted at 2018-11-15 by Wilberforce As a possible work around - you might be able to use the pwm output and do a setwatch on that - and in the setwatch- use that to drive another pin low then high and low again. You can use a variable flag to say if you want the out put in the output pin. Just an idea. Posted at 2018-11-15 by barbiani So, is the pwm software driven? Or espruino will use hw interrupts for the pwm edges? Posted at 2018-11-15 by Wilberforce No - the pwm on the Esp32 is hardware driven. Or another thought - you could send an array of o,1,1,1,0 and then adjust the number of 1s to be close to 2us Posted at 2018-11-15 by @gfwilliams Or maybe:
So use the hardware PWM to do the output, then cancel it in software after the first one - leave the duty cycle low enough that any jitter in execution by Espruino won't be an issue. Posted at 2018-11-15 by JumJum Sorry, no bell is ringing on that. Posted at 2018-11-15 by @gfwilliams Git blame to the rescue! espruino/Espruino@1b3f15a I imagine it will break if you don't at least limit it to Posted at 2018-11-18 by barbiani Looks like the original esp32 port used RMT then changed to the Espruino style. I wonder why. @gfwilliams Can the timer functions be used with or changed to use the floating point delay to achieve sub ms timing? Sub millisecond would only make sense in the digitalPulse function, because I see that:
Gives a high pulse from 3.6 to 7ms. Posted at 2018-11-18 by Wilberforce
What do you mean by espruino style? Posted at 2018-11-18 by barbiani That came from the source code comments! The RMT code is commented out... with it and added code from the nrf52, it says. Posted at 2018-11-19 by @gfwilliams
That won't be your issue. The timer functions are currently using
He's probably referring to it using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-11-06 by barbiani
Hello,
I was evaluating if the digitalPulse() (on ESP32 v2.00) timing would meet the requirements of a project and found that:
Produces pulses from about 2096us to 2160us.
Being generated by hardware I wonder if it can do any better. Maybe the original espruino does not have the jitter?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions