You're only using RMT to send a
single pulse at a time - see where you're sending a tuple of length one with DRV8825_mp?; this is effectively the same as toggling a regular Pin and is not an effective way to use RMT!
Instead, build up a tuple or list of
durations. The length of the list will be the number of times the pin is toggled, the durations will determine how long the interval is between toggling the pins. Then bundle that list to RMT via write_pulses to send them accurately.
Note that the time of each duration is the period determined by the input clock (currently 80MHz) divided by an 8-bit clock_divider (you've specified '8' in your class). For example, if you use your current clock divider:
Code: Select all
r = RMT(0, pin=Pin(step_pin), clock_div=8)
r.write_pulses((5, 1) * 10)
With this clock divider, the duration's
resolution is defined as: 1/(80MHz/8) = 1us. Since we're sending a stream of (5, 1, 5, 1...) step_pin will toggle 10 times - 5us high and 1us low. This is
much faster than the 17KHz you're currently achieving since now all the timing sensitive activity happens in hardware. If write_pulses was sent the minimum durations for both high and low (ie
r.write_pulses((1, 1) * 10)) this frequency would be 10MHz.
Reducing the clock_div to 1 will allow an 80MHz frequency (12.5ns resolution). Probably too fast for steppers but very convenient for some protocols.
Is that clearer?
OutoftheBOTS_ wrote: ↑Tue Dec 31, 2019 6:31 am
Wow this is super interesting to me.
I thought you might like RMT.
OutoftheBOTS_ wrote: ↑Tue Dec 31, 2019 6:31 am
I play with steppers for many of my robotics projects. I having mainly found MP problematic for stepper pulse generation especially for multiple steppers so for many of my project I have had to use C and timers for interrupts to generate the step pulses.
RMT ought to make that unnecessary. Just build a step acceleration profile and ask RMT to send it.
OutoftheBOTS_ wrote: ↑Tue Dec 31, 2019 6:31 am
First can you generate pulses for many stepper(on separate pins) that are running at different speeds and different accelerations??
There are eight RMT channels (0-7, the first parameter passed to RMT at initialisation) and they can all have different clock dividers and be bound to different pins. They can all be run simultaneously though there's currently no way in MicroPython to accurately synchronise them (to start at exactly the same time for example). They just start - and operate in a non-blocking fashion - when you call write_pulses.
OutoftheBOTS_ wrote: ↑Tue Dec 31, 2019 6:31 am
Does you code use real time calculations for acceleration profiles or do you use a lookup table??
I'll leave that as an exercise for the reader.
Do note though that write_pulses can't accept a
generator, it must be a tuple or list (I need to know the length of the data in the C module before iterating over it).
If any of that is still not clear please let me know.
Oh, finally, I'm working on the next iteration of RMT for MicroPython that will expose a few more features - in particular, different ways to specify the bit pattern (effectively using the same
three methods that PyCom implemented). That's currently happening on my
esp32_rmt2 branch on my fork. I've been posting updates in the
MicroPython slack channel so it may be best to join there if you're interested.