Hello,
I am working on an application that will need to send a 5.25μs +/- .25μs pulse to an old piece of hardware.
I have not yet tried this on an oscilloscope but I am curious if anyone has any experience with the timing resolution of writing to esp8266 pins with micropython. On an arduino there is a fair amount of overhead that is worked around. [see here: http://www.billporter.info/2010/08/18/r ... uino-pins/] Are there similar caveats for micropython? Am I expecting too much? Or being too cautious?
Thanks for your insight!
μs timing for pins
Re: μs timing for pins
Some observations and sample code around that aspect are here: http://forum.micropython.org/viewtopic. ... gle#p16445
Summary: Yes it's possible. The caveat I've seen: If you execute a certain piece of code in ESP8266 the first time, e.g. the first run of a loop, it's execution time can me much slower. In the sample non-viper code, typically the ifrst pulse was substantially longer.
Summary: Yes it's possible. The caveat I've seen: If you execute a certain piece of code in ESP8266 the first time, e.g. the first run of a loop, it's execution time can me much slower. In the sample non-viper code, typically the ifrst pulse was substantially longer.
Re: μs timing for pins
This is gold. Thanks you so much.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: μs timing for pins
There is support for inline assembler if you need very tight timing: https://github.com/micropython/micropython/issues/2695.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: μs timing for pins
In this toggle test i used also an assembler version, which was not faster, but far less readable.
Code: Select all
def loop():
import machine
machine.Pin(4, machine.Pin.OUT, value=0)
do_loop()
print("loop done")
@micropython.asm_xtensa
def do_loop():
movi(a2, 0x60000300) # GPIO Base address
movi(a5, 0x10) # set/clear bit 4
movi(a3, 10) # loop count
movi(a4, 1) # loop decrement
label(loop_start)
s8i(a5, a2, 4)
s8i(a5, a2, 8)
sub(a3, a3, a4)
bnez(a3, loop_start)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: μs timing for pins
Interesting. Viper is evidently very efficient
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: μs timing for pins
In my previous test on Pyboard, viper took about two times longer than assembler, mostly becaus it does not keep local values in registers. That is still very good. In this example I guess that the limiting factor is the port access, which seems to be timed to ensure proper signals.