DCMotorControl

I'll try to capture my Journey in getting a better understanding of a Motor Control, what's a best start other than a simple DC motor.

Parts I've used
  • Swiss Maxon A-max 391116 Mini 22mm Coreless Motor DC 12V 24V 11000RPM High Speed (spoiler alert: it's max 2250rpm) buy here

image

image

  • Power Op-Amp OPA548T
  • logic level Op-Amp for level shifting, Sallen-Key Filter, ... LM324
  • Nucleo STM32-F411RE dev board buy here
  • Resistors, Diodes, capacitors...
Tools I've used
  • RIGOL DHO804 oscilloscope
  • Two 30V-10A DC power Supply ( you need two to get + and - voltage since I don't use bridge setup at first)
  • Bambu Lab P1S 3D printer
  • of course a computer to program (Duh!)
  • A Taranis X7 Controller and its receiver to send commands ( you don't need this necessarily but it's fun!)
  • Also I used this Awsome plotter software get it here
First Setup - Forward Direction Only

Just to make things more fun I've started with the encoder mentioned above and made this setup:

image

later on moved to this to have it more stable:

image

All models can be find in the 3D model folder

Basic circuit for this setup (you can find it in the KiCAD folder): image

This can do forward direction only for speed control with relative encoder. List of Branches:

  • This branch is to read the encoder with normal GPIO
  • This branch is to read the encoder with Interrupt
  • This branch is to read the encoder with Timer in Encoder Mode ( this is easiest and probably best way, the other two was just to practive and for fun of it)
Second Setup - Bidirectional Control

in order to have both position and velocity control I moved to an absolute encodr and I made it myself! This branch is the final branch with the new circuit that can control the motor direction and speed with the same power op-amp

image

Here is the absolute encoder disc I made :

image

it's an 8 bit ablsute encoder which is using gray code to have less error on reading the position.

I've used some cheap IR transmitter and receiver diodes and made some sort of a stand for it as below

image image

The IR sensors can be purcahsed here

and you can easily drive them with 1k resistor on transmitter and 10k on receiver ( no amplification or comparator needed for 3.3V logic level )

image

and of course you'll find all my 3d designs in the 3d model folder

image

Position Control Results image

Velocity Control Results image

mechanical parts not being perfect and low resolution of the encoder causes sthe fluctuations you see, otherwise it's controlling pretty good.

Watch Here:

Watch the video Watch the video

Improvements - Speed control by Voltage reading

This is the branch for this feature. some improvement and correction in the main circuit that will be merged into the main

Here is the new circuit - you'll find it in the KiCAD folder MotorControl-V2

Screenshot 2023-12-30 154358

Here is How it looks on the scope, I'm disabling the power op-amp for around 300 usec and read the voltage after some level shifting and clipping in channel 1 of the ADC. the big pulse is the op-amp enable pulse and the blue line is the motor voltage to condition and read by ADC:

image

here is the speed reading results, red is the encoder feedback and blue is the voltage reading, notice it's clipped as I decided to not scale it down with voltage divider since it already had lots of fluctuation and noise. also some delay due the wait time in the mcu ( to let the self induce voltage caused by cutting motor current to dampen)

image

as nice at it looks, I decided not to use this as a control feedback as the encoder works mych better:) but it's fun doing it.

Stay Tuned, AC Induction Motor is next!

Update: Here is the Induction Motor Repo