PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

Similar documents
FFT Frequency Detection on the dspic

Android, Bluetooth and MIAC

Solar Energy Conversion using MIAC. by Tharowat Mohamed Ali, May 2011

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

LED board datasheet EB

FlowKit in-circuit debug system

ECIO40P ECIO28P ECRM40. Page 1. USB programmable microcontrollers. 0.6 DIP footprint. Supplied with a free version of Flowcode. E-blocks compatible

Switch board datasheet EB

Microcontroller-based experiments for a control systems course in electrical engineering technology

E-Blocks Easy Internet Bundle

PC BASED PID TEMPERATURE CONTROLLER

CAN bus board. EB018

E-Blocks Easy RFID Bundle

How to Turn an AC Induction Motor Into a DC Motor (A Matter of Perspective) Steve Bowling Application Segments Engineer Microchip Technology, Inc.

dspace DSP DS-1104 based State Observer Design for Position Control of DC Servo Motor

Pulse Width Modulated (PWM) Drives. AC Drives Using PWM Techniques

EE 402 RECITATION #13 REPORT

HITACHI INVERTER SJ/L100/300 SERIES PID CONTROL USERS GUIDE

Time Response Analysis of DC Motor using Armature Control Method and Its Performance Improvement using PID Controller

RS232 Board datasheet

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

Pulse Width Modulated (PWM)

Advantages of Auto-tuning for Servo-motors

MECE 102 Mechatronics Engineering Orientation

Introduction to SMPS Control Techniques

A Study of Speed Control of PMDC Motor Using Auto-tuning of PID Controller through LabVIEW

Automotive electronics CAN and LIN buses. Copyright 2006 Matrix Multimedia Limited

Accurate Measurement of the Mains Electricity Frequency

MAS.836 HOW TO BIAS AN OP-AMP

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

EXERCISE 3: String Variables and ASCII Code

Hands On ECG. Sean Hubber and Crystal Lu

Switch Mode Power Supply Topologies

Measuring Resistance Using Digital I/O

Robotics. Lecture 3: Sensors. See course website for up to date information.

INTRODUCTION TO SERIAL ARM

Technical Guide No High Performance Drives -- speed and torque regulation

Designing Gain and Offset in Thirty Seconds

Active Vibration Isolation of an Unbalanced Machine Spindle

Open Source 100kW Electric Vehicle Controller/Inverter

FAST METHODS FOR SLOW LOOPS: TUNE YOUR TEMPERATURE CONTROLS IN 15 MINUTES

dspic30f4012 Microcontroller

DC Motor with Shaft Encoder

3. Identification of water pumps through RFID technology. 4. Wireless control of remote water pump using RF technology.

Android based Alcohol detection system using Bluetooth technology

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Controller Design in Frequency Domain

Innovative Practices in Optimal Utilization of Solar Energy (Solar Tracking System)

Degree programme in Automation Engineering

Self-Balancing Robot Project Proposal Abstract. Strategy. Physical Construction. Spencer Burdette March 9, 2007

Implementation of Fuzzy and PID Controller to Water Level System using LabView

Project Plan. Project Plan. May Logging DC Wattmeter. Team Member: Advisor : Ailing Mei. Collin Christy. Andrew Kom. Client: Chongli Cai

2.0 Command and Data Handling Subsystem

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

ECE 495 Project 3: Shocker Actuator Subsystem and Website Design. Group 1: One Awesome Engineering

Chapter 19 Operational Amplifiers

Bi-directional Power System for Laptop Computers

MSc in Autonomous Robotics Engineering University of York

Force/position control of a robotic system for transcranial magnetic stimulation

EDUMECH Mechatronic Instructional Systems. Ball on Beam System

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

Closed Loop Pressure Control for the Extrusion Process

PIC Application Notes

Procedure for DAM Testing 24 Hour Energy Star DAM Power Consumption test procedure Version 1.3, 13 April 2010

Dr. Yeffry Handoko Putra, S.T., M.T

TwinCAT NC Configuration

Understanding Power Impedance Supply for Optimum Decoupling

21. PID controller SYSTEM ACTUATOR. Figure 1: A crude example for a regulation

Experiment 8 : Pulse Width Modulation

Pulse width modulation

Sensorless Field Oriented Control (FOC) for Permanent Magnet Synchronous Motors (PMSM)

Constructing a precision SWR meter and antenna analyzer. Mike Brink HNF, Design Technologist.

Process Control Primer

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

A simple method to determine control valve performance and its impacts on control loop performance

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Power Electronics. Prof. K. Gopakumar. Centre for Electronics Design and Technology. Indian Institute of Science, Bangalore.

Basics electronic speed Governor

Microcontroller based speed control of three phase induction motor using v/f method

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

2/26/2008. Sensors For Robotics. What is sensing? Why do robots need sensors? What is the angle of my arm? internal information

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

THE MECHANICS OF TENSION CONTROL By Jeff Damour CONVERTER ACCESSORY COPORATION Wind Gap, PA USA

Hand Gestures Remote Controlled Robotic Arm

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

Signal Processing in So.ware and Electric Field Sensing

Manufacturing Equipment Modeling

Dyeing Programmer DP - 01

Electronic Speed Variator for a Brushless DC Motor

How to design an insulin pump

TETRIX Add-On Extensions. Encoder Programming Guide (ROBOTC )

Controlling a Dot Matrix LED Display with a Microcontroller

DCMS DC MOTOR SYSTEM User Manual

Electrical Resonance

Dr Robot C# Advance Sputnik Demo Program

Transistor Amplifiers

Transcription:

PID Control by Ben Rowland, April 2011 Abstract PID control is used extensively in industry to control machinery and maintain working environments etc. The fundamentals of PID control are fairly straightforward but implementing them in practise can prove to be a uphill struggle. In this article we provide a clear explanation of how PID control works and also a couple of Flowcode example files designed to demonstrate how PID control is performed. Requirements Software: Professional licence of Flowcode v4 for dspic. Hardware: EB064 dspic Multiprogrammer board EB058 glcd Eblock EB022 Motor Eblock Proportional Integral Derivative (PID) Control When controlling a real system such as a motor there is normally an error between the speed you wish to drive the motor and the speed the motor is running. This is due in part to the fact that the motor will take time to respond and also due to the fact that the load on the motor can change. Adding some kind of feedback to the system allows us to essentially close the loop allowing us to control the motor, read the feedback and then adjust our output signal to suit. PID control is essentially a mechanism that is used to monitor and control a varying system, for example when we are driving along in a car our brain is automatically tracking the distance from the central line and adjusting accordingly. This type of system is known as a closed loop system as we do an action such as turn the steering wheel then monitor the response by looking at the road and then adjusting the steering wheel if necessary. Example of closed loop system using PID Page 1

The above diagram contains some terms, here are the definitions: Setpoint Desired output of the system. PID Controller System monitoring setpoint and feedback eg the brain or a microcontroller. Output The modified output from the controller. Process The action that is happening eg driving along the road. Disturbances Outside influences on the system eg turns in the road. Sensor A way of measuring how far off our setpoint we are eg our eyes. Feedback The control signal fed into the controller from the sensor. The PID equation is used a lot in control systems as it takes into account three types of feedback error. Proportional error This is the simplest form of error and simply tells us the difference between the setpoint and the feedback signal. Integral error This is used to correct any end result offset that the proportional control cannot reduce due to gain limitations by creating a rolling average of previous errors. Derivative error This uses multiple errors over time to monitor the rate of change and try to predict what is going to happen next. The basic PID function is basically a sum of all three types of error. Output = Pout + Iout + Dout An example of the PID equation using three previous error readings would look like this. Output = P * (Error Prev_Error + (Error / I) + D * (Error (2 * Prev_Error) + Prev_Prev_Error)) To calculate the errors in the above equation we are basically subtracting the sensor feedback from the control setpoint. To allow this to work effectively there has to be a way of allowing the feedback signal to be equal to the setpoint. This way when both the setpoint and the feedback match the error is zero. Here is a worked example of the above equation. Setpoint = 5 P = 2 I = 6 D = 1 (Step 1) Feedback = 0 P * (5 5 + (5 / I) + D * (5 (2 * 5) + 5)) = 10 At step 1 we are far from the setpoint so we have a large output to try and speed up the process to get to the setpoint. (Step 2) Feedback = 1 P * (4 5 + (4 / I) + D * (4 (2 * 5) + 5)) = -2.66 At step 2 we are predicting that the setpoint will shortly be reached so we are backing off the control signal slightly from 10 to 7.34. Page 2

(Step 3) Feedback = 2 P * (3 4 + (3 / I) + D * (3 (2 * 4) + 5)) = -1 At step 3 we are nearing the setpoint so the control signal tries to back off more to avoid overshooting the setpoint and changes from 7.34 to 6.34. A system controlled by PID requires tuning to make the system stable and achieve the fastest possible response to the control signal. To aid in this we have generated an Excel spreadsheet that simulates a second order system such as a DC motor. Different values for the P, I and D control values can be tested and the starting point and setpoint can be altered for any given situation. It is normally fairly simple to see if a system is going to respond well or become unstable as long as you have the system characteristics modelled correctly.tuning a system can often be fairly hard to do without loads of trial and error. There are ways to allow the PID system to tune itself but these systems are often said to be teetering on the unstable side and the slightest unpredicted error can cause lots of problems. Example stable system using P=2 I=6 and D=1 1200 1100 1000 900 800 700 600 500 400 300 200 100 0 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 Example unstable system using P=8 I=4 and D=4 1200 1100 1000 900 800 700 600 500 400 300 200 100 0 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 A reactive PID system should aim for a little overshoot before settling down. Rule of thumb values are that P is roughly equal to I and D is roughly one quarter the value of I. Page 3

The first example uses my integer based PID calculation to simulate this second order system on hardware. To do this I am using the EB064 - dspic and PIC24 Multiprogrammer E-block along with a EB058 graphical LCD. The program creates a random setpoint between 0 and 100 which it draws as a red line and then plots the response of the PID algorithm. Here we can see the differences between our excel calculation and our microcontroller based integer only calculation. It should be possible to see that the discrete sampled system is a lot more prone to becoming unstable due to fractional errors in the equation. A B C A: Example stable system using P=2 I=6 and D=1 B: Example stable system with ringing using P=6 I=6 and D=2 C: Example unstable system P=6 I=3 and D=2 Now that we can simulate a PID control signal how about applying it in practise. To do this I am using a new style NXP Lego DC motor but the same method can be applied to just about any system that can be effected by the surroundings with outputs that can be measured, e.g. room temperature, motor speed, motor position, generator output, voltage charge pumps etc. The next example shows how to apply the PID algorithm by using actual feedback to control the error signals rather than using a simulated error. To start you first need to determine the range of your control signal. I will be using PWM to control the speed of a Lego DC motor. The PWM input is a byte so this can go between 0 and 255 where 0 is the motor is stopped and 255 is the motor at full speed. To feed error back into the system I will be using the opto-encoder fitted inside the motor to measure its speed. Again I will let the program pick random setpoints and plot the response of the algorithm onto the graphical display. The running program controls the motor and will try to maintain a steady speed to match the setpoint even if the load on the motor changes significantly. The feedback signal from the Lego motor is fairly good but not amazing and therefore the control of the motor is not perfect, though obviously far better than using normal open loop control. Using a shaft encoder with a greater resolution would allow for a better motor response. To get the encoder feedback to approximately equal the setpoint to generate a 0 error I have measured the encoder response when the motor is at full speed. Doing this I found that a speed of 255 represented an encoder frequency of around 125 cycles in 25ms. Therefore to normalise the feedback signal I simply multiplied it by 2 before calculating the error and then plugging this into the PID equation which runs every 25ms. Page 4

This motor was taken from a industrial robotic camera and uses a tacho as the source of feedback rather than an encoder. The tacho gives us an analogue signal that is proportional to the rotational speed of the motor. So to monitor the error from a motor like this a potential divider circuit would be used to get the tacho signal as close as possible to the control signal when read in through an ADC. The examples in this article were written for the dspic30f2011 device that comes as standard with the EB064 PIC24 and dspic E-block. By using the import file menu the programs should work equally well with other versions of Flowcode and other devices. The PID algorithm also could be improved by using floating point calculations rather than integer based calculations though this would have an impact on the speed of the PID routine as well as the amount of code that is generated. In practise the integer based PID algorithm is working well. Further reading Below are some links to other resources and articles on related subjects, and technical documentation relating to the hardware used for this project... Flowcode: Eblocks: Learning Centre: User Forums: Product Support: http://www.matrixmultimedia.com/flowcode.php http://www.matrixmultimedia.com/eblocks.php http://www.matrixmultimedia.com/lc_index.php http://www.matrixmultimedia.com/mmforums http://www.matrixmultimedia.com/sup_menu.php Copyright Matrix Multimedia Limited 2011 Flowcode, E-blocks, ECIO, MIAC and Locktronics are trademarks of Matrix Multimedia Limited. PIC and PICmicro are registered trademarks of Arizona Microchip Inc. AVR, ATMega and ATTiny are registered trademarks of the ATMEL corporation. ARM is a registered trademark of ARM Ltd. Page 5