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.

1

E(n-1) is the previous and E(n-2) the previous-previous error signal.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. 2 . U(n) represents the present value written to the PWM register. 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). Root-locus is the process of finding the location of the poles and zeros as a function the gain. we can determine the properties of the closed-loop control systems. U(n-1) is the previously written value. 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). E(n) is the present error signal. This difference equation will be implemented in the PIC24F. 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.

3 .95.den) sysd = tf(num. As an example % Motor Step Response clc A = 13.Embedded Systems Interfacing Fall 2008 jeg Figure 3 Closed-Loop Root-Locus An example of a root-locus is shown in Figure 3. MATLAB Transfer Function MATLAB Control Tool box has a transfer function called tf( ). The root-locus tool may be used to find the controller gain at various damping ratios.333.den. % Motor B = A*1. The damping ratio is a measure of how fast the controlled signal settles on the reference signal. The second form is for discrete systems where Ts is the sample interval.[1 A]).Ts) We will use the first form for continuous systems step response. % step(1. The syntax is: sys = tf(num.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 lower the number the longer it takes to settle. % Motor Motor = tf([B].

The syntax is: sysd = c2d(sys. 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. or SS). Find the step response of the servomotor and electronics. step(6*Motor) Use your values for A and B.333. In a feedback control system. See above for an example Y (s ) . If one defines the numerator of the motor transfer function. The time range and number of points are chosen automatically. 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.Embedded Systems Interfacing Fall 2008 jeg MATLAB Step Function: MATLAB has a function called step( ) that will plot the step response of the system. U (s ) as N and the denominator of the control ratio as D. For multiinput models.[1 A]). independent step commands are applied to each input channel. %use your measured value 4 .333. step response. Next we will find the root locus of the closed loop system for various gains. Task 1: Use the A and B values from the previous laboratory exercise. and sysd is the discrete transfer function. %use your measured value B = A*1. %use your measured value Motor = tf([B]. Use the following m-script: %Task 1 Feedback Lab Root Locus clc A = 13. ZPK. 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.95. Ts is the sample interval (50 ms). Use the following m-script: %Task 1 Feedback Lab Step Response clc A = 13.Ts) where sys is the continuous domain transfer function. the location of poles and zeros of the control ratio move around as system gain is changed. 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. If the measured and calculated responses do not agree contact the laboratory assistant or instructor for help. Then compare with the step response of the previous laboratory exercise.

Table 2 Difference Equation Gains Condition Under Damped Critical Damped Over Damped Unstable Task 3: K1 = 1024•k K2 = b•K1 Connect the output of the frequency to voltage converter to AN3/RB3. Repeat for all four cases. Apply +12 VDC to one side of the motor and driver. Download the source code off the course web page and study the initialization. Motor_Z = c2d(tf([B]. replace rlocus(H_z) with the following. This will invoke the root-locus tools GUI. Capture the speed on A1 and the reference switch on RD1 with A2. and save the step response figure as a JPEG. Use the b and k’s from the previous task to calculate K1 and K2 and place the results in Table 2.T). Supply the LM2907 with +5 VDC and ground on the appropriate pins. Add your critically damped K1 and K2 constants to the code.[1 -1 0].0 Over Damped 1. hold on step(CR) %Closed Loop Step Response grid() title(['Controller Gain is '. Your output should look similar to 5 . Table 1 Controller Gain Condition Damping Controller Gain Under Damped 0. Compile. %use your measured value T = 0.[1 A]).0 Unstable <0 Once the gains have been found. Connect the other side to the output of the driver. Connect OC1/RD0 pin to the input of the Darlington sinking current driver.050.num2str(k)]) hold off Task 2: The code in Task 3 uses a scaling factor of 1024.T) H_z=Cntrl_Z*Motor_Z CR=H_z/(1+H_z) rlocus(H_Z). endless loop and interrupt service routine. %use the values observed in previous laboratory exercise k=1.Embedded Systems Interfacing Fall 2008 jeg B = A*1.0. From the plot area of the tool determine the controller gain for the four specified condition listed below in Table 1.5 Critical Damped 1. Discuss these in your report. Supply a common ground with the LM2907 with the driver.8. program and run the code. K1 = 1024*k and K2 = K1*b. Verify that all systems are working properly.95. Change the k from 1 to each value in the Table 1. Cntrl_Z = tf([k -b*k]. b=0.

power supply cord. and serial cable to ICD on the bench top with ever thing connected. In your report discuss similarities and differences. Task 4: Use MPLAB’s Data Monitor and Control Interface to Adjust K1 and K2. Do not discuss this task in your report. Capture Image on MSO and repeat for: • Critically Damped • Over Damped • Under Damped • Unstable Compare the MSO images to the MATLAB figures. Explorer-16 printed circuit board. Return your PICTail Protoboard to your laboratory bench drawer. Task 5: Return the workbench and drawers to their original condition.Embedded Systems Interfacing Fall 2008 jeg Figure 4 Simulated MSO Image for ξ = 1. Leave the ICD-2. 6 . and video switch. Perform an inventory of the workbench drawers using the manifest supplied in the upper left-hand drawer. Turn off the power supply. Make sure that all instruments have been turn off and reposition on the shelf if they have been moved. After the laboratory assistant has inspected your workstation you may leave the laboratory. Report Format: This laboratory experience requires a formal report. There is also an example laboratory report on the course web page. Use the four sets of values from Table 2. Shut down the computer. monitor. Consult the Report Format given to you in the laboratory or the PDF on the course web page for details.

Presenting the work of others is plagiarism and will be penalized by failure of the course for the slightest infraction.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. 7 .