DC motor closed loop examples with encoder

by | | 0 comment(s)

DC motor closed loop examples with encoder.

Basic PID encoder DC motor control examples with both Serial and RC.

The Project

DC motor closed loop examples with encoder. 

Both of these examples are running on teensy 2 small form factor boards but can easily be changed to any Arduino style board. 

You need a dc motor with a quadrature encoder and there are links inside the code for how they work if you need. You also need an H-bridge with at least one enable pin for direction and one PWM pin. The RC receiver used in encode 7 is a hitec which is the same as futaba. Read encode 6 example first. 

The PID loop is complete as an example but only the proportional is running in the loop. The other functions are coded but commented out. 

Download the teensyduino addon if you want to run the examples as they are.
Examples are
Encode 6 is of a serial controlled PID set in P mode.
DC motor with encoder as feedback.
Format to send a command is a positive number upto 4bytes long with a * and then enter.
After the motor has come to a stop you can enter a new positive number and * of any number less than the maximum and in this way you can control the motor forward and back.

Encode 7 is the same except the input for the setpoint is from RC receiver using the function pulsein which on the receiver will record approximately a value between 1000 and 2000 depending on left or right stick on your transmitter. The value is scaled and used for the setpoint and is in a constant loop. Both tested and work, no tuning done 2000 count encoder running on teensy2 with H-bridge.

Download the code from here

This entry was posted in no categories.

You must be logged in to post comments.