This action might not be possible to undo. Are you sure you want to continue?

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Using the Example of a Microchip PIC 18F4550

**Nathan Hufstetler ECE 480: Design Team 1
**

Last edited: 3 April 3, 2013

1|Page

............................................................................................................................................................................................ 3 Buck Converter............................................. 7 Variables............................................................................................................................................ 8 Appendix .......... 12 2|Page ........................................................................................ 4 Obtaining a Transfer Function ....................................................................................... 3 Plant .................................................................................................................................... 4 Tuning Method ......................................................................... 6 Programming the Microcontroller ................... 11 Glossary .......................................................................................................................................................................................................................................................................................................... 7 Pseudo code Implementation ........................................................ 11 Refrences .........................................................................................................................................................................................Contents Introduction .................................................................................................... 5 Controller ..........................................................................

In order to proceed. A buck converter is a type of voltage regulator used to step a reference voltage down to some fraction of that voltage. the basics of implementing PID control on a MCU will be covered using an example of controlling a Buck Converter to regulate voltage at an output to a load. This allows the tuning to be done via software. One way in which to digitize a controller is by writing software to a Micorcontroller Unit (MCU) and interfacing the software using one or several of the MCU’s Input Output ports. The solution for this is commonly becoming to implement the controller digitally. For this purpose a glossary has been provided in Appendix B. This combination allows for the pulse train to be smoothed into a constant voltage and current draw at the output node. However. the converter needs to first be understood and analyzed. Buck Converter In order to use the Buck converter example. the output voltage is described directly by the duty ratio as: The duty ratio is given by: 3|Page .Introduction A Proportional Integral Derivative (PID) controller is one of the most prolific methods of controlling system error which is implemented in industry today. The output voltage is determined by the duty ratio of a relay or transistor switching at some frequency “f”. and often times also allows for the tuning to become an automated process. these controllers often require a significant amount of tuning to become optimized. the reader must be familiar with certain terminology. For our example we will claim the switch is a transistor. In this Application Note. likely because it offers an engineer direct and intuitive control of both transient and steady state response. while the inductor resists changes in current. This creates a pulse train which then passes through an RLC circuit. During continuous operation. In this circuit the capacitor holds the voltage relatively constant.

The second approach would be to simply tune each parameter until the best response is reached. and T is the switching period (2). Plant There are two basic approaches to designing a controller for a system. Feedback could be given in the form of a voltage output measurement from the output node using a digital voltmeter. the first step to controlling a plant is typically finding a transfer function which describes the plant.Where thigh is the time the transistor is on. Both methods will be discussed in this section Obtaining a Transfer Function When one wishes to design a PID control for a system. This can often be the most 4|Page . Figure 1: Buck converter diagram The role of the PID controller in this system is to control the system based upon regulating the duty ratio of the relay or switch. The first of these is to obtain a model for the plant and use various design techniques to analytically find the proper gains for a PID system.

instead. For this we need only place voltage sensor at the output a feedback the voltage through an A to D converter port at the MCU.difficult task in implementing any control system. Plants can very infinitely in the number of degrees of freedom and states. the only data we are concerned with is the real time error of the system at the output. The error can then be calculated as: 5|Page . Using our example of the Buck converter. not to mention non-linear phenomena which can result. In these cases it is often better to simply tune the PID controller until a desired response is achieved. often plants it is much more involved. Tuning Method The Buck Converter was not an essentially difficult model to obtain. however. applied as a fraction determined by the duty ratio. However for most applications which would involve a microcontroller. This transfer function could again be rewritten as: This function could then be applied as the plant model as we will see in a later section. we have an RLC circuit which can be modeled by applying KCL and KVL then taking the Laplace transform to change the equation to an expression in terms of the Laplace variable s. For this scenario. these can often be reduced to a simple form based upon approximations. This yields the following transfer function(1): Simplifying gives: Since Vs is not continuously applied and.

Where e(t) is the error. These gains are typically labeled Kp. (2) 6|Page . These effects are often summarized in the following table: Steady-state error Decrease Eliminate No effect in theory Parameter Kp Ki Kid Rise time Decrease Decrease Minor change Overshoot Increase Increase Decrease Settling time Little change Increase Decrease Stability Degrade Degrade Improve for Kd is small Table 1: Effects of PID controller gains on system response. The role of each of these operations is controlled by a corresponding gain. Controller A PID controller uses Proportional. Each of these controls will mitigate error differently. When used in parallel with each other. Kd. This process will be covered in the next section. and Ki respectively. Vref is the desired voltage output and Vout is the real time output voltage as measured by the sensor. Derivative and Integral operations to attenuate tracking error in a system and obtain a desired step response. Once we have this error. the PID controller gains can be tuned until is it mitigated as we desire. these controls are modeled by the following equation(2): ∫ Where e(t) is the input error found at the output and τ is simply used a s an integration variable.

1.Programming the Microcontroller Variables The first step to implementing a PID controller on microcontroller is to define all the variables which will be used in the program. There are 4 types of errors needed for use in PID control. The following table from Microchip Technologies Inc. Offers a good summary of variables. called “a_error” in the table above. Table 2: Variables needed to implement the PID functionality on a PIC microcontroller (4) The variables with “:” are variables which span more than one memory location. and 2 suffixes). The third. The first is the current error which is calculated as described in the tuning method section.” this error is given by the difference of the previous iterations error and the current error. Be default a variable has an 8 bit length. Variables such as the error variable use two or three (hence the 0. this error is the accumulated sum of all error over many clock cycles. 7|Page . The final is the derivative error “d_error. The third is “p_error” which is the previous iterations error. These variables are large because they require higher resolution.

and finally Kd will actually be kept as a direct scale to base 10. pid_stat1&2 are variable used to call the status registers for interrupt purposes. output terms are created as 24-bit variables (deriv_#. For the purposes of the Buck converter example. two additional variables must be defined. we find the gains Kp. Other variables include: integral limiters (a_err_1_lim. These are the products which will be summed to calculate the new output. Pseudo code Implementation The general psudocode for a PID implementation is as follows (3): <Include statements> <Define all variables> Main{ While(1) { Vref=(value found from a2d port or defined internally by code) Vout =(read from a2d conversion port from voltage sensor) error = Vref – Vout a_error = a_error + error d_error = (error . Ki.previous_error) deriv = Kd*d_error integ = Ki*a_error prop = Kp*error output = prop+integ+deriv p_error = error wait(until next iteration) } } 8|Page .In addition to the errors. and Kd. spanning the range from 0 to 255. again as seen in the tuning method section of this paper. Ki will scale to represent a value between 0 and 0. a_err_2_lim) which are provided to control integrator windup resulting from saturation conditions. After the gains are multiplied by their corresponding errors. and pid_#). Kp will be scaled to represent a value from 0 to 5. and finally timer1_hi&lo are also used in ISR calling ( see reference 4). integ_#. prop_#. Vout and Vref as 16-bit variables from which the errors are calculated.1. These are 8bit variables which will be normalizations representations of each actual analog gain.

In addition to a main block. an interrupt subroutine should be defined for unfavorable conditions such and instability or integral windup. Again Microchip offers a good flow chart to capture this process: Figure 2: Flow Diagram for PID ISR.The code above gives the general implementation of a main firmware for PID control for a Buck Converter. (4) 9|Page .

This branch checks for integrator wind-up. This causes the integrator to take a long time in returning to normalcy after the saturation occurs. This branch will reset the a_error variable to the limit. This is the phenomena which occurs when the output actuator of the system has become saturated and the accumulated error in linearly increasing. 10 | P a g e . so that the PID control can more easily achieve normalcy.The most important parts of these ISRs are the branches at “Call GetA error” branch.

the controller uses the error in its calculation to find the output that will get you to the setpoint. or pressure into a digital number that a computer can process and interpret. 11 | P a g e . This electronic hardware converts an analog signal like voltage.Appendix Glossary "A to D" or A2D Converter: A to D means Analog to Digital. and most people don't use it. Derivative is the "icing on the cake" in PID control. Some manufacturers use the term rate or pre-act instead of derivative. Derivative action can compensate for a changing process variable. Error is defined as the difference between set-point and process variable. Gain (of a controller): This is another way of expressing the "P" part of the PID controller. temperature. The set-point is where you would like the process variable to be. With derivative action. GAIN = 100/(Proportional Band). the controller output is proportional to the rate of change of the process variable or error. Derivative: The "D" part of PID controllers. and pre-act are the same thing. PID Controller: Controllers are designed to eliminate the need for continuous operator attention. Derivative. Cruise control in a car and a house thermostat are common examples of how controllers are used to automatically adjust some variable to hold the process variable (or process variable) at the set-point. It can make the controller output jittery on a noisy loop and most people don't use derivative on noisy loops for this reason Error: Error = setpoint . rate. The more gain a controller has the faster the loop response and more oscillatory the process. In auto mode.PV. electric current.

edu. Available from UNSA. . 11 May 2009. (2004).microchip. April 5. Az." www.pdf 12 | P a g e . United States Naval Acadamy. .org/w/index. (2013. In Wikipedia.com/downloads/en/AppNotes/00937a.org/w/index. (2013. 2013.wikipedia. 5 Apr 2013. 2013. In Wikipedia. (2009). Web. March 31). United States Naval Acadamy. March 15).Refrences (1) Buck converter operation.wikipedia.. Microchip Technology Inc. The Free Encyclopedia. Retrieved 18:16. Retrieved 18:18.com. Informally published manuscript. (2) Buck converter. Manuscript submitted for publication.usna. (AN937)Retrieved from http://ww1.edu. .php?title=PID_controller&oldid=547984770 (4) Valenti. from http://en.php?title=Buck_converter&oldid=544237691 (3) PID controller. Chandler. April 5. from http://en. The Free Encyclopedia. Available from Microchip. Implementing a pid controller using a pic18 mcu. Retrieved from "Buck Converter Operation. C.

- TheAvionicsHandbook_Contents.pdf
- 2_006 Coursenotes.pdf
- Acc. No. DC 89
- PR11 v4
- PID Control
- Pid Control of Line Following Robot Cheu Kai Wee TJ223.P55.C43 2007
- Program to Implement Structure
- Motor Lift Power
- 0470863358
- 2013 Arduino PID Lab 0
- Micro Controller
- Thermocouple
- bf99bb5df6533b6_ek_2
- Temperature Control for Hatching Chicks
- BFY-2012 Wkshp Robinson
- 2009 Master Proposal Motor Control
- 571-230
- 92 - A Simple Substrate Heater Device With Temperature Controller for Thin Film Preparation_2
- slos099e
- EWARM_AssemblerReference.ENU
- 13_ASG_APG
- Audible Alarm Basics
- 14_AVG
- The PIC Micro Controller Book

- RegC
- 3D IC Report
- Kam All Ll Lllll Lllll
- GLI Model E53 Inductive Conductivity Analyzer Operating Manual.pdf
- 29[1].Pc Based Robot
- Project Reprt333
- ASIC by Sebastian Smith
- Asic Ppt Complete
- 85464369359011_installation
- Vlsi Important Questions
- HA350678
- Report_car Parking System
- pd2435
- unit 1
- A Short History of Computers
- Abs Tables
- Chapter 6 - Data Presentation
- Graphics5-ScanConvertingLines
- Engineering Std Dwg
- Computers
- CMOS Circuits 2010 Lecture20
- history of computer.docx
- Pulse Sensor Amped Getting Started Guide Rev 2
- Spooky Pulse Training
- THASOS. Service manual.doc
- ST L6713A
- 350 Install
- MCP4011 Digital Pot
- Force Sensitive Resistor Fsr

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd