The Embedded System. - Development and analysis of an Embedded DC-motor controller - by Embedded System Team

Similar documents
Rotary Motion Servo Plant: SRV02. Rotary Experiment #02: Position Control. SRV02 Position Control using QuaRC. Student Manual

Lab 11. Speed Control of a D.C. motor. Motor Characterization

Sfwr Eng/TRON 3DX4, Lab 4 Introduction to Computer Based Control

Laboratory Assignment 5 Digital Velocity and Position control of a D.C. motor

Penn State Erie, The Behrend College School of Engineering

MEM01: DC-Motor Servomechanism

2.017 DESIGN OF ELECTROMECHANICAL ROBOTIC SYSTEMS Fall 2009 Lab 4: Motor Control. October 5, 2009 Dr. Harrison H. Chin

Feedback Systems. Many embedded system applications involve the concept of feedback. Sometimes feedback is designed into systems: Actuator

Rotary Motion Servo Plant: SRV02. Rotary Experiment #03: Speed Control. SRV02 Speed Control using QuaRC. Student Manual

CHAPTER-III MODELING AND IMPLEMENTATION OF PMBLDC MOTOR DRIVE

Lab 2: Quanser Hardware and Proportional Control

EE 461 Experiment #1 Digital Control of DC Servomotor

Laboratory Assignment 1 Sampling Phenomena

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

Electrical Drives I. Week 4-5-6: Solid state dc drives- closed loop control of phase controlled DC drives

Digital Control of MS-150 Modular Position Servo System

Ball Balancing on a Beam

EE 3TP4: Signals and Systems Lab 5: Control of a Servomechanism

TODO add: PID material from Pont slides Some inverted pendulum videos Model-based control and other more sophisticated

SRV02-Series Rotary Experiment # 3. Ball & Beam. Student Handout

RAPID CONTROL PROTOTYPING FOR ELECTRIC DRIVES

Advanced Servo Tuning

UNIT 2: DC MOTOR POSITION CONTROL

Sensors and Sensing Motors, Encoders and Motor Control

Linear Motion Servo Plants: IP01 or IP02. Linear Experiment #0: Integration with WinCon. IP01 and IP02. Student Handout

REAL-TIME LINEAR QUADRATIC CONTROL USING DIGITAL SIGNAL PROCESSOR

Servo Tuning. Dr. Rohan Munasinghe Department. of Electronic and Telecommunication Engineering University of Moratuwa. Thanks to Dr.

dspace DS1103 Control Workstation Tutorial and DC Motor Speed Control Project Proposal

Development of a MATLAB Data Acquisition and Control Toolbox for BASIC Stamp Microcontrollers

DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING BANGLADESH UNIVERSITY OF ENGINEERING & TECHNOLOGY EEE 402 : CONTROL SYSTEMS SESSIONAL

Automatic Control Systems 2017 Spring Semester

Motor Control. Suppose we wish to use a microprocessor to control a motor - (or to control the load attached to the motor!) Power supply.

Feedback Devices. By John Mazurkiewicz. Baldor Electric

ECE 5670/6670 Project. Brushless DC Motor Control with 6-Step Commutation. Objectives

Sensors and Sensing Motors, Encoders and Motor Control

Ball and Beam. Workbook BB01. Student Version

Root Locus Design. by Martin Hagan revised by Trevor Eckert 1 OBJECTIVE

Lab 2: Introduction to Real Time Workshop

Fundamentals of Servo Motion Control

Optimal Control System Design

Embedded Control Project -Iterative learning control for

Department of Electrical Engineering

JUNE 2014 Solved Question Paper

Lab 23 Microcomputer-Based Motor Controller

Cantonment, Dhaka-1216, BANGLADESH

Latest Control Technology in Inverters and Servo Systems

CHAPTER 4 CONTROL ALGORITHM FOR PROPOSED H-BRIDGE MULTILEVEL INVERTER

Design and Implementation of an Inverted Pendulum Controller to be used as a Lab Setup

Module 08 Controller Designs: Compensators and PIDs

Design of stepper motor position control system based on DSP. Guan Fang Liu a, Hua Wei Li b

SRV02-Series. Rotary Servo Plant. User Manual

Comparisons of Different Controller for Position Tracking of DC Servo Motor

Closed-Loop Transportation Simulation. Outlines

Design of a Simulink-Based Control Workstation for Mobile Wheeled Vehicles with Variable-Velocity Differential Motor Drives

Implementation of discretized vector control strategies for induction machines

Open Loop Frequency Response

AC : A STUDENT-ORIENTED CONTROL LABORATORY US- ING PROGRAM CC

dspace DS1103 Control Workstation Tutorial and DC Motor Speed Control Project Report

Loop Design. Chapter Introduction

A PID Controller for Real-Time DC Motor Speed Control using the C505C Microcontroller

Modeling, Simulation and Implementation of Speed Control of DC Motor Using PIC 16F877A

Analog I/O. ECE 153B Sensor & Peripheral Interface Design Winter 2016

Page ENSC387 - Introduction to Electro-Mechanical Sensors and Actuators: Simon Fraser University Engineering Science

Interfacing dspace to the Quanser Rotary Series of Experiments (SRV02ET)

Step vs. Servo Selecting the Best

Hydraulic Actuator Control Using an Multi-Purpose Electronic Interface Card

A HARDWARE DC MOTOR EMULATOR VAGNER S. ROSA 1, VITOR I. GERVINI 2, SEBASTIÃO C. P. GOMES 3, SERGIO BAMPI 4

Lecture 11. Phase Locked Loop (PLL): Appendix C. EE4900/EE6720 Digital Communications

A COMPARISON STUDY OF THE COMMUTATION METHODS FOR THE THREE-PHASE PERMANENT MAGNET BRUSHLESS DC MOTOR

User Guide IRMCS3041 System Overview/Guide. Aengus Murray. Table of Contents. Introduction


University of California, Berkeley EE128, Fall Lab 7 A Microcontroller Based Position/Speed Controller

ECE 5670/ Lab 6. Parameter Estimation of a Brushless DC Motor. Objectives

The Air Bearing Throughput Edge By Kevin McCarthy, Chief Technology Officer

EE 4314 Lab 3 Handout Speed Control of the DC Motor System Using a PID Controller Fall Lab Information

A Real-Time Platform for Teaching Power System Control Design

The Discussion of this exercise covers the following points: Angular position control block diagram and fundamentals. Power amplifier 0.

MAE106 Laboratory Exercises Lab # 5 - PD Control of DC motor position

1. To study the influence of the gain on the transient response of a position servo. 2. To study the effect of velocity feedback.

Volume 1, Number 1, 2015 Pages Jordan Journal of Electrical Engineering ISSN (Print): , ISSN (Online):

7 Lab: Motor control for orientation and angular speed

FPGA Implementation of a PID Controller with DC Motor Application

Elements of Haptic Interfaces

Chapter 5. Tracking system with MEMS mirror

Paul Schafbuch. Senior Research Engineer Fisher Controls International, Inc.

Design of double loop-locked system for brush-less DC motor based on DSP

Motor Modeling and Position Control Lab 3 MAE 334

Experiment Of Speed Control for an Electric Trishaw Based on PID Control Algorithm

Lecture 2 Exercise 1a. Lecture 2 Exercise 1b

A Case Study of Rotating Sonar Sensor Application in Unmanned Automated Guided Vehicle

Microcontroller Based Closed Loop Speed and Position Control of DC Motor

UNIVERSITY OF JORDAN Mechatronics Engineering Department Measurements & Control Lab Experiment no.1 DC Servo Motor

Continuous Time Model Predictive Control for a Magnetic Bearing System

CHAPTER 2 PID CONTROLLER BASED CLOSED LOOP CONTROL OF DC DRIVE

Modelling and Simulation of a DC Motor Drive

A PID Controlled Real Time Analysis of DC Motor

University of California at Berkeley Donald A. Glaser Physics 111A Instrumentation Laboratory

Figure 1: Unity Feedback System. The transfer function of the PID controller looks like the following:

BLuAC5 Brushless Universal Servo Amplifier

A Searching Analyses for Best PID Tuning Method for CNC Servo Drive

Transcription:

The Embedded System - Development and analysis of an Embedded DC-motor controller - by Robert Eriksson Nicklas Lundin Mehiar Moukbel Ronnie Sjödin Thomas Wahlström 2E1242, Project Course Automatic Control at The Royal Institute of Technology (KTH) Stockholm, May 2004

2E1242, Project Course in Automatic Control i Abstract In the spring of 2004 the project Embedded System was active. The project goal was to develop and analyse an Embedded DC-motor controller with emphasis on the lateral. As a part of the developing process the DC-motor was externally controlled using dspace. When programming the processor the greatest limitation was the available memory and not the processor calculation time. Due to the memory limitation a simple PD-controller was developed and tested for different sampling time, interrupts and perturbations. Due to its simplicity, the controller and its high sampling time, the processor could still, although interrupted and perturbated, stabilize the system.

2E1242, Project Course in Automatic Control ii Contents 1 Introduction 1 1.1 Background............................ 1 1.2 Problem definition........................ 1 1.3 Solution proposition....................... 1 2 Equipment 2 2.1 Hardware............................. 2 2.1.1 DC-motor......................... 2 2.1.2 Inputs........................... 3 2.1.3 Outputs.......................... 3 2.1.4 Serial port......................... 3 2.1.5 PIC............................ 3 2.1.6 dspace DS1104 board................. 4 2.2 Software.............................. 4 2.2.1 Matlab/SIMULINK.................... 4 2.2.2 Real Time Workshop/dSPACE............. 4 2.2.3 PCWH compiler..................... 4 2.2.4 PIC Downloader..................... 4 2.2.5 Hyperterminal....................... 4 3 Theory 5 3.1 The continuous closed loop system............... 5 3.1.1 Open loop transfer function............... 5 3.1.2 PD-controller....................... 6 3.2 The discrete closed loop system................. 7 3.2.1 The discrete open loop system.............. 7 3.2.2 Discretizing the PD-controller.............. 8 3.2.3 Discretizing the closed loop system........... 8 4 Execution 9 4.1 Simulation dspace....................... 9 4.1.1 Building a continuous PD-controller........... 9 4.1.2 Evaluating the continuous PD-controller........ 10 4.1.3 Building a discrete PD-controller............ 10 4.1.4 Evaluating the discrete PD-controller.......... 10 4.2 Embedded processor control................... 12 4.2.1 Function libraries..................... 12 4.2.2 Building an embedded PD-controller.......... 12 4.2.3 Processor scheduling................... 15

2E1242, Project Course in Automatic Control iii 5 Conclusions 15 6 Bibliography 17

2E1242, Project Course in Automatic Control 1(17) 1 Introduction As a part of the project course in automatic control between 9th of March an the 18th of May of 2004 the course participants was divided into five groups with different projects. One of these five projects was the Embedded System - the development and analysis of an Embedded DC-motor controller. 1.1 Background The (EST) received an order from Mr Johansson with the specifications to create an automatic controller to control the angle of a DC-motor shaft. The controller should be implemented in an embedded microprocessor. Detailed analysis of the implementation should be provided, which should illustrate both the trade-off between control performance and CPU-time and the importance of quick application of controller output. 1.2 Problem definition In cooperation with the project consultant Oscar Flärdh the team defined the problem as follow. Create an application which from the embedded processor control the DCmotors rotor angle from an extern given angle. The application will, with focus on the control algorithm and its implementation, be analyzed and optimized for best control performance. 1.3 Solution proposition The solution consists of three main parts. The QIC is going to be controlled using dspace to get control values to compare with the performance on the processor. A function library is going to be built to simplify the encoding of control algorithms. Last optimizing of the control algorithm for best control performance considering the processor s capacity will be made. Of these parts the function library will be the most time consuming due to the complexity of programming a processor.

2E1242, Project Course in Automatic Control 2(17) 2 Equipment In the following section all equipment used in the project will be describe. The equipment has been dived into two main areas: hardware and software. 2.1 Hardware To be able to understand which part of the hardware each section is handling, here are some definitions. QIC is the name of the entire board consisting of the DC-motor and the processor PIC. 2.1.1 DC-motor The graphite brush Maxon DC-motor is powered by a linear power amplifier which can be controlled, either from the PIC, see section 2.1.5, or from a dspace DS1104 board, see section 2.1.6, through the Command input. The way of controlling the motor is selected with the jumper switch J6, see figure 1. Figure 1: The QIC board

2E1242, Project Course in Automatic Control 3(17) 2.1.2 Inputs Only one input is available, the Command input. It is fed by the dspace DS1104 board and is either controlling the DC-motor directly or giving external inputs to the PIC. This input has a range of ±5V. 2.1.3 Outputs Five outputs are available: The Potentiometer output measures the angle of the DC-motor shaft. The output signal is in the range of ±5V. It is a linear output, hence 180 o equals 5V and 180 o equals 5V. This means that when the rotor angle exceeds 180 o, the output jumps from 5V to 5V. The Tachometer output measures the speed of DC-motor rotor. The output signal is in the range of ±5V. This proportional sensor has a sensitivity of 1.5V/1000RP M. A clock-wise rotation generates a positive voltage and counter clock-wise rotation a negative voltage. The Current sensor measures the current from the Power amplifier. The output voltage is proportional to the current supplied to the DCmotor. It has sensitivity of 1.8V/A. The D/A output can only be used when the QIC processor core is controlling the DC-motor. This output is used to supervise the control signal. The rotary Encoder output is a digital positioning measurement (can not be used by dspace, no input). Note: The potentiometer, the tachometer and the current meter are all scaled and shifted from the range 5 V to 5 V to the range of 0 V to 5 V before entering the PIC. 2.1.4 Serial port The RS232 Serial port is used to communicate with the PIC. Software is downloaded and processes can be supervised through this port. The processor can also receive external instructions through this port while running. 2.1.5 PIC A programmable processor capable of controlling a process attached from any external controller. All external available measurements are also available for the PIC without any wiring required.

2E1242, Project Course in Automatic Control 4(17) 2.1.6 dspace DS1104 board The external hardware interface which allows a computer to communicate with the process. The board has eight BNC analog inputs and eight BNC analog outputs. 2.2 Software In the following section the software used in this project will be commented. 2.2.1 Matlab/SIMULINK Generate and build controllers which can be applied on the process to simulate different scenarios and calculate time delay and sampling frequencies. 2.2.2 Real Time Workshop/dSPACE The dspace software Control Desk and the dspace board allow communication with the QIC when using Real Time Workshop, RTW. Hence simulation can be done directly on the physical process involving virtual instrument building, meaning there is no need to build a model of the process. RTW transforms the controller from a SIMULINK block model to dspace. 2.2.3 PCWH compiler This program compiles all the c-code in to hex-code 1 which the PIC can handle. 2.2.4 PIC Downloader This program is the serial bootloading program. Once you have programmed the PIC with a bootloader, you can use this program for programming the PIC through the serial port. 2.2.5 Hyperterminal The add on Windows program Hyperterminal is used on the computer for serial communication with the PIC. 1 Assembler code for the processor

2E1242, Project Course in Automatic Control 5(17) 3 Theory The theoretical part of this project is divided into two parts: the continuous and the discrete closed loop system. 3.1 The continuous closed loop system This section describes how the parameters K p and K d is calculated. 3.1.1 Open loop transfer function Basics from electrical 2 and mechanical 3 engineering results in the following equations, that can be seen as the open loop equations of the DC-motor. V m = I m R m + K m ω m (1) T m = K τ I m = J l ω m (2) where V m : motor terminal voltage [V ] I m : motor current [A] R m : motor resistance [Ω] K m : motor torque constant [Nm/A] ω m : motor shaft speed [rad/s] T m : torque [Nm] K τ :back emf constant [Nm/A] J l : load inertia [kgm 2 ] Starting by deriving the open loop transfer function of the motor, G o, from voltage to motor position. After insertion of known values and simplification the equation gives G o (s) = θ(s) V m (s) = K m s(r m (J m + J l )s + Km) = 19.6 2 s(0.0566s + 1) where θ(s) is the angle of the motor shaft and J m is the motor inertia. (3) This second order system is not open loop stable due to the fact that there exists a pole in the origin. Now a PD controller is designed which will stabilize the system and allow the user to give position of the motor shaft. The system should track the desired position while minimizing the steady state error with consideration of the overshoot and the rise time. 2 Kirchoff s first law 3 The definition of momentum

2E1242, Project Course in Automatic Control 6(17) 3.1.2 PD-controller The model of the DC-motor includes an integral part which gives that a PDcontroller is sufficient to control the system. By having this built in integral part the steady state error converge to zero. The implemented controller is given on the form where V m = (K p + sk d )(θ θ d ) = K p (θ θ d ) + K d dθ dt (4) K p : proportional gain [V/rad] K d : derivative gain [V/(rad/s)] θ: shaft angle [rad] θ d : angle command [rad] The closed loop transfer function, G c, is given by G c (s) = θ(s) θ d (s) = K m K p (R m J m + R m J l )s 2 + (K 2 m + K m K d )s + K m K p (5) where the denominator can be written on the form s 2 + 2ζω 0 + ω 2 0 (6) where ζ is defined as the damping coefficient and ω 0 is the natural frequency. These parameters, ζ and ω 0, are used as tuning parameters which alters the systems dynamic with respect on the step response dynamics 4. By choosing reasonable values of ζ = 0.5 and ω 0 = 29 rad/s the rise time becomes 58 ms with an overshoot and settling time of M = 14% and T settling = 180 ms. The controller coefficients, K p and K d, were calculated according to resulting in K p = 2.69 and K d = 0.0462. K p = ω2 0R m (J m + J l ) K m (7) K d = 2ζω 0R m (J m + J l ) K 2 m K m (8) 4 overshoot, rise, settling time, etc

2E1242, Project Course in Automatic Control 7(17) 3.2 The discrete closed loop system Sampling a time continuous system results in a discrete system which is dependent of the sampling time T s. The sampling frequency must be chosen in such a way that the sampled system will have its poles and zeroes inside the unit circle to assure stability. Using a high sampling frequency will lead to a system that is almost continuous in its characteristics, while a too low sampling frequency will lead to instability of the system. In this case the sampling time was chosen to 10 ms resulting in very acceptable system properties. The border around 50 ms, corresponding to sampling frequency of 20 Hz, will lead to instability. 3.2.1 The discrete open loop system First the continuous time system is written in its state space form with x 1 = y and x 2 = ẏ. This results in the following continuous state space system ẋ(t) = Ax(t) + Bu(t) (9) y(t) = Cx(t) (10) where A = ( 0 1 0 0.0556 ), B = ( 0 19.6 ), C = ( 1 0 ) The eigenvalues of the matrix A gives one pole in s = 0 and another in s = 0.0556. The pole in the origin gives oscillation in the system. By sampling the state space continues time system gives a discrete time system written as where x(n + 1) = Φx(n) + Γu(n) (11) y(n) = Cx(n) (12) Φ = e At, Γ = T 0 e At Bdt

2E1242, Project Course in Automatic Control 8(17) The second order discrete transfer function H d (q) is now given by H d (q) = C(qI Φ) 1 Γ (13) meaning that the system has two poles and one zero as 3.2.2 Discretizing the PD-controller H(z) = a 1z + a 2 z 2 + b 1 z + b 2 (14) The discrete time controller H c (z) will be calculated using Euler backward method, where s is replaced by s as where T s is the sampling time. s = z 1 zt s (15) The PD-controller, H c (z), is be given by 3.2.3 Discretizing the closed loop system H c (z) = K p + K d z 1 zt s (16) The closed loop discrete time system is finally given by G(z) = H(z)H c(z) 1 + H(z)H c (z) (17) where H(z) and H c (z) are the discrete system and the discrete time PDcontroller as given in equation 14 and 16. The system is a third order system which means that it has three poles and two zeros.

2E1242, Project Course in Automatic Control 9(17) 4 Execution The execution of this project is performed in two steps. First the process is controlled externally through the dspace interface to get a performance reference for future controllers and model verification. The second step is to implement the controller onto the processor and evaluate it. To be able to compare control performance, measurements are performed using a step response, equivalent to rotate the motor shaft 90 degrees. To evaluate control performance the overshoot is fixed to a maximum level, see section 3.1.2, and the system rise time and settling time are measured. 4.1 Simulation dspace The dspace software is used to externally control the process. By designing a controller in SIMULINK, using the potentiometer output on the QIC board as a feedback signal and the command input as a control signal, a closed-loop system is created. Hence, the controller is simulated but uses data from the real process to calculate its output. 4.1.1 Building a continuous PD-controller A PD-controller based on results derived in section 3.1.2 is designed in SIMULINK. The controller is presented in figure 2. Scaling due to the dspace-motor interface is not included in the figure but accounted for in the simulation. The scaling factor is π/5. Figure 2: PD-controller used in dspace

2E1242, Project Course in Automatic Control 10(17) 4.1.2 Evaluating the continuous PD-controller To evaluate the performance of the closed-loop system the step response is analyzed. The result of the system is shown in figure 3. 120 100 80 angle/degrees 60 40 20 0 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 time/s Figure 3: Step response for the externally controlled process Measuring performance data gives T r = 53ms, M = 16% and T settling = 150ms. Comparing these values to the ones derived in section 3.1.2 gives a satisfactory result and therefor validates the possibility to evaluate the process through a discrete SIMULINK-controller. These values will also be used as a reference when developing the real embedded processor controller. 4.1.3 Building a discrete PD-controller To simulate a discrete controller dspace is used. The flexibility in this software makes it easy to change controller parameters and evaluate performance before implementing the controller onto the processor. To model a discrete controller a zero-order-hold block is added to the output of the controller model and the input signal is sampled. 4.1.4 Evaluating the discrete PD-controller When controlling the process using a discrete PD-controller in dspace the sampling time is chosen below 20 ms to get the system stable. If the system should reach the same performance as the continuous system the sampling

2E1242, Project Course in Automatic Control 11(17) time must be chosen at least 10 ms, due to the rule of thumb that at least four to ten sample should be in the rise time. The step response for the two cases is illustrated in figures 4 and 5. 140 120 100 80 angle/degrees 60 40 20 0 20 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 time/s Figure 4: Discrete controller simulated with T s = 20 ms The control performance for the controller when using T s = 20 ms is M = 36%, T settling = 220 ms, T r = 50 ms 120 100 80 angle/degrees 60 40 20 0 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 time/s Figure 5: Discrete controller simulated with T s = 10 ms and for the controller using T s = 10 ms is M = 18%, T settling = 175 ms, T r = 50 ms.

2E1242, Project Course in Automatic Control 12(17) 4.2 Embedded processor control The embedded controller is written in C-code and the PCWH Compiler, see section 2.2.3 is used to convert it to assembler code. The assembler code is then downloaded into the processor using the PIC Downloader software, see section 2.2.4. 4.2.1 Function libraries To simplify the controller development in C-code a library of functions and macros is created. The QIC has two onboard devices which can be accessed by the PIC. These are the D/A chip which can be set to work as an encoder or a digital to analog converter, DAC. Using the DAC enables the PIC to write a 12 bit value trough an 8 bit bus to the amplifier. The function initda() is created such that the D/A chip sets to DAC mode. The bus is attached to a port on the PIC. Reading and writing to this port enables the user to access the D/A chip. Since the bus can carry only 8 bits, the data segment has to be divided into two 8 bit values, high bit and low bit. The function w2da() accepts a 12 bit value, and writes the two data parts to a data register enabling the D/A chip to write to the amplifier. To allow the signal to pass from the potentiometer to the PIC via the 10 bit A/D converter, the function initad(c) initiates the input pins and allows reading from the requested pin c. The main program that is downloaded onto the PIC uses the function req angle() which demands the user to give the system a reference signal. The reference signal, an angle, is entered in the Hyperterminal window, see section 2.2.5 which is attached to the PIC trough the serial port. 4.2.2 Building an embedded PD-controller Implementing an embedded controller requires effective programming. When constructing a controller or program for a conventional PC, effective programming is of less importance. However, when programming for a DSP or a processor with strictly limited resources, like this embedded processor, several processor properties has to be accounted for. The greatest limitation in this processor was found to be its programming memory. The used compiler, the PCWH Compiler, see section??, calculates used percentage program-

2E1242, Project Course in Automatic Control 13(17) ming memory when compiling. The memory usage and the total calculation time of an algorithm is used to decide how effectively the program is written. Variable declaration is a crucial part when writing effective programs. By not using more variables than necessary and, most important, not using more memory demanding variable types 5 than the application need, a lot of memory can be saved. The result of an effective algorithm is presented in figure 6. The algorithm is very fast and uses a sampling time of T s = 5 ms. The actual control algorithm is so fast that its running time can not be measured with precision, it is approximated to 0.25 ms between reading and writing. This can be compared with one of the first, non optimized controller, which had a running time of approximately 1.5 ms and required more than twice as much memory. 120 100 80 angle/degrees 60 40 20 0 20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 time/s Figure 6: Embedded controller with T s = 5 ms This embedded controller has control performance M = 14%, T r = 65 ms, T settling = 225 ms. Comparing these results with controlling with dspace, the rise time and settling time are worse. Due to the strictly limited memory of the processor, the algorithm is written with integer variables. This means that all K p and K d values can not be represented, so an overshoot M = 18% cannot be constructed. A larger overshoot and faster rise time can be accomplished, but for this application a lower overshoot has been chosen. This 5 char, int, long, floats etc.

2E1242, Project Course in Automatic Control 14(17) results in a controller, not exactly like the dspace controller. Experimenting with higher sampling time results in a high-sampling-time limit. When using T s = 20 ms the system has very bad control performance, but is still stable. This is derived in section 3.1.2 showing that a stable system requires T s < 50 ms. Although, to get acceptable control performance the sampling time should be chosen as T s < 10 ms. In figure 7 and 8 the result is shown for the two limit value cases. 150 100 angle/degrees 50 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 time/s Figure 7: Embedded controller with T s = 20 ms The control performance when using T s = 20 ms it gives M = 62%, T r = 56 ms and T settling = 500 ms 120 100 80 angle/degrees 60 40 20 0 20 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 time/s Figure 8: Embedded controller with T s = 10 ms and for T s = 10 ms is M = 25%, T r = 54 ms and T s = 250 ms

2E1242, Project Course in Automatic Control 15(17) 4.2.3 Processor scheduling Since the processor is quite powerful for this controller, other applications could be run simultaneously with it. This means that processor scheduling has to be accounted for. The chosen sampling time can be created by inserting a delay after the output-writing. This is how an interrupt is modelled, i.e. the control algorithm has the highest priority. By inserting a delay before the writing process two things can be achieved. Either a model of a higher priority task than the controller or a model of inefficient written, time consuming code. Several possible situations has been tested. The controller being interrupted often by a short task at high frequency, being interrupted by longer tasks at lower frequency and situations in between. Looking at a controller with the quite low sampling time of T s = 5 ms all these situations are handled with very good result. The controller can handle a couple of missed samples without becoming unstable. However, this is heavily affected by at which time the interrupt is called. When the same tests as above is performed using a controller with T s = 10 ms the result also is satisfactory. Performance is though degraded more than in the previous case which is even more emphasized when using a controller with T s = 20 ms. These tests have also shown that, when the controller is interrupted before it has written its output, it is better to write the delayed output than ignoring it. But it would be even better to start over if interrupted. 5 Conclusions The main conclusion of this project is that, for controlling the angle of the DC-motor shaft, the greatest limitations of the processor lies in its small programming memory capacity. The processor is more than fast enough for the controller. The implemented controller has therefor been designed to be fast and consume as little programming memory as possible. Since the processor is fast, there is no problem having a short sampling time. The used controller is of PD type. This is a rather simple controller, but compensating this with a short sampling time enables the controller to use little valuable programming memory, giving room for other applications to be run on the processor as well. Coding a fast algorithm requires restricted use of variables. Using a larger

2E1242, Project Course in Automatic Control 16(17) variable type than necessary costs processing time, but most important in this case, programming memory. The requirements on the controller was set to have a rather small overshoot and a quite fast rise time. This is possible to achieve even when using a longer sampling time, but when the controller is supposed to handle delays due to interrupts and other perturbations, a shorter sampling time gives better control performance. Hence, the fast processor enables the use of a low sampling time, giving the programmer the possibility to give the controller a rather low priority when scheduling the tasks, and still get good control performance.

2E1242, Project Course in Automatic Control 17(17) 6 Bibliography QIC Processor core V16 User s Manual Quanser consulting Inc., 2002 Engineering Trainer, DC-motor Control user guide Quanser consulting Inc., 2002 Engineering Trainer, DC-motor Control qkinterface Quanser consulting Inc., 2002 Installing and Configuration Guide, Release 3.4 dspace GmbH, 2002 Implementation Guide, Release 3.4 dspace GmbH, 2002 Design and Implementation of an Embedded Real-Time System Master Thesis by Paul Cedwall, 2003 The Not So Short Introduction to L A TEX2e Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl, 2003 Reglerteknik, Grundläggande teori Torkel Gladh and Lennart Ljung, 1989 Reglerteknik, Flervariabla och olinjära metoder Torkel Gladh and Lennart Ljung, 2003