Skip to content

Arduino Library for controlling DC motors with rotary encoders. They can be used both Hardware Interrupts or Pin-Change

Notifications You must be signed in to change notification settings

kr4fty/DCMotorServoPCI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DCMotorServo

An Arduino Library for controlling DC motors with rotary encoders. This library uses PID and Encoder feedback. It is modeled a little bit after the AccelStepper library.

Circuit

I used a 754410 quad half-H controller (a pin-compatible L293D). I'm sure it would be cheaper to make out of other components, but i've never done transistor matching, and i'm afraid of burning things.

Example circuit connections

L293D or 754410 pinsDevice
1, 9arduinopin_pwm_output
2, 15arduinopin_dir
7, 10arduinopin_dir
4, 5, 12, 13powerGND
16power5V
8power12V
3, 14motormotor pin 1
6, 11motormotor pin 2

Hardware

Pins

Pinout for motor control uses 3 pins for output. It is somewhat wasteful, but had more flexibility. Two pins for direction control, and one for motor power (assuming PWM). Be sure to pick a PWM capable pin for pin_pwm_output.

The two input pins are for the encoder feedback.

Two direcional pins allow for setting a motor brake by shorting the terminals of the motor together (set both directions HIGH, and preferably turn off the PWM)

Update (by Kr4fty)

EncoderPCI library is used instead of Encoder.

This is because "Arduino ONE" only has two external interrupt pins and if you wanted to control two motors you would need two "arduino one", one for each encoder. To solve this, the Atmega chips have a special type of interrupts called "PIN CHANGE INTERRUPT" (PCINT) that allows you to have many more pins for interrupts (arduino one has 23 PCINT for example) but only has three interrupt vectors for all of them So you have to see which pin is really interrupting. This suggests that the "interruption" process is slower.

NOTE: To use the encoders in pins with pin-change interruptions, you must first define USE_PINCHANGEINT within the library DCMotorServo.h
#define USE_PINCHANGEINT

More information can be found here: https://www.avrprogrammers.com/howto/int-pin-change

TODO

  • implement brake feature for 3-pin mode
  • 2-pin constructor
  • implement friendlier tuning method for PID

About

Arduino Library for controlling DC motors with rotary encoders. They can be used both Hardware Interrupts or Pin-Change

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%