Bi-directional DC motor control?



  • I'm looking for some advice on using the duet to control a DC motor (6V 90mA). It's part of an actuator to raise and lower a second hotend, so it needs to reverse. My plan was to turn the motor on for a period and turn it off. Reverse motor direction to raise it. Both directions have hardstops.
    Originally I planned to use a fan channel, which seemed simple to implement the gcode, but realized that they aren't bi-directional. Some research suggests to use a H-bridge. It looks like that would require two pins to control both directions.

    I'm curious if there are any pins available other than the 3 fan channels. I'm also curious if an h bridge is the best option? If there are pins available are there any resources I can check out to see how to configure them?

    Thanks!


  • administrators

    An H-bridge is the usual option for controlling a reversing DC motor. You can drive an H-bridge from two pins using M42 commands. See https://duet3d.dozuki.com/Wiki/Using_servos_and_controlling_unused_IO_pins. A suitable H-bridge might be https://www.pololu.com/product/2990 or another in the Pololu range.



  • Thanks for the advice!

    I picked up a H bridge, checked out the M42 command and the controlling IO pins link you provided.

    What would be the prefered pins to use? I see heaters labeled pins 3-7 which look like 8, 13, 18, 23, and 28 on the expansion header. I don't see any labeled fan on the header though. I assume using a couple of the heater channels would be the way to go?

    To implement this using heater 6 for direction and 7 for speed it would look something like this:
    First disable the channels in config (I assume)
    M307 H6 A-1 C-1 D-1
    M307 H7 A-1 C-1 D-1

    Then to extend the tool
    M42 P6 S0
    M42 P7 S255
    G4 S1
    M42 P7 S0

    and to retract
    M42 P6 S255
    M42 P7 S255
    G4 S1
    M42 P7 S0

    Am I on the right track?


  • administrators

    Yes, that's the sort of thing I had in mind.



  • I got this to work using heater channels 6 and 7 and the pins 1 and 2 on the header for GND and 5V. I setup the pins with
    M307 H6 A-1 C-1 D-1
    M307 H7 A-1 C-1 D-1

    When I command M42 P6 S0 I read 3.3v to GND (pin 2) and when I command M42 P6 S255 they read 0V. Is this the expected behavior? Are pins 1 and 2 ok for 5V power?

    I powered this with USB.


  • administrators

    The heater outputs are inverted by default, because when they are used to drive heaters there is an inverting level shifter driving the MOSFET.


 

Looks like your connection to Duet3D was lost, please wait while we try to reconnect.