Author Topic: Single GPIO/PWM controlled Stepper Motor?  (Read 1143 times)

0 Members and 1 Guest are viewing this topic.

Offline leestrongTopic starter

  • Newbie
  • Posts: 8
  • Country: jp
Single GPIO/PWM controlled Stepper Motor?
« on: June 28, 2021, 08:41:36 am »
Typical stepper motor driver takes 4 gpios to control, which I feel is a waste of precious ports. Are there any drivers that require only 1 port, perhaps via PWM like a servo motor?
« Last Edit: June 28, 2021, 08:44:30 am by leestrong »
 

Online tom66

  • Super Contributor
  • ***
  • Posts: 7334
  • Country: gb
  • Electronics Hobbyist & FPGA/Embedded Systems EE
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #1 on: June 28, 2021, 08:55:54 am »
There are I2C based motor controllers, like DRV8847S, which can implement basic stepper motor controls. 

Only two GPIOs required and you can address multiple ones by using the nFAULT lines of the devices so one additional IO required per stepper controller.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13216
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #2 on: June 28, 2021, 08:58:57 am »
How do you plan to encode step and direction on a single pin without introducing an often unacceptable lag between issuing a step command and decoding its direction so it can be actioned, and without making it excessively sensitive to glitches and noise?  GPIO interface stepper controllers use two pins for step and direction for a reason, and often use a third pin to signal status back to the MCU.

If you don't care (much) about latency, as Tom noted, there are I2C interface smart stepper drivers available.  Consider  NXP's PCA9629 [Mouser] which allow you to drive up to 16 motors from only two I/O pins on your MCU, which can still be used for other I2C devices. 
 

Offline Bradlez

  • Contributor
  • Posts: 34
  • Country: au
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #3 on: June 29, 2021, 02:09:35 pm »
Well if you're considering price, you could use the DAC of your microcontroller to connect to the ADC of a second 8 pin microcontroller where the second drives the stepper via some transistors. This is because you'd have 3 states: clockwise, stop, anticlockwise, which you can assign to Vcc, Vcc/2, GND respectively. If you only need to rotate one way, then it's even easier and just use a normal digital output.

If you don't want to use a microcontroller and only go one way, you can probably use a decoded counter IC like the 4022 or 4017 with the fifth output connected to the reset pin so it will only ever count through the first 4 outputs. The digital output of the microcontroller will go to the enable pin and the outputs of the counter IC will drive the stepper via transistors. If you want to go both ways, I don't think there is an IC with a counter, decoder, and bidirectionality all in one so you would need to convert the analog output from your microcontroller into two digital lines through some weird circuit design, pass that into your bidirectional binary counter, connect the output to a binary decoder, to the stepper motor via transistors and voila, you have the definition of unnecessary ;D.

And lastly, if you care about variable speed, I'm sure some 1 wire asynchronous transmission solution exists you can communicate to your second microcontroller (like Maxim's "1-wire"). If you're good at assembly, you can bit bang at a given transmission rate and make the second micro sync up with it based on the first pulse. Transmissions shouldn't be too long however as they will go out of sync. You can even make it two way by adding circuitry so both sides will only be pulling the line low to prevent a short circuit (like I2C but asynchronous). Add CRC verification in the transmission to make sure there is no miscommunication and the second micro can signal if the transmission has to be sent again. As this is done through software, both micros must have interrupts for other things off and they will be busy waiting focused on performing the transmission before they can run other code.

Or if you're really into analog, add to what I said in the second paragraph but make the source oscillator of the stepper motor a VCO with your analog output from your microcontroller basically be mathematically |out - Vref/2| * 2 into the VCO but done through analog circuitry. There will probably be linearity issues.

If you have to use PWM instead of analog output, well I hope you like 4th order sallen key low pass filters. Because the other solution is not pretty (I think it involves PLLs).
« Last Edit: June 29, 2021, 02:26:14 pm by Bradlez »
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 9330
  • Country: fi
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #4 on: June 29, 2021, 05:37:50 pm »
Likely you need to roll your own 1-wire stepper controller, I think it's unlikely anything exist off-the-shelf because this isn't a very common use case. Any small MCU would do the trick of acting as a bridge to a driver IC,  or a complete driver, and you'd have the luxury of defining your own 1-wire protocol as you'd like (contrary to previous suggestion, I'd go digital; UART would be obvious!), but this is a lot of work and flashing the separate microcontroller is pain in the ass.

I'd look at all the possibilities to change the main microcontroller to a larger one so you can afford the pins required for the stepper.
 
The following users thanked this post: Ian.M

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4857
  • Country: dk
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #5 on: June 29, 2021, 05:56:28 pm »
How do you plan to encode step and direction on a single pin without introducing an often unacceptable lag between issuing a step command and decoding its direction so it can be actioned, and without making it excessively sensitive to glitches and noise?  GPIO interface stepper controllers use two pins for step and direction for a reason, and often use a third pin to signal status back to the MCU.

steppers are quite slow, GRBL on an AVR tops out at about 30kHz steprate, you could do step/direction serially at that speed

some TMC stepper drivers can run the internal motion controller with a single pin uart


 

Offline leestrongTopic starter

  • Newbie
  • Posts: 8
  • Country: jp
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #6 on: June 30, 2021, 08:42:22 am »
Thank you guys, really appreciate your ideas. I think I am going with I2C based drivers, it essentially costs no pins since I am already using I2C. Decade counter and UART drivers are also great for if the MCU doesn't support I2C.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2785
  • Country: us
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #7 on: July 01, 2021, 04:56:19 pm »
Trinamic have some stepper drivers with built-in motion control that can be controlled via SPI or UART.  Through either interface you can configure acceleration, current curves, etc, and also tell the driver to move to a given position and it will do the required accel/decel automatically, or you can tell it to accelerate to a certain velocity.  There are both integrated drivers as well as motion controllers that can control external drivers.  Here's one example: https://www.trinamic.com/products/integrated-circuits/details/tmc5031-la/
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 4004
  • Country: nl
Re: Single GPIO/PWM controlled Stepper Motor?
« Reply #8 on: July 03, 2021, 03:23:44 pm »
Stepper motors usually run on more voltage and current then a uC can deliver, so you will need some kind of interface.

Most stepper motor controllers take step and direction inputs from a uC, and if your motor only has to turn in one direction, then you can get away with tying the direction signal to either GND or Vcc.

Apart from that, uC pins are cheap. Jumping though hoops to control 1000 gadgets at once with your 8 pin microcontroller is pretty silly.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf