Position and Speed Control of a DC Motor using Analog PID Controller Application Note Position and Speed Control of a DC Motor using Analog PID Controller AN CM 250 Abstract This is a demonstration of how to implement an analog PID controller controlling the angular position of a DC motor shaft then editing the design to control its speed as well as tuning PID parameters for reliable performance This application note comes complete with design files which can be found in the References section A.
Proportional Controller
The proportional component is simply a gain The gain is set by the values of the resistors as follows:
Integral Controller
We can think of this as accumulating (adding) a quantity over time In our PID controller, we are integrating voltage as time progresses The output voltage is given by:
The area under a voltage-time graph is crucial for understanding the function of an ideal integrator By simplifying the calculations with the assumption that the 1/RC term equals 1 (where R is in KΩ and C is in µF), we can streamline the analysis of the integrator's performance.
Figure 9: Relation between Output and Input in Integral Controller
In the initial 2 seconds, a 2 V square wave is fed into the integrator, resulting in an output of -4 V due to the inverting nature of the circuit, as it accumulates a 2 V signal over this duration, yielding an area of 4 From T2 to T4, the absence of voltage input keeps the output stable Additionally, the diagram illustrates that the integrator's output polarity reverses in response to changes in the input signal's polarity.
In practical applications, the ideal integrator concept is challenged by real capacitors that exhibit leakage and self-discharge, as well as OpAmps that may inadvertently charge the capacitor without an input signal Consequently, circuits designed as shown may experience saturation after a few minutes of operation To mitigate this issue, it is advisable to incorporate a resistor in parallel with the capacitor However, for our current objectives, saturation is not a primary concern, as we intend to utilize the integrator alongside other circuits to effectively manage the capacitor's charge.
Derivative Controller
The derivative measures the rate of change, and this circuit resembles high-pass filters found in various schematics It effectively attenuates low frequencies while allowing high frequencies to pass through The output voltage can be calculated using a specific formula.
The rate of change can be understood as the slope of a line, which quantifies the change in voltage relative to the change in time, expressed mathematically as delta voltage over delta time (dv/dt) When a ramp is applied to a differentiator, it produces a consistent DC output voltage.
Figure 10: Relation between Input and Output in Derivative Controller
In this analysis, we set RC equal to 1 for simplification Over a duration of 2 seconds, the voltage decreases by 4 volts, resulting in a slope of -2 Consequently, the output of the differentiator, taking into account that the stage is inverting, will be 2.
Using PID Controller as a Position Controller in Application
Proportional Operation
● An error must be present!
The system will try to correct the error by turning the motor in a direction that opposes the error with appropriate speed
The intensity of the correction is determined by proportional gain If there is no error, there is no proportional drive.
Integral Operation
Integrating the error then provides a correction signal to the motor
● An error must be present!
The integral section accumulates the error A small error can become a large correction over time
As the error is accumulated, the motor is forced to correct the error
The integrator will overshoot the set-point It must produce an error to counter act the input signal to discharge the capacitor.
Derivative Operation
When the motor starts to turn, the voltage measured by the resistor will be increasing or decreasing
When voltage varies over time, it creates a ramp effect, with the slope of the ramp reflecting the motor's speed A faster motor results in a steeper slope, leading to a higher output from the derivative stage.
● The motor must be moving!
The differentiator will have a high output voltage when the motor is moving quickly and a low voltage when the motor is moving slowly
This signal is applied in such a way as to slow down the motor
If the motor is not moving, the differentiator has 0 output voltage
The connections for the differentiator differ from those of the proportional and integral sections, as it directly receives input from the resistor This design allows the differentiator to measure only the speed of the motor's movement, without considering the set-point.
Figure 12: Schematic of Analog PID Controller Circuit along with the Other Blocks of the
PID Parameters Effect on the System Response
Figure 13: Increasing PID Parameters’ Effect on the Overall System Response
Implementing the Circuit using SLG88104
I utilized a variable resistor to fine-tune the setpoint of the PID circuit, initially set at a counter value of 127, which corresponds to approximately 3.27 volts The variable resistor's input is connected to the VDD of the SLG46621, allowing us to adjust the output voltage to the required 3.27 volts.
After evaluating the PID circuit, I proceeded to design a voltage amplifier utilizing an additional operational amplifier (op-amp) to enhance the output signal This amplification significantly increases the visibility of voltage changes.
Figure 14: Non-Inverting Voltage Amplifier
To overcome the issue of adding another op-amp to correct the sign of the op-amp I used a non- inverting amplifier configuration The output voltage is given by:
I chose R1 to be 1 kΩ and R2 to be 10 kΩ so the voltage is amplified by 11 times from the original signal The output signal will be changing from approximately 0 to 4.7 V
Note that: if you aren't using an SLG88104, don't forget your +V and -V to the op-amp for appropriate operation like the one explained in the DAC operation
I designed a PCB with EagleCAD software for an analog PID controller that accommodates both the SLG88104 and LM358 amplifiers to compare their outputs The PCB features test pins for the input signal, pre-amplification output signal, and setpoint Additionally, I incorporated jumper-configurable test pins for the output signal post-amplification.
Figure 15: Analog PID Schematic using Eagle Software before Voltage Amplification
Figure 16: Analog PID Circuit Board using Eagle Software before Voltage Amplification
To utilize the LM358, simply insert the IC into its holder on the PCB For the SLG88104, connect the OpAmps from the SLG88104 evaluation board to the pin headers on the far left The PCB features extensive labeling to facilitate easy connections and debugging.
When constructing a voltage amplification circuit, it's advisable to use a small breadboard for organization If you are utilizing the LM358, voltage amplification is unnecessary; however, for the SLG88104, amplification is essential for optimal performance.
SLG88104 vs LM358
The SLG88104 op-amp offers significant advantages over the LM358, including reduced noise, a quicker response to input signal changes, and a smaller size Although an additional op-amp is required to amplify the voltage, this allows for a redesign of the analog PID circuit using surface mount components, resulting in a more compact design without compromising performance.
6 Taking the Analog Signal, Which Shall Control the PWM to the PWM Block in GreenPAK
The PID circuit generates an analog correction signal to regulate motor speed, aiming to achieve the zero position at 127 counts, the counter's initial value However, this analog signal cannot be directly connected to the motor driver; it must first pass through the GreenPAK to the PWM block The resulting PWM output is then utilized to effectively control and maintain the motor's speed.
I used the app note AN-1057 servo motor control as a reference to adjust the PWM block parameters
Figure 17: Matrix0 Connection for PWM Block
Figure 18: Matrix1 Connection for PWM Block
At the zero position, which is set at an initial value of 127, the motor remains in continuous oscillation and will not stop, even with minimal voltage fluctuations This oscillation can cause a count to increase or decrease To manage the state of pin 5, which supplies the PWM signal to the motor driver, I implemented a multiplexer When the motor reaches the zero-position point, the states Q0 to Q6 are set to HIGH, while Q7 is not.
In most scenarios, the output from pin 20 will be linked to the PWM block, delivering a PWM signal to the motor driver This setup guarantees that the motor will halt at the zero position within an acceptable error margin, utilizing the same control blocks designed for this purpose.
DC servo motor which needed a 1.5ms pulse at 0 degree and this multiplexer trick ensured there i s no output when the count is 127 i.e zero position
7 Choosing the Right Direction Pin to be Connected to the Motor Driver
In our revised scenario, the motor starts at the zero position When moved clockwise, it must rotate counter-clockwise to return to zero, utilizing the appropriate output speed from the PWM block, and this is reflected in the output from DFF3 Specifically, a clockwise movement generates a LOW signal sent to the motor driver, prompting the motor to rotate counter-clockwise to counteract the initial movement, and the same principle applies when moving counter-clockwise.
The motor driver PWM pin is connected to Pin 5 and the motor driver direction pin is c onnected to pin 6
8 Final System Lookout & Resources Utilization
System Block Diagram
Figure 21: System Block Diagram of Position Control
How the System Works
The motor encoder generates two outputs, pulse A and pulse B, which are essential for sending direction signals to the motor driver These pulses also activate the clocked quadrature circuit, allowing the counter to increment or decrement based on the motor's rotational direction.
● An 8-bit up/down counter is used to count the slots the disk of the motor encoder covered: up in
CW direction and down in CCW direction;
The data will be transformed into an analog signal through an external DAC, which will then be input into the analog PID circuit, with the initial counter value set as the setpoint at 127.
To achieve a stable motor speed response, it is essential to fine-tune the PID parameters of the system The resulting output from the PID controller should effectively maintain the desired motor speed, and it is important to note that this output is not a PWM signal Instead, it should be directly fed back to the GreenPAK for optimal performance.
● The analog signal will go through the ADC block then to the PWM block to output a corresponding PWM signal;
● Now we have the appropriate PWM signal and the direction signal from the direction detection circuit, which should be fed to the motor driver to correct the motor position
PID tuning is a complicated process and within the scope of the app note
This application aims to familiarize students with PID control, where trial and error serves as an effective method for tuning PID parameters By observing the system's response, students can adjust the parameters to achieve stability without overshooting or oscillations.
However, for small, low torque motors with little or no gearing, one procedure you can use to get a good baseline tune is to probe its response to a disturbance
To tune a PID use the following steps:
● Set all gains to zero;
● Increase the P gain until the response to a disturbance is steady oscillation;
● Increase the D gain until the oscillations go away (i.e it's critically damped);
● Repeat steps 2 and 3 until increasing the D gain does not stop the oscillations;
● Set P and D to the last stable values;
To achieve the desired setpoint, gradually increase the gain until it reaches the target, allowing for the preferred number of oscillations While aiming for zero oscillations is typical, a faster response can be achieved with a slight tolerance for overshoot oscillations.
The choice of disturbance depends on the mechanism connected to the controller Typically, simply moving the mechanism away from the setpoint by hand and releasing it suffices However, if the oscillations increase in amplitude, it's necessary to decrease the P gain to stabilize the system.
If you set the D gain too high the system will begin to chatter (vibrate at a higher frequency than the
P gain oscillations) If this happens, reduce the D gain until it stops
Table 1: Comparison between PID Tuning Methods
Manual tuning No math required; online Requires experienced personnel
Ziegler–Nichols Proven method; online Process upset, some trial-and- error, very aggressive tuning
Tyreus Luyben Proven method; online Process upset, some trial-and- error, very aggressive tuning
Software tools for consistent tuning, whether online or offline, utilize computer-automated control system design (CAutoD) techniques These tools facilitate valve and sensor analysis, enabling simulations prior to implementation Additionally, they support non-steady-state (NSS) tuning, enhancing overall system performance and reliability.
Some cost or training involved
The Cohen-Coon method is an effective process model primarily suited for first-order processes and involves mathematical calculations performed offline In contrast, the Åström-Hägglund approach is advantageous for auto-tuning, as it minimizes amplitude, resulting in the least process disturbance.
The process itself is inherently oscillatory
10 Modifying the System for Speed Controlling:
The speed of the motor is directly related to the number of pulses per second it generates Pulse A is decoded to create either a count up or a count down pulse In software decoding, the A output is monitored by software counters, with the counts per second being proportional to the revolutions per second of the motor.
Figure 22: Decoding Rotary Encoder for Speed Control Block Diagram
System Block Diagram
Figure 23: System Block Diagram of Speed Control
An alternative to employing a GreenPAK for PID control is utilizing an Arduino, a widely-used microcontroller among hobbyists However, the Arduino option necessitates programming skills and occupies considerably more space due to its larger size compared to a GreenPAK Moreover, GreenPAK is more cost-effective than even the most affordable Arduino models.
A software-based PID controller has its limitations, while a hardware implementation allows users to gain control over all design parameters, albeit with increased complexity in adjustments.
Sample Arduino Code
#include double Setpoint, Input, Output;
PID myPID(&Input, &Output, &Setpoint,1.002,0.0001,0.01, DIRECT);
Encoder myEnc(2, 8); long oldPosition = -999; void setup() {
Serial.begin(9600); pinMode(10,OUTPUT); pinMode(9,OUTPUT);
Setpoint = 0; myPID.SetMode(AUTOMATIC); myPID.SetOutputLimits(-254,254); myPID.SetSampleTime(60);
} void loop() { long newPosition = myEnc.read(); if (newPosition != oldPosition) { oldPosition = newPosition;
Input = myEnc.read(); myPID.Compute();
Serial.println(newPosition); if(Output > 0){ digitalWrite(10,HIGH); analogWrite(9,abs(Output));
} else{ digitalWrite(10,LOW); analogWrite(9,abs(Output));
The system was developed in distinct phases, with each component being implemented separately before integration This approach facilitated thorough debugging of the entire system, aided by the PCB design that included convenient test pins for efficient troubleshooting.
Part 1: Position and Speed Control of a DC Motor using Analog PID Controller
Part 2: Position and Speed Control of a DC Motor using Analog PID Controller
The following tests have been applied while building the educational kit:
In the unit testing phase, I systematically divided the application into smaller components, ensuring each functioned correctly I created an external circuit with 8 LEDs to test the GreenPAK up/down counter with scaling, allowing me to monitor the counter's increase while indicating motor direction through a separate LED The DAC circuit was verified according to the specifications outlined in section 4 of the application note Additionally, I constructed an analog PID circuit on a breadboard, testing it first with an Arduino's analog signal and later with input from the 8-bit DAC I also evaluated the PID output post-op-amp amplification and tested the motor driver using input PWM and direction signals from both Arduino and GreenPAK implementations.
2 Integration testing: I attached small pieces of the system to each other and tested them as design blocks
3 System testing: I tested the whole system as a black box I turned the kit on then checked the motor response with respect to the pointer movement
4 Acceptance testing: reaching the perfect parameters for stable system and noticing how changing the potentiometer’s value affect the response I used the below curves as a guide for perfect response
Figure 24: Oscilloscope Screenshot of the System Reaching a Stable System Response
Figure 25: Reference Curves for P and I Parameters
Figure 26: Final Assembly of the System before Putting it Into the Box
Figure 27: Final Appearance of the Educational Kit
This app note illustrates the process of controlling the position and speed of a DC motor, serving as an educational kit to explore the impacts of proportional, integral, and derivative control strategies It also highlights the influence of saturation, anti-windup mechanisms, and controller update rates on system stability, overshoot, and steady-state error.
The SLG46621V utilizes only a limited number of its internal blocks, preserving the majority for additional circuitry development This device exemplifies a mixed signal IC, integrating both analog and digital components in its design.
A LCD can be added later to display the PID parameter values
GreenPAK implementation eliminates the need for extra hardware or software development, making it a streamlined alternative to microcontrollers Its emphasis on hardware-driven PID control guarantees the rapid response essential for effective analog PID control.
DC motor with Rotary Encoder
● Encoder Type: Hall effect quadrature encoder 5v (monitor position and direction of rotation);
Figure 28: DC Gear Motor with Quadrature Encoder
DC Motor Driver
● Bi-directional control for 1 DC motor;
● Support motor voltage ranges from 3V to 25V;
● Maximum current up to 10A continuous and 15A peak (10 second);
● Solid state components provide faster response time and eliminate the wear and tear of mechanical relay;
● Fully NMOS H-Bridge for better efficiency No heat sink is required;
● Speed control PWM frequency up to 10KHz;
● Support both locked-antiphase and sign-magnitude PWM operation;
Figure 29: Cytron 10Amp DC Motor Driver
SLG46621V
● 8-bit Successive Approximation Register Analog-to-Digital Converter (SAR ADC);
● ADC 3-bit Programmable Gain Amplifier (PGA);
● Two Digital-to-Analog Converters (DAC);
● Twenty-Five Combinatorial Look Up Tables (LUTs);
● Three Digital Comparators/Pulse Width Modulators (DCMPs /PWMs) w/Selectable Deadband;
● Ten Counters/Delays (CNT/DLY);
● Two Pipe Delays - 16 stage/2 output;
● Two Programmable Delays w/ Edge Detection;
● Three Internal Oscillators: Low-Frequency, Ring and RC 25 kHz and 2 MHz;
SLG88104V
● Low Quiescent Current: 375 nA per Amplifier (typ);
● Rail to Rail Input/output;
● Low Offset Voltage: ±200 àV (typ);
● Low Offset Drift: 1 àV/˚C (typ);
● Gain-Bandwidth Product: 10 kHz (typ);
● Tiny Package: 20-pin 2 x 3.5 mm STQFN.
Power supply
Enclosure
The enclosure was meticulously crafted in SolidWorks, featuring various openings for essential components such as the power switch, power indication LED, data cable for emulation, LCD display, potentiometers for PID parameter adjustments, and test crocodiles for output testing.
The enclosure was made from 3mm Wood and cut by my own laser cutting machine
Figure 31: Educational Kit Enclosure Design without Openings