micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

Add Stepper Motor PWM-Counter driver.

Open IhorNehrutsa opened this issue 2 years ago • 8 comments

image The main feature of this driver is that the generation and counting of pulses are performed by hardware, which frees up time in the main loop. PWM will start pulses and Counter will stop pulses in irq handler.

View the README Motor speed acceleration/deceleration video

This driver requires PR's: esp32/PWM: Reduce inconsitencies between ports. #10854 ESP32: Add Quadrature Encoder and Pulse Counter classes. #8766

IhorNehrutsa avatar Aug 21 '23 12:08 IhorNehrutsa

@jonathanhogg May you test esp32/esp32_pcnt: Add PCNT class and Counter/Encoder shims in machine #7582 with this PR?

IhorNehrutsa avatar Aug 25 '23 05:08 IhorNehrutsa

@robert-hh May you test mimxrt: Add Quadrature Encoder and Pulse Counter classes. #7911 with this PR?

IhorNehrutsa avatar Aug 25 '23 05:08 IhorNehrutsa

Sorry, I do not have any motor and /or driver hardware for testing.

robert-hh avatar Aug 25 '23 07:08 robert-hh

@jonathanhogg May you test esp32/esp32_pcnt: Add PCNT class and Counter/Encoder shims in machine #7582 with this PR?

This code won't work with my version of Counter() as I don't support an .irq() method – I've only implemented the basic #8072 API – on the assumption that anyone who needed to do something more low level would use my PCNT() class directly.

As I currently use IRQs to implement wide-value counting, it'll be hard – though probably not impossible – to extend Counter() to support a threshold callback. I'd not look at doing this unless there was a decent cross-port API for it though, which at the least is going to need to decide on what to call the IRQ constant and how to specify the threshold.

jonathanhogg avatar Aug 25 '23 09:08 jonathanhogg

@jonathanhogg I think you remember the docs\machine: Add Counter and Encoder classes. #8072

IhorNehrutsa avatar Aug 25 '23 09:08 IhorNehrutsa

@jonathanhogg I think you remember the docs\machine: Add Counter and Encoder classes. #8072

I'm sorry, I don't know what you mean.

jonathanhogg avatar Aug 25 '23 09:08 jonathanhogg

Sorry, I relied on the API in which you also participated in the discussion. I have no complaints.

IhorNehrutsa avatar Aug 25 '23 10:08 IhorNehrutsa

Sorry, I relied on the API in which you also participated in the discussion. I have no complaints.

Yes, but we didn't arrive at a standard API for .irq() in that discussion. This code uses .irq():

self._counter.irq(handler=self.irq_handler, trigger=Counter.IRQ_MATCH1, value=self._match)

and thus won't work with my implementation.

As far as I can tell, @robert-hh's MIMXRT implementation doesn't have an IRQ_MATCH1 and so I don't think it'll work with his code either.

jonathanhogg avatar Aug 25 '23 10:08 jonathanhogg