Open Source DC Servo Controller

open dc pid arduino motor control for diy arduino servomotor driver


I am looking into replacing the stepper motors on my motion control head with PID controlled DC motors. This should allow me to make improvements in terms of noise produced by the steppers, and speed. I have previously done some experimenting with PID loops with the Arduino mega and found that although I could get the system working, the board is only really fast enough to run only the PID loop, and not the full firmware.

Therefore I am designing a small custom board which can run one or two axes and be controlled either by I2C or by Step/Dir pins. This should allow the board to be used with other Arduinos, generic 3D printer controllers, most CAM controllers, or by the MiniE motion control engine.

Design Spec

  1. This project uses an atmega328p (the same chip from in the arduino uno) for closed-loop control of a pair of DC-motor.
  2. Motor motion is detected by a quadrature encoder for each axis.
  3. Encoder counting is managed by single purpose IC (LS7366R).
  4. Two inputs named STEP and DIR allow changing the target position for each motor.
  5. I2C port allows target position to be changed for both axes.
  6. Serial port prints current position and target position every second.
  7. Change PID values using serial port.
  8. All unused pins broken out to provide expandable functionality.
  9. Motor driver can control up to two DC motors at a constant current of 1.2A (3.2A peak).
  10. Built-in thermal shut-down circuit and low voltage detecting circuit
  11. Power supply voltage: VM=15V max
  12. Count frequency: 40MHz

Relevant reading


Previous tests

I did a quick test and got a working PID closed loop controller working. Although as you can see in the videos it is clearly unstable and needs to be tuned.

While doing this I worked out a couple of tricks, most importantly that you need to manually alter the pwm frequency of the arduino to operate at a higher frequency too avoid an audible ‘pwm buzz’ from the motor casings.

Arduino PID controller for DC geared motor from Steven Brace on Vimeo.


Did a quick schematic in DipTrace and have most of the components placed although there are still a couple more things to iron out.

Communication protocols

I2C – Motion controller to OPEN SERVO DRIVER
  • Scalable to allow for more OSDs
  • Only 2 wire
  • Faster than serial
  • OSD cannot be master and slave SPI at same time.
  • fastest system, allows many loops of PID
  • Already supported by counter ICs

Assigned pins

Arduino pin – Project Net (atmega port)
PIN 4 – Bin1 (PD4)
PIN 5 – Bin2 (PD5) PWM
PIN 7 – Ain1 (PD7)
PIN 8 – Ain2 (PB0)
PIN 9 – Standby motor driver (PB1) PWM
PIN 10 – Slave select counter A (PB2) PWM
PIN 11 – Slave select counter B (PB3) PWM


diy dc pid motor controller encoder arduino

[ ]Connector for I2C in.
[ ]Connector for serial coms.
[ ]Sharing clock for all ICs, good idea?
[ ]Change ICSP connector to correct header
[ ]Step direction inputs to mirror miniE
[ ]scaling pot?

More to come!

1 Reply to “Open Source DC Servo Controller”

  1. i gonna same thing insted LS7366R i am gonna use another atmega that work as encoder buffer and send encoder count over spi so things will be cool i need your code to do this it will be very helpful to me

Leave a Reply

Your email address will not be published. Required fields are marked *