Close
0%
0%

let's convert a DC motor into a stepper one

Ever wanted to use a DC motor as a stepper ?
To drive it with Step and Dir signals ?

Similar projects worth following
This project is a way to convert a DC motor into a stepper motor.
Of course "conversion" will not be "physical" but the DC motor will become a Servo Motor and will be controlled as a stepper.

The story

I have an old Trotec laser engraver which is almost totally dead:

  • laser tube is almost blind
  • software is using Windows95 OS

So more than 25 years later it was time to refurbish this machine.

  • Changing the laser tube will be described into another project
  • Changing the control board should be simple...FluidNC can drive any stepper board

So I opened the machine and very soon discovered that steppers motors were not "steppers" but DC motors with encoders... and a very specific electronics to drive them...

Here is the rotary axis of this Trotec machine when "opened"

  • on the right the DC motor
  • on the end shaft of this motor is an optical encoder
  • under the main shaft is a "home switch"

We will see how to reuse these elements to convert this motor into a stepper.

This mod will be demonstrated with this motor but will be generic enough to be applied on any other DC motor.

Main specifications are synthetised into this log

But let's start by a video showing the "final" product !


And a second one with this stepper (almost) installed into my Trotec laser. Control is still done by FluiNC and jogging done by gSender.

Before going further i must say that this controller will NOT act exactly as a stepper does

I did mount two of these "pseudo steppers" into my CNC machine and added a pen plotter. Here is the result of what should have been a straight line at 45° in theXY plane (line x=y in cartesian coordinates)

As you can see, oscilations are visible and the slope of the curve is not constant, we can clearly see when the braking is applied on one motor.

Consequently this controller is NOT suitable to precisely control a CNC. Despite the fact that the target position will be reached precisely, the motion itself is not linearly controlled. It is not a speed controlled PID. Furthermore the tuning of the PID will depend on the motor and two pieces (even from the same manufacturer) will not have exactly the same tuning... 

This project is usefull to control position (number of steps) but not to control the speed to reach this position.


The DC motor driver

My motors are all 35NT2R_82_426SP ones. They are still manufactured by Portecap and have the following specs :

  • 102 W, 
  • 32 V,  --> power supply 24V
  • 115 mNm, 
  • 5900 rpm, 
  • 3mm Shaft Diameter

To drive them I needed a driver able to sustain 24V and 4A

I chose the "IBT-2" one available on Aliexpress at very cheap price 

They are all equiped with a BTS7960 43A chip which is a dual H bridge with following specs:

  • Input Voltage: 6 ~ 27Vdc.
  • Dual BTS7960 H Bridge Configuration.
  • Peak current: 43-Amp.
  • PWM capability of up to 25 kHz.
  • Control Input Level: 3.3~5V.
  • Control Mode: PWM or level
  • Working Duty Cycle: 0 ~100%.
  • Over-voltage Lock Out.
  • Under-voltage Shut Down. 

So this driver is perfect for my setup. It can even be controlled by 5V or 3.3V logic MCU. An ESP32 will be perfect.


The encoder

Attached to the motor shaft is an optical encoder hedm-5500_J14 manufactured by Avago

it has a Two channel quadrature output with a resolution of 1024 counts per revolution. It will be perfect to know precisely the shaft position.


Schematics

Here is the schematics of the driver board.

The heart of the system is a Lolin32 lite ESP32 board. And that's almost it !

You will find 

  • the encoder interface (5V or 3.3V if yours is more modern than mine)
  • the Step/Dir connector
  • input for the Home switch

Note that the encoder outputs need to be pulled up (CHA, CHB signals)


PCB

This schematics was routed into a tiny PCB which was kindly sponsored by PCBWay.

You can find it on PCBWay shared projects

Soldering this board is as simple as it could be. The result is a "mezzanine" board to put and screw on top of the DC motor IBT-2 driver.

And here is the result into a small video :


Software

Software of this project is quite simple but rather "tricky".

We need...

Read more »

7-Zip - 137.69 kB - 11/18/2023 at 17:47

Download

encodeur-optique__hedm-5500_J14.pdf

Optical encoder datasheet

Adobe Portable Document Format - 461.89 kB - 11/17/2023 at 10:56

Preview
Download

BTS7960 Motor Driver.pdf

IBT-2 driver datasheet

Adobe Portable Document Format - 1.07 MB - 11/17/2023 at 10:52

Preview
Download

DCmotor_specifications_35NT2R_82_426SP.pdf

Portecap DC motor datasheet

Adobe Portable Document Format - 319.21 kB - 11/17/2023 at 10:25

Preview
Download

  • main real time considerations

    JP Gleyzes11/19/2023 at 08:17 0 comments

    Thi project has to run in "real time" to be efficient.

    Here are the main considerations regarding hardware and software limits.

    encoder processing

    you MUST not miss any encoder step.

    reading is done by hardware using ESP2 PCNT device :

    The PCNT (Pulse Counter) module is designed to count the number of rising and/or falling edges of an input signal.

    Each pulse counter unit has a 16-bit signed counter register and two channels which can be configured to either increment or decrement the counter. Each channel has a signal input that accepts signal edges to be detected, as well as a control input which can be used to enable or disable the signal input on the fly.

    The count and control inputs have optional filters which can be used to discard unwanted glitches in the signal input.

    The pulse counters have five watchpoints that share one interrupt. Interrupt generation can be enabled or disabled for each individual watchpoint. The watchpoints are: • Maximum / Minimum count value: Triggered when the counter value reaches the set upper or lower value. The upper limit should be a positive number, the lower limit a negative number. Additionally, this will reset the counter to 0. • Two threshold values, threshold 0 and 1. Triggered when the value is reached, the counting continues. • Zero: Triggered when the counter value is zero, the counting continues.

    So that we do not miss any encoder pulse !

    Step Dir processing

    you MUST not miss any step signal.

    Step signal is triggering an external interrupt on the ESP32 hardware.

    Hardware interrupt sustain a rate of 400kHz.  FluidNC will use it at less than 125kHz so we are safe. We won't miss any step pulse.

    The main limitation on my motor is the moor itself. When powered at 24V and with the stepper driver tuned at 200 steps per revolution and 4 micro stepping then the max step frequency is around 48kHz before reaching the max speed and saturating the PID output.

    PID frequency

    With the modified version of the PID library I did measure working sustained PID loop at 25 kHz. This doesn't meen that we will loose steps if they are arriving faster than 25kHz but just that they will be processed at 25 kHz. (for instance 4 by 4 if their frequency is 100 kHz).

    Conclusion

    We do have a safe "stepper controller" allowing a refresh rate of 25 kHz and with virtually no limitation on the step frequency. (limitation will come from the mechanical part (in my case the motor itself))

  • Installing FluidNC

    JP Gleyzes11/18/2023 at 20:29 0 comments

    To install FluidNC on a brand new ESP32, connect it to your serial port with USB and into a web browser go to FluidNC web installer.

    click Install and select the proposed Processor

    Then choose the "Wifi" firmware variant

    Now select the file browser and import the config.yaml of my pseudo stepper

    Now you should enter the credentials of your wifi router into your ESP32.

    Reboot the ESP32 and a hot spot names "Fluidnc" should appear. Connect to this hotspot with password 123456

    then you should see this page :

    Click on the FluidNC tab and enter your wifi credentials

    now  your ESP32 will reboot and can connect to to your internet router.

    So with your PC browser go to this URL : http://fluidnc.local

    And here we are : your "CNC" is accessible from your web browser

View all 2 project logs

Enjoy this project?

Share

Discussions

guineapigdiary1 wrote 11/19/2023 at 04:17 point

what is the cost for this project ?

  Are you sure? yes | no

JP Gleyzes wrote 11/19/2023 at 07:55 point

you can find IBT-2 driver for less than 3$ and ESP32 lolin lite board for less than 5$

So for the electronics it shouldn't cost more than 8$ per motor!

(provided you have the motor + encoder)

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

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