Close
0%
0%

Stepper to DC Motor Conversion

Control DC Motor position from driver sockets meant for A4988 or DRV8825 stepper driver

Public Chat
Similar projects worth following
567 views
In the makerspace, typically, stepper motor is used when precision movement control is required in a project. This is fine for projects where weight of the motor and power consumption is not a concern. DC motor have the advantage of being lighter in weight and consuming less power than a stepper motor with the same torque rating.

This project is to replace stepper motors with DC motors. The Arduino code accept STEP and DIRECTION input from driver sockets meant for A4988 or DRV8825 driver.

I have used geared DC motor for my 3D printer direct extruder (http://www.thingiverse.com/thing:4562946) where a lighter motor will improve the print quality but yet have a high torque to be able to squeeze the filament through the hotend nozzle.

My CNC machine (https://www.thingiverse.com/thing:4544582) is another project I have used DC motor. For CNC machine, closed loop feedback to is used to raise an alarm and stop the job if the milling bit is stuck in the workpiece.



_________________________________

Challenges:

_________________________________
DC motor position control is more complicated than stepper motor control requiring a closed feedback loop and PID parameter tuning to provide a fast but yet well damped motor movement. For this PID tuning purpose, I've wrote a Python program to allow visualization of the motor step response when PID parameters are changed.

_________________________________

Hardware:

_________________________________

I started with Attiny as the microprocessor as the PID controller. It was a pain to use as changing PID values meant reprogramming the Attiny chip.

I moved on to using Arduino Nano as it was much easier to investigate the PID step response and change the PID value with just a USB cable.

However, I found that the minimum sampling time for Arduino nano is about 200us. This is fine when I used a DC motor with just a 44CPR quadrature encoder. When I switched to an optical encoder with 448 CPR, I had to switch to STM32 blue pill to bring the sampling time down to 50us. STM32 has a much faster 80MHz processor and a better 16bit PWM compared to Arduino Nano's 8bit PWM.

For the motor driver, I use TB6612FNG. It's efficiency is much higher than L298N. It runs cool without any need for heat sink whereas L298N need a large heat sink.

_________________________________

PID Controller Software:

_________________________________

This Arduino code started it's life based on Misan's github's code (https://github.com/misan/dcservo). I've added features I needed to build my CNC machine which uses Arduino Nano as the controller (https://www.thingiverse.com/thing:4544582) and DC motor servo extruder using STM32 blue pill as the controller  (https://www.thingiverse.com/thing:4562946).

Features added are:
- Motor driver changed to TB6612
- Added support for STM32 blue pill board 
- Added a step response output printout for PID parameter tuning
- Added dual motor control
- Added LED output as an indicator when PID output is at maximum
- Motor stuck detection (PID max output over a defined period and not moving much)
- Motor stuck output alarm to send kill signal to terminate CNC job or 3D print job. This can happen when the 3D print nozzle is stuck or when the milling bit is stuck in the workpiece
- Motor runaway detection (PID max output over a defined period and moving much more than the setpoint)
- Modified Brett Beauregard Arduino PID library:
  -reduce sampling time from millisecond to microseconds
  -average differential term over 2 samples to smooth out motor response
  -added maximum output for definable sample period at setpoint change to for motor to overcome intitial inertia.

_________________________________

PID Visualization and Tuning Software:

_________________________________

The PID visualization and tuning Software is written in Python. I use it to change the PID values and see how the DC motor would response to a step response.

The software uses the USB COM port to send command to the Arduino Nano or STM32 board and read the motor step response from the controller memory.

Once an acceptable PID value is found, this value can be saved permanently to Arduino Nano or STM32 board using the save button.

NanoTB6612 connection diagram.pdf

Connection Diagram for Arduino Nano and TB6612 motor driver

Adobe Portable Document Format - 33.33 kB - 07/02/2021 at 07:00

Preview
Download

STM32TB6612 connection diagram.pdf

Connection Diagram for STM32 Blue Pill and TB6612 motor driver

Adobe Portable Document Format - 40.34 kB - 07/02/2021 at 07:32

Preview
Download

  • 1 × Arduino Nano or STM32F103C8T6 Blue Pill Microprocessor as the PID controller
  • 1 × TB6612FNG Motor driver
  • 1 × DC motor with quadrature encoder DC motor with quadrature encoder

  • 1
    STM32 Blue Pill preparation

    For Arduino Nano, this step is not required.

    Prepare the STM32 Blue Pill board using instruction from this link:  https://www.electronicshub.org/how-to-upload-stm32f103c8t6-usb-bootloader/

  • 2
    Upload DC servo controller software into STM32 Blue Pill or Arduino Nano

    Download the DC servo controller software from: https://github.com/patlhy/PID-DC-Motor-Servo-Controller/tree/master/ArduinoTB6612PIDController

    For Arduino Nano, edit the config.h file so that "#define NANO" instead of "#define STM32" is in the file before uploading.

    For STM32 Blue Pill, set "#define STM32" in the config file and upload with the following settings:

  • 3
    Hardware Connection

    For Arduino Nano,  connect the board to TB6612FNG driver board as per the wiring diagram below.

    NanoTB6612 connection diagram.pdf

    Connect STM32 blue pill board to TB6612FNG driver board as per the wiring diagram below.

    STM32TB6612 connection diagram.pdf

    Please note that if you use the USB port to power the STM32 blue pill board, do not connect the 5V power to STM32 board. Connecting both at the same time may cause damage to the board as STM32 blue pill does not have a protection diode between the 5V pin and the USB 5V pin.

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates