Professional Documents
Culture Documents
1. Required Hardware
- Arduino Uno (01).
- DC motor with pre-assembled encoder (Faulhaber 2342L012CR) (01).
- Resistor 10K (03), 100 (01), 50 (01).
- Button (01).
- Green LED (01).
- Power supply > 12VDC (01).
- Breadboard and connecting wires.
2. Hardware Connection Diagram
Fig. 1 Hardware Connection Diagram
3. PID Block Diagram
The following diagram shows connections between function blocks to establish a closed loop to control
the motor speed.
HHManh, Mechatronics, AIT Thailand. Page 1
Fig. 2 Block Diagram of the Experiment
The encoder attached with the motor shaft at the back of the motor will follow the rotation of the
motor. The generated pulse trains by the encoder will become inputs for the micro-controller to
calculate the motor shaft speed in RPM. The speed in RPM later is converted into percentage by
software and become feedback to the PID controller.
The speed setpoint in RPM sent by the user to micro-controller will be converted to percentage and
become the setpoint for the PID controller.
Based on the setpoint and feedback (both are in %) the controller will calculate its output in percentage.
Then PWM converter will generate a pulse train that its pulse width dependent on the PID output value.
PWM later is sent to the motor drive to move the motor.
4. PID Algorithm
We will use the ideal, dependent PID form with derivative on error for our experiment since this form is
used most popular. From the PID background, we have the form as the following:
( )
. ( ) ( ) .
bias
Kc de t
CO CO Kc e t e t dt Kc Td
Ti dt
= + + +
Where,
CO = controller output signal.
CO
bias
= controller bias, set by bumpless transfer.
e(t) = current controller error, defined as SP PV.
SP = set point.
PV = measured process variable.
Kc = controller gain (also called proportional gain), a tuning parameter.
Ti = reset time, a tuning parameter (or sometimes called Pre-Act).
Td = derivative time, a tuning parameter.
PID
Algorithm
PWM
Converter
MOTOR
DRIVER
MOTOR
ENCODER
% Conversion
Speed
Calculation
% Conversion
MicroController
Speed Setpoint (RPM)
(settingSpeed)
RPM Setpoint (%)
(setPoint)
Motor Speed (%)
(processVariable)
Motor Speed (RPM)
(rotationSpeed)
PID output (%)
(lmn)
Motor Shaft
operationMode
(AUTO =1, MANUAL =0)
manualValue
controlVariable
HHManh, Mechatronics, AIT Thailand. Page 2
Using nomenclature is up to the controller vendor since there is a little standardization on it. I prefer to
use the nomenclature a little bit different from the above formula as followings. The bias value doesnt
appear in the formula since this value will be the value set by user at manual mode:
lmn = +
1
lmn = lmnP + lmnI + lmnD
lmnP = GAIN * ER
lmnI = GAIN
1
lmnD = GAIN
Where,
lmn = loop manipulated variable or controller output signal (unit is %).
lmnP = proportional portion.
lmnI = integral portion.
lmnD = derivative portion.
ER = current controller error, defined as setPoint processVariable (unit is %).
GAIN = controller gain (also called proportional gain), a tuning parameter (no unit).
TI = reset time, a tuning parameter (or sometimes called Pre-Act) (unit is ms).
TD = derivative time, a tuning parameter (unit is ms).
setPoint = set point (unit is %).
processVariable = measured process variable (unit is %).
The PID forms written above are in continuous form and used by analog controller. Using
microcontroller, forms should be converted into digital form. In microcontroller, the calculation will be
done at fixed interval called CYCLE.
4.1 PID Portions
- Proportional Portion
lmnP = GAIN * ER
lmnP = GAIN * (setPoint processVariable)
- Integral Portion
lmnI = GAIN *
1
d(lmnI)/dt = GAIN * (1/TI) * ER
d(lmnI) = GAIN * (1/TI) * ER * dt
lmnI lastLmnI
= GAIN * ER * (1/TI) * dt
lmnI = lastLmnI + lmnP * (1/TI) * dt
lmnI = lastLmnI + lmnP * (1/TI) * CYCLE
lmnI = lastLmnI + (CYCLE/TI) * lmnP
- Derivative Portion
lmnD = GAIN