You are on page 1of 7

Embedded Systems Interfacing

Fall 2008

jeg

Feedback Speed Control


Purpose:
To learn how to control the speed of a DC Servomotor under various load and gain conditions.

Background:
This laboratory exercise will require an exposure to control system theory. In that Computer Engineering students in this course have not had a formal course in control system theory we will base our discussion on the course of Signals & Systems.
P W M D R I V E R

Speed Reference (Internal)

Error

Control Algorithm
PIC24FJ128CA010

DC Servo Motor

Speed

Tachometer Output

Frequency to Voltage Converter


Figure 1 Speed Control System The system will consist of the Explore-16 with PICTail Protoboard, an LM2906 Frequency-to-Voltage converter, a TD62003AP Darlington Sinking Driver to power the motor, and the 429A6004 DC servomotor. These are assembled into the control system of Figure 1. We need to model the DC servomotor and the frequency-to-voltage converter. For experience with the previous laboratory exercise we know the servomotor may be modeled using one dominant pole. The transfer function for this is: Equation 1 Single Dominate Pole

P( s) =

B 1+ A s

The values of B and A should have been determined in the previous laboratory exercise via the Open-Loop StepResponse. The next step is to decide what control algorithm should be used that is easy to implement, makes the system reasonable responsive, and keeps the system stable. These topics constitute a great deal of time in Controls I and Controls II. You will not be asked to make the decision but only to observe the results of the decisions made for you. We will use a Proportional-Integral or PI controller were the signal applied to the motor is proportional to the desired speed and the integral of the error between desired and actual speed.

Embedded Systems Interfacing

Fall 2008

jeg

R(z)

E(z)

_k(z-b)___ z(z-1)

U(z) DAC

U(s)

B_ (s+A)

Y(s) ADC

Y(z)

Figure 2 Proportional-Integral Speed Control System In the z-domain the PI controller is: Equation 2 z-Domain PI Controller
C( z) = U (z ) k (z b ) = E (z ) z (z 1) )

This z-domain controller can be translated to the following difference equation. Equation 3 Control Algorithm
U ( z ) k (z b ) = E ( z) z (z 1) U ( z ) kz kb = E ( z) z2 z z 2 U ( z) z U ( z) = k z E( z) k b E( z) z U ( z) + k z E( z) k b E ( z) U ( z) = z2 U ( z ) = z 1 U ( z ) + k z 1 E ( z ) z 2 k b E ( z ) U (n) = U (n 1) + k E (n 1) k b E (n 2);

This difference equation will be implemented in the PIC24F. U(n) represents the present value written to the PWM register. U(n-1) is the previously written value. E(n) is the present error signal, E(n-1) is the previous and E(n-2) the previous-previous error signal.

Stability:
The stability of a control system can be determined by first finding the forward gain of the feedback system which we will call H(z). This can be found by using the relationship: Equation 4 Control Ratio
H ( z) = M ( z) C ( z)

where C(z) is the controller transfer function and M(z) is the motor transfer function translated to the z-domain. If we find the location of the poles and zeros of a function as a function of the controller gain, we can determine the properties of the closed-loop control systems. Root-locus is the process of finding the location of the poles and zeros as a function the gain.

Embedded Systems Interfacing

Fall 2008

jeg

Figure 3 Closed-Loop Root-Locus An example of a root-locus is shown in Figure 3. The root-locus tool may be used to find the controller gain at various damping ratios. The damping ratio is a measure of how fast the controlled signal settles on the reference signal. The lower the number the longer it takes to settle.

MATLAB Transfer Function


MATLAB Control Tool box has a transfer function called tf( ). The syntax is: sys = tf(num,den) sysd = tf(num,den,Ts) We will use the first form for continuous systems step response. As an example % Motor Step Response clc A = 13.333; % Motor B = A*1.95; % Motor Motor = tf([B],[1 A]); % step(1.95*Motor) % Motor

Pole Gain Motor Transfer Function step response

The A and B values given here are made-up and will not be equal to your measured and calculated values. The second form is for discrete systems where Ts is the sample interval.

Embedded Systems Interfacing

Fall 2008

jeg

MATLAB Step Function:


MATLAB has a function called step( ) that will plot the step response of the system. If one defines the numerator of the motor transfer function, step response. From the MATLAB online help the step function details are: STEP(SYS) plots the step response of the LTI model SYS (created with either TF, ZPK, or SS). For multiinput models, independent step commands are applied to each input channel. The time range and number of points are chosen automatically. See above for an example
Y (s ) , U (s )

as N and the denominator of the control ratio as D, Then step(N,D) will plot the

MATLAB Continuous to Discrete Function


To convert the continuous transfer function to its equivalent discrete transfer function use the c2d( ) function. The syntax is: sysd = c2d(sys,Ts) where sys is the continuous domain transfer function, Ts is the sample interval (50 ms), and sysd is the discrete transfer function.

MATLAB Root-Locus Tool


Initialize the Root Locus Design GUI by rlocus(sys) where system is the transfer function of the product of the controller and motor in the z-domain.

Task 1:
Use the A and B values from the previous laboratory exercise. Find the step response of the servomotor and electronics. Then compare with the step response of the previous laboratory exercise. Use the following m-script: %Task 1 Feedback Lab Step Response clc A = 13.333; %use your measured value B = A*1.95; %use your measured value Motor = tf([B],[1 A]); step(6*Motor) Use your values for A and B. If the measured and calculated responses do not agree contact the laboratory assistant or instructor for help. Next we will find the root locus of the closed loop system for various gains. In a feedback control system, the location of poles and zeros of the control ratio move around as system gain is changed. To see where the poles and zeros of the servomotor lie we will use the c2d( ) function and the pzmap( ) in the MATLAB Controls Toolbox. Use the following m-script:

%Task 1 Feedback Lab Root Locus clc A = 13.333; %use your measured value

Embedded Systems Interfacing

Fall 2008

jeg

B = A*1.95; %use your measured value T = 0.050; %use the values observed in previous laboratory exercise k=1.0; b=0.8; Motor_Z = c2d(tf([B],[1 A]),T); Cntrl_Z = tf([k -b*k],[1 -1 0],T) H_z=Cntrl_Z*Motor_Z CR=H_z/(1+H_z) rlocus(H_Z); This will invoke the root-locus tools GUI. From the plot area of the tool determine the controller gain for the four specified condition listed below in Table 1. Table 1 Controller Gain

Condition Damping Controller Gain Under Damped 0.5 Critical Damped 1.0 Over Damped 1.0 Unstable <0
Once the gains have been found, replace rlocus(H_z) with the following. Change the k from 1 to each value in the Table 1, and save the step response figure as a JPEG. Repeat for all four cases. hold on step(CR) %Closed Loop Step Response grid() title(['Controller Gain is ',num2str(k)]) hold off

Task 2:
The code in Task 3 uses a scaling factor of 1024. K1 = 1024*k and K2 = K1*b. Use the b and ks from the previous task to calculate K1 and K2 and place the results in Table 2. Table 2 Difference Equation Gains

Condition Under Damped Critical Damped Over Damped Unstable


Task 3:

K1 = 1024k

K2 = bK1

Connect the output of the frequency to voltage converter to AN3/RB3. Supply the LM2907 with +5 VDC and ground on the appropriate pins. Connect OC1/RD0 pin to the input of the Darlington sinking current driver. Supply a common ground with the LM2907 with the driver. Apply +12 VDC to one side of the motor and driver. Connect the other side to the output of the driver. Download the source code off the course web page and study the initialization, endless loop and interrupt service routine. Discuss these in your report. Add your critically damped K1 and K2 constants to the code. Compile, program and run the code. Verify that all systems are working properly. Capture the speed on A1 and the reference switch on RD1 with A2. Your output should look similar to

Embedded Systems Interfacing

Fall 2008

jeg

Figure 4 Simulated MSO Image for = 1.

Task 4:
Use MPLABs Data Monitor and Control Interface to Adjust K1 and K2. Use the four sets of values from Table 2. Capture Image on MSO and repeat for: Critically Damped Over Damped Under Damped Unstable Compare the MSO images to the MATLAB figures. In your report discuss similarities and differences.

Task 5:
Return the workbench and drawers to their original condition. Perform an inventory of the workbench drawers using the manifest supplied in the upper left-hand drawer. Make sure that all instruments have been turn off and reposition on the shelf if they have been moved. Leave the ICD-2, Explorer-16 printed circuit board, power supply cord, and serial cable to ICD on the bench top with ever thing connected. Turn off the power supply. Shut down the computer, monitor, and video switch. After the laboratory assistant has inspected your workstation you may leave the laboratory. Return your PICTail Protoboard to your laboratory bench drawer. Do not discuss this task in your report.

Report Format:
This laboratory experience requires a formal report. Consult the Report Format given to you in the laboratory or the PDF on the course web page for details. There is also an example laboratory report on the course web page.

Embedded Systems Interfacing

Fall 2008

jeg

Motor Feedback
Name 1: ___________________
Please Print

Name 2: ___________________
Please Print

Name 3: ___________________
Please Print

Submitted On: ___ Oct 2008 Laboratory Section: ____________ Please Print

Check List: Description Purpose Discussion To include MATLAB and MSO Image differences and similarities To include software operation Required Results MATLAB Root Locus Gain Table MATLAB Step Response of Motor MATLAB Step Response of System (All 4 Cases) MSO Step Response of System (All 4 Cases) No Data Sheets Total Score

The work presented in this report is solely the work of the authors. Presenting the work of others is plagiarism and will be penalized by failure of the course for the slightest infraction.

You might also like