How fast can the MicroPython switch a pin?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Deane
Posts: 2
Joined: Tue Nov 22, 2016 9:08 pm

How fast can the MicroPython switch a pin?

Post by Deane » Fri Dec 02, 2016 4:01 am

I am in need of a processor way faster than Arduino. I also hate the arcane C language. Python looks much more intuitive.
Can someone please do the following test with their oscope hooked to their MicroPython or Teensy board?
Just write a short code to turn on a digital output and with no delay turn it off.
Measure the resulting pulse width.
With an Arduino Nano the fastest it can do, using C, is 4 microseconds.
Thank you.
Dean

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How fast can the MicroPython switch a pin?

Post by dhylands » Fri Dec 02, 2016 4:12 am

You probably want to read this thread: http://forum.micropython.org/viewtopic.php?f=2&t=1349

Deane
Posts: 2
Joined: Tue Nov 22, 2016 9:08 pm

Re: How fast can the MicroPython switch a pin?

Post by Deane » Fri Dec 02, 2016 3:23 pm

Thanks for pointing out that thread from February, Dave. I know nothing about Python but it seems as though getting a 100 ns pulse is possible with some software tricks on a board running at 168 Mhz. What is Viper?
I just don't want to buy a board and find it won't do what I need it to. Which board would you recomend; MicroPython or Teensy 3 point something?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How fast can the MicroPython switch a pin?

Post by dhylands » Fri Dec 02, 2016 4:28 pm

MicroPython is definitely more mature. The Teensy only runs a small bit faster then MicroPython.

Viper is a sort of optimized code generator. It only works with some python, but it allows it to get compiled into something much faster than bytecode.

Personally, if I was looking for very precise pin toggling performance, I would write the low level code in C or assembler and call it from Python. If you choose assembler, then its possible to do it directly from MicroPython.

Here's an example I did where I needed a register write to happen within 10's of microseconds of a character leaving the serial buffer:
https://github.com/dhylands/bioloid3/bl ... ort.py#L60

Post Reply