Pin Toggle Performance
Pin Toggle Performance
Hi everyone,
could someone tell me how to toggle the 0 pin the fastest way? I found this post, but it is mostly talking about the STM uC. Maybe someone could tell me how to switch the 0 pin as fast as possible. Maybe with the help of ASM commands?
http://www.mikrocontroller.net/topic/388161
Thanks,
rose
could someone tell me how to toggle the 0 pin the fastest way? I found this post, but it is mostly talking about the STM uC. Maybe someone could tell me how to switch the 0 pin as fast as possible. Maybe with the help of ASM commands?
http://www.mikrocontroller.net/topic/388161
Thanks,
rose
Re: Pin Toggle Performance
Check the topic on sound in here and the reply of pythoncoder. There was a contest on how fast a pin could be set. I am on my mobile and cannot get the link but you can easily find there.
Edit: found
http://forum.micropython.org/viewtopic.php?f=2&t=1349
Edit: found
http://forum.micropython.org/viewtopic.php?f=2&t=1349
Re: Pin Toggle Performance
These two links circle around the same contest. More recent for the ESP8266 is the following discussion, even if the title is misleading:
http://forum.micropython.org/viewtopic.php?f=16&t=2678
The answer would be like 21.8 us for a full cycle at 80 MHz, using the native code emitter, with something like:
Using viper code & direct port access should be much faster.
http://forum.micropython.org/viewtopic.php?f=16&t=2678
The answer would be like 21.8 us for a full cycle at 80 MHz, using the native code emitter, with something like:
Code: Select all
@micropython.native
def toggle():
import machine
pdsckPin = machine.Pin(4, machine.Pin.OUT, value=0)
isr = machine.disable_irq()
for i in range(24):
pdsckPin.value(1)
pdsckPin.value(0)
machine.enable_irq(isr)
Re: Pin Toggle Performance
Good, that sounds like there is the possibility to get a full cycle of 250ns. I will try this. Thanks again for linking me further!
Re: Pin Toggle Performance
It's 21.8 µs for each of the 24 cycles, not for all 24 cycles, and the first cycle always takes longer.
Re: Pin Toggle Performance
Since Micropython on this platform executes not much faster than BASIC on a BBC Micro if you want sub 1uS you'll need to write it in C. You could cheat and pretend it's an SPI device and clock out something using that.
Jon
Jon
Re: Pin Toggle Performance
Using viper code and direct register access, you can get a "little bit" faster. The following code example creates a 100 pulse burst with a time of 376 ns between two pulses (or 2.66 MHz) at 80 MHz clock frequency. Using C code or assembler would be a little bit faster
Unrolling the loop results in a period duration of 150ns @ 80MHz.
Update: Setting the CPU clock to 160 MHz does NOT increase the toggle frequency.
Code: Select all
def toggle():
import machine
pdsckPin = machine.Pin(4, machine.Pin.OUT, value=0)
isr = machine.disable_irq()
do_toggle()
machine.enable_irq(isr)
@micropython.viper
def do_toggle():
GPIO_OUT = ptr32(0x60000300) # GPIO base register
for i in range(100):
GPIO_OUT[1] = 0x10 # set bit 4
GPIO_OUT[2] = 0x10 # clear bit 4
Update: Setting the CPU clock to 160 MHz does NOT increase the toggle frequency.
Re: Pin Toggle Performance
Sorry to dig this up.
I failed to find any documentation on this part:
I failed to find any documentation on this part:
Is there documentation or is it obsolete by now?GPIO_OUT = ptr32(0x60000300) # GPIO base register
for i in range(100):
GPIO_OUT[1] = 0x10 # set bit 4
GPIO_OUT[2] = 0x10 # clear bit 4