Replies: 2 comments
-
These numbers are worse than I would expect. Repeating the tests I get much better figures (code below), but the principle limitations stay. The numbers I get: a: Short loop, b: Loop with Pin I/O and longer wait times: This is for the short loops. The inherent problems are cache misses of the code with a serial attached memory and garbage collection. In case of a cache miss, the page with the missing code has to be reloaded. Garbage collection in critical phases can be both disabled and, if not disabled, avoided. Modified code. Note that calling ticks_ms() takes time as well. e.g. for ESP32 removing the sleep_us(1) statement result in a time of 3 us. from time import ticks_us, sleep_us
def tickloop(n=100):
for i in range(n):
t2 = ticks_us()
sleep_us(1)
t = ticks_us() - t2
print(t)
tickloop(24) from time import ticks_us, sleep_us
from machine import Pin
st=Pin(5, Pin.OUT)
def tickloop(n=100):
for i in range(n):
t2 = ticks_us()
st(1)
sleep_us(150)
st(0)
sleep_us(150)
t = ticks_us() - t2
print(t)
tickloop(24) |
Beta Was this translation helpful? Give feedback.
-
microstepping is a property of the stepper driver (i.e. how many pulses of the step pin correspond to one full cycle of the A and B lines). But if your issue is that the pulses are too slow, then note that your loop can be optimised slightly I think to avoid some attribute lookups def run(p, n, us):
s = sleep_us
for j in range(n):
p(1)
s(us)
p(0)
s(us) Because it's inside a function, the variables are all now local (rather than having to be looked up in globals). This includes the sleep_us function, which is cached in the local variable You could also add See https://www.youtube.com/watch?v=hHec4qL00x0 for more tips like this. There are other ways to generate pulse trains though. See e.g. esp32.RMT, or even you could use the SPI clock line. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, i'm working with a stepper motor drv8825 with 32microsteps
the code is super simple:
but the pulses are wrong.
because loop with delays is wrong.
even simple code like this:
gives me range from 105-120us
trying this code:
gives 380-410us. not close to 300.
the lowest delay i can set is 31us. and it gives 140-190us and not 62
does this mean that we cant use micropython in microsteps mode?
how can i "calculate" a speed this way?
thanks
Beta Was this translation helpful? Give feedback.
All reactions