<<

1 LABORATORY 2

Introduction to: Analog and the DSPACE System.

Mark Schedule

33% Preparation 67% Lab Report

Contents

1 INTRODUCTION 2 1.1 Objective ...... 2 1.2 Hardware Description ...... 2

2 USING THE COMDYNA GP-6 ANALOG 2 2.1 Analog Computer Elements ...... 2 2.2 Operation of the Analog Computer ...... 6 2.3 Example 1 ...... 6 2.4 Example 2 ...... 7

3 USING THE dSPACE SYSTEM 9 3.1 Creating a dSPACE Block Diagram ...... 12 3.2 The ControlDesk Package ...... 13 3.3 Using dSPACE to find a Step Response ...... 17

4 Laboratory Preparation 20

5 Laboratory Procedure 20 5.1 Analog Computer ...... 20 5.2 dSPACE ...... 21 5.3 dSPACE and the Analog Computer ...... 21 1 INTRODUCTION 1.1 Objective The objective of this laboratory is for students to become familiar with the use of the GP6 analog computer and the dSPACE system in implementing given transfer functions. This knowledge will form the basis of later laboratories in which these systems are used to implement controllers or simulate control systems.

1.2 Hardware Description The hardware used in this laboratory experiment consists of the following:

Comdyna GP-6 Analog Computer • Generator • • IBM PC running Matlab and dSPACE . This PC also contains a dSPACE DSP board. • 2 USING THE COMDYNA GP-6 ANALOG COMPUTER

One approach to implementing a given transfer involves using various elements contained in the Comdyna GP-6 analog computer.

2.1 Analog Computer Elements (i) Integrators: The symbol for integrators together with their patch panel layout is shown below:(Note Amplifiers 1–4 must be used)

2 SJ' IC A A

SJ 1

1 Integrator B 1 C 1 1-4 1 Eo D B 10 E 10 1 F C Eo

1 D E0=- (B+C+D+10E+10F)dt-A .1

E B

.1 .1 B F

SW OP

3 (ii) Alternatively, if a higher gain is required then we can use the following alternative patching

SJ' IC A A

SJ 1

10 Integrator B amplifiers 10 C 1 1-4 10 Eo D B 100 E 100 1 F C Eo

1 D E0=- (10B+10C+10D+100E+100F)dt-A .1

E B

.1 F .1 B SW OP

4 (iii) The symbol for summers together with various possible patch panel layouts is shown below:

SJ' IC

SJ 1

1 Summer A amplifiers 1 1 1-4 B Eo 10 C 10 1 D A Eo

1 B E0=-(A+B+10C+10D) .1 B C

.1 .1 B D

1 SJ A A 1

Eo 6 Summer B 10 1 amplifer 6 C 10 .1 B Eo Eo=-(A+10B+10C) .1 C

1 SJ A 1 A

Eo Summer B 1 5 1 5 C 10

1 Eo Eo=-(A+B+10C) B

.1 C

(iv) Inverters: The symbol for an inverter together with its patch panel layout is shown below:

Inverter A 1 Eo A7 Eo amplifiers 7 & 8

Eo=-A

(v) : The symbol for potentiometers together with their patch panel layout is shown below:

5 Attenuator A A Eo pots 1-6

Eo = K A 0 < K < 1 Eo

0

Voltage A Divider A (pots 7 & 8) Eo

Eo 0 < K < 1 B

Eo = K(A-B)+B B

2.2 Operation of the Analog Computer Setting Potentiometers The first operation to be performed after wiring up the analog computer for a given simu- lation is to set the values. This is performed as follows.

(i) Position the MODE SELECTOR switch to POT SET. (If the overload light goes on, remove the overload condition by patching the overloaded amplifier output directly to its summing junction. Be sure to remove this patch cord after all of the Pots are set.)

(ii) Position the Y/POT ADDRESS switch to the number of the pot to be set.

(iii) Adjust the pot knob until the desired setting is displayed.

Running the Analog Computer After the circuit has been wired up and the pots set to the correct value, the analog computer is run with the OP mode control button pushed and the mode selector switch set to OPR.

2.3 Example 1 Implementation of a simple For a given transfer function:

Y (s) 2 G(s) = = U(s) s + 1 we have

2U(s) = (s + 1)Y (s) 2u(t) =y ˙(t) + y(t) ⇔ y˙(t) = 2u(t) + y(t) ⇔ − − This equation can be implemented on the analog computer according to the following block diagram:

6 u -0.2u y -1 0.2 10 1

This would be wired up on the analog computer as indicated on the patch panel diagram in Figure 1. The following pot values would be used

Potentiometer 1 2 3 4 5 6 7 8 Setting 0.2

Notes: Output of Pot 5 = 2u(t) Output of Integrator− 3 = y

2.4 Example 2 Implementation via Phase Variable Form Given the transfer function:

Y˜ (s) 2s + 1 G˜(s) = = , U(s) s2 + 3s + 4 we can implement this transfer function on the analog computer using a version of the “Phase variable form” state space realization. First consider the transfer function Y (s) 1 G(s) = = , U(s) s2 + 3s + 4

Hence,

(s2 + 3s + 4)Y (s) = U(s) y¨ = u 3y ˙ 4y ⇔ − − This leads to the following analog computer block diagram

7 + + - + SJ’ IC SJ’ IC - - SJ’ IC SJ’ IC iue1 ac ae aotfrEape1. Example for layout panel Patch 1: Figure

1 2 3 4 5 6 SJ 1 SJ 2 SJ 3 SJ 4

1 1 1 1

1 1 SJ SJ 7 8 1 1 1 1

5 6 8 1 1 1 1 1 1

.1 .1 1 .1 .1 B B .1 B B

.1 .1 B .1 .1 B .1 .1 .1 .1 B .1 .1 B

X Y X Y X SJ SJ X

SW OP SW OP SW OP SW OP

7 8 u 1 . -y y 10 1 10

. 0.3 -0.3y

-0.4y 0.4 -1

Now we use the fact that G˜(s) = (2s + 1)G(s) Hence

Y˜ (s) = (2s + 1)Y (s) y˜ = 2y ˙ + y. ⇔ Thus, the transfer function G˜(s) can be implemented on the analog computer via the block diagram shown in Figure 2: The patch panel layout corresponding to this block diagram is shown in Figure 3 The following pot values would be used

Potentiometer 1 2 3 4 5 6 7 8 Setting 0.3 0.4 0.2

Notes: dy Output of Integrator 1 = dt Output of Integrator 3 = y− Output of Summer 3 =y ˜

3 USING THE dSPACE SYSTEM

The dSPACE system is high performance digital control system based on the TI TMS320C31 DSP processor. It is directly interfaced with MATLAB/SIMULINK running on a PC. A simulink block diagram is converted to real time C code, cross compiled and downloaded to the DSP board. Software is also available for controlling the DSP from the PC and plotting variables in real time in the DSP. In this laboratory, you will familiarize yourself with some of the capabilities of the dSPACE system including the implementation of transfer functions and the ability to provide step inputs and to plot the resulting step responses of

9 . ~ -0.2y 10 y 0.2 1 -y

u -1 1 . -y y 10 1 10

. 0.3 -0.3y

-0.4y 0.4 -1

Figure 2: Analog Computer Block Diagram For Example 2.

10 + + - + SJ’ IC SJ’ IC - - SJ’ IC SJ’ IC iue3 ac ae aotfrEape2. Example for layout panel Patch 3: Figure

1 2 3 4 5 6 SJ 1 SJ 2 SJ 3 SJ 4

1 1 1 1

1 1 SJ SJ 7 8 1 1 1 1

11 5 6 1 1 1 1 1 1

.1 .1 1 .1 .1 B B .1 B B

.1 .1 B .1 .1 B .1 .1 .1 .1 B .1 .1 B

X Y X Y X SJ SJ X

SW OP SW OP SW OP SW OP

7 8 the systems under consideration. Each of the four IBM PCs in the control lab contains a dSPACE ds1102 DSP board. This board can be connected to the outside world via a connector box. The first step in using the dSPACE system involves logging on to the PC. You should use the username “student” and the password “Eleceng1”. All of the files that you generate during the course of the laboratory should be stored in the directory:

C:\matlabR11\work\student

3.1 Creating a dSPACE Block Diagram We now present a case study of using the dSPACE system. The implementation of this case study is not part of the laboratory but should give you an idea as to how to carry out the actual laboratory. In order to use the dSPACE system, you must construct block diagrams on MATLAB/SIMULINK and run them on your dSPACE board. After you log onto the PC, run MATLAB as follows:

Start Programs Matlab Matlab 5.3 → → → Run simulink and create a block diagram which you wish to implement on dSPACE; e.g., see below:

ADC #1 1 1 DAC #1 ADC #2 s s DAC #2 Integrator Integrator1 ADC #3 DAC #3 ADC #4 DAC #4 1 DS1102ADC DS1102DAC Gain

1

Gain1

Figure 4: A simple simulink block diagram

Note that the ADC and DAC blocks included in this block diagram are specific to dSPACE and should be obtained from the dSPACE RTI1102 folder of the simulink library browser. Also, ensure that you use the correct board which is ds1102. The signal applied to a dSPACE ADC channel must be in the range -10 to 10 volts. A signal of +10 volts gives an internal value of 1.00 within simulink. The dSPACE DAC converters give an output in the range of -10 to 10 volts. An internal value of 1.00 gives +10 volts on the DAC.

Compiling and Downloading First make sure the matlab default directory is correct by giving the command: >> cd C:\matlabR11\work\student In order to generate C code for your block diagram, go to the “Tools” menu and select RTW options (RTW stands for Real Time Workshop). This is necessary in order to configure simulink C code generation for use with dSPACE.

12 Select the Solver tab and set the “step size” to a suitable value in seconds. (Say 0.001) This determines the sample • period used in the real time implementation of the system.

Choose the “Real Time Workshop” Tab and click build. This will compile the block diagram and download it to • the dSPACE board.

From now on, if you change the block diagram and do not need to change the step size, you can compile the block • diagram simply by going to the tools menu and choosing “RTW build”.

3.2 The ControlDesk Package This is a powerful dSPACE software package used to interact with the program you have running on the dSPACE DSP board. In particular, it is used to change parameters in the model and to plot variables and in the DSP. The following write up gives some basic instructions on the use of the ControlDesk package. However, in order to use the package correctly you will need to use the online help. The online help package is called “dSPACE HelpDesk”. To run this package choose the windows menu items as follows:

Start Programs dSPACE Tools dSPACE HelpDesk → → → This online help system contains all the information about the ControlDesk package. In particular, if you can’t do something in ControlDesk, DO NOT ASK THE DEMONSTRATOR HOW TO DO IT but rather look it up in HelpDesk.

Overview ControlDesk allows you to collect the various files you need for a particular model in an “Experiment”. An experiment can consist of

1. Hardware specification: This specifies which board the program runs on (In our case there is only one DSP board to worry about).

2. Instrumentation layout: In control desk, the instrumentation layout is used to display signals from the DSP and to adjust parameters in the DSP model. For each experiment, you must construct a layout to display the required variables and adjust the required parameters.

3. The ControlDesk package requires a .trc file corresponding to the simulink model which is running on the DSP board. This file is automatically generated when the simulink block diagram is compiled as above. This file is specified for the given experiment in the Variable Manager section.

Main Window A typical ControlDesk window is shown below

13 Figure 5: ConrolDesk Window

As illustrated in this diagram, the main window contains a number of elements:

Navigator. The Navigator panel provides access to the different parts of a real-time experiment. These are, the • Hardware View, the Experiment View and the Instrument View. The current view is controlled by the tabs at the bottom of the Navigator panel.

Menu Bar. These menus allow for the various commands to be given to ControlDesk. The menus are dynamic • and depend on the view and element selected in the Navigator.

Tool Bars. These provide quick ways of given ControlDesk commands rather than using the menus. The tool • bars can be turned on or off.

Tool Window. This window is used for various tools controlling the experiment depending on the view chosen • from the Navigator. Most commonly used is the variable manager which enables the selection variables from a simulink model.

Working Area. This is the area in which a ControlDesk instrument layout is constructed and used. • Status Bar This displays some information about the state of the ControlDesk system. • We now outline how to create a simple experiment which is based on the simulink block diagram above. The aim of this experiment is to display the output signals for this system using an oscilloscope type display.

To start ControlDesk, double click on the dSPACE ControlDesk icon on the windows screen. •

14 Create a new experiment using the following menu commands: • File New Experiment → You should then specify a name for your experiment and specify the “working root” directory as

C:\matlabR11\work\student

Click on the green Hardware tab (Ha ...). This should indicate that a program is running on your ds1102 board • (by the green triangle). If not, you can drag and drop the corresponding .obj file onto the ds1102 icon to download this program. Add this hardware description to your experiment by right clicking on the window with the ds1102 icon and then choose “Add to Experiment”

Click on the blue Experiment tag (E...). You should now see the hardware icon included in your experiment. To • add the required .trc file to your experiment use the following menu commands:

File Open Variable File → and choose the .trc file corresponding to your simulink block diagram constructed above. This should open a new window with your model name and also a window listing some variables for your model. To add the .trc file to your experiment, right click on this window and choose “Add to Experiment”. This should give you a new icon in your experiment which includes your .trc file.

Also, you may wish to add your simulink block diagram to the experiment. This .mdl file is not used by ControlDesk • directly but it is useful to keep track of it. To add this file to your experiment, give the following menu command:

File Import Files → Then locate the .mdl file for your block diagram. This should lead to a new “External Files” section in the Navigator panel (under Experiment) with your .mdl file included.

To construct an instrumentation layout for your experiment, give the menu commands • File New → Then scroll down and select layout. This should create a blank layout window. Click on the multi-coloured Instrumentation tab (In...). You should then see a virtual instrument panel.

In this example, we wish to create a oscilloscope type display to plot the variable “Integrator1” which is the output • of our system. We will also include a gauge which displays the model “turnaround Time”. This is useful if we want to know how short we can make the system sample time (It must be at least greater than the turnaround time.).

Click on “Data Acquisition” in the Virtual Instruments panel and then click on the plotter icon. Then move to • the Layout panel and draw a rectangle which will determine the size of your plot (It should take up about half the available area but can be adjusted later if desired.) A set of axes should appear on your layout panel.

We now need to set up this plotter to plot the desired variable. First move to the Tool Window and click on Model • Root. The variable panel should display a list of variables associated with your simulink block diagram. Click on the variable denoted B:Integrator1 (The notation B:Integrator1 refers to the fact that we are interested in the output signal corresponding to the simulink block labelled Integrator1) Now drag and drop to the area just to the left of the plotter y-axis in the Layout panel. The y-axis now should be labelled Integrator1 and a red square appears indicating the color of the plot for this variable.

We can adjust the parameters of the plotter by right clicking on the plotter area and then choosing the Properties • menu item. Then click on the axes tab. At this stage, the only thing we will adjust will be the Y-min value to -0.05 and the Y-Max value to 0.05.

15 The time and triggering of the plotter can be controlled by using a capture settings instrument. Click on the • capture settings icon and then draw a suitable rectangle in the layout panel (About half of the available area.) Double click on the settings button in the capture instrument and click on the Capture tab. In the Capture window, click on the right downarrow and choose the only option available “DSP - ... - Service #1”. Also, set the length variable to 1sec. Then click OK. In this case, our trigger variable will be the same variable that we are going to plot. Hence, again click on B:Integrator1 in the Variable panel and drag and drop it in the trigger window in the capture instrument panel (This is just below the words level and delay.) You can then adjust the plot interval and trigger level to suitable values depending on the signal you are plotting. If the signal applied to the filter is a 1Hz sine wave with amplitude of 10V, then a suitable length is 1sec. Turn the trigger on with AutoRepeat and leave the trigger level at 0.

To start plotting (assuming that the signal generator has been connected to the DSP board connector panel), • simply give the following menu command

Instrumentation Animation Mode → This should commence the interaction between your instrumentation layout and the DSP board. To stop, choose the menu command Instrumentation Edit Mode → This enables you to make further adjustments to your instrument panel.

The controldesk program does not have a direct way of printing plots. A simple way to print plots is to use screen • capture (hold down the “alt” key and press the “print screen” key). Then run the “paint” program and paste the screen capture into the program. The required plot can then be cut out and printed.

If you wish to save your traced data to a file so that it can be later loaded into matlab and printed, make the • following adjustment to the properties of the capture instrument: Under Acquisition, choose simple capture and check Automatic storage. Then specify a filename in which the data will be stored; e.g., output.mat. Then run the animation again. It is best to turn off Autorepeat this time since every time a trace is plotted, it will also overwrite this file. After the capture is complete, you can open this file and plot it from your matlab command window as follows:

>> load output >> plot(trace_x,trace_y),xlabel(trace_x_n),ylabel(trace_y_n)

This plot can then be printed if required. (Before printing, be sure to choose matlab print setup and set the paper type to A4. If you don’t do this, you will need to press shift continue on the printer to obtain the plot.)

Our final step in this example will be to add a gauge to our layout which displays the program turnaround time. • With the layout in edit mode, click on the virtual instrument button in the virtual instruments panel and then click on the Gauge icon. Then draw a suitable size rectangle in the layout panel for the gauge. A gauge should appear in the layout. To get this gauge to display the turnaround time, click on the “Timer Task 1” item in the Tool Window. The variable panel should then display various variables associated with the program running on the DSP board. Drag and drop the “turnaroundTime” item onto the gauge instrument in the layout panel. The gauge should now be labelled turnaroundTime. Right click on the gauge instrument and choose properties. Then click the gauge tab. Adjust the stop value to 100e-6. Then click on the Tics tab and adjust the Delta to 25e-6. Restarting the animation, this gauge should now display the turnaroundTime in micro seconds.

This completes our layout for this experiment. The layout can be added to the experiment by right clicking on the • layout panel and then choosing “Add layout to Experiment” (This will also ask you to save your layout to disk which you should do). A new Instrumentation element should appear in your experiment listing which contains the corresponding layout file.

16 The final ControlDesk window should look something like the following: •

Figure 6: Final ConrolDesk Window

3.3 Using dSPACE to find a Step Response The best way to use the dSPACE system to construct a step response is to add a constant block to your simulink block diagram which will provide the step input. Then use the ControlDesk package to control the step and view the resulting step response using a plotter instrument.

To provide the step input, we do NOT use the standard simulink step block. (The step would be over before we • had time to set things up). Rather we add a “Constant” block whose value will be adjusted by ControlDesk to provide the step input at the required time. Also, the ADC and DAC blocks can be removed. This leads to the following simulink block diagram.

17 0 1 1 Constant s s Integrator Integrator1

1

Gain

1

Gain1

Figure 7: Simulink block diagram for step response

Compile this system as above • Return to ControlDesk and close any old experiments. Open a new experiment and give it a suitable name. As • described in the previous example, add the hardware configuration and .trc file to this experiment.

Create a new layout (or modify the existing layout) as follows: •

18 Figure 8: Instrument layout for step response

In this instrument layout, the plotted signal is the output of the system “B:Integrator1”. Also, plotted on the same • graph is input to the system “B:Constant”. This is achieved by dragging both of these variables to the Y-axis of the plot. The capture instrument is set as above. In this case, the trigger variable is the step input signal “B:Constant”. The time interval is 10sec and a factor of 10 down sampling is used to ensure the DSP does not run out of memory with this long time interval. Triggering is set up as above. Also, the data can be saved to a file and loaded into matlab as above. A step input is achieved by using an On/Off button to control the constant block in the simulink block diagram. A suitable On/Off button can be obtained as one of the options in the RadioButton Instrument. To achieve a step input, the constant value parameter variable “P: Constant Value” is dragged to the On/Off button in the layout. Also, the properties of this instrument are set so that its form is as shown above and the On value is is set to the size of the required step and the Off value is zero. The above layout also includes two Display instruments. One displays the input variable “B: Constant” and the other displays the output variable “B: Integrator1” To use this ControlDesk experiment, the layout should be put in animation mode and then the constant value set from off to on. This should trigger the data capture and produce the resulting step response.

The above procedure can be used to plot the step response of any physical system connected to the dSPACE • board. Connect the input of the system to a DAC channel (Vout(1) in the connector box) and connect the output of the physical system to an ADC channel (Vin(1) in the connector box).

Construct a simulink block diagram as shown below •

19 0 DAC #1 ADC #1 1

Constant DAC #2 ADC #2 Output DAC #3 ADC #3

DAC #4 ADC #4

DS1102DAC DS1102ADC

Figure 9: Physical system step response

Compile the system and obtain the step response using ControlDesk as above. • 4 Laboratory Preparation

This preparation must be done before the laboratory session. It should be handed in with your laboratory report which is handed in at the end of the lab and will form 33% of the total lab grade. (You should hand in your own preparation even if your lab group decides to use the preparation of another group member in the actual lab experiments.)

1. Choose a second order transfer function with at least one zero which can be implemented in dSPACE and on the Analog computer. You should make sure that your transfer function is stable. If you choose an unstable system, this will cause problems when you try to implement the system in the lab. If you find during your matlab/simulink simulations that your system is unstable, you will need to came back and choose a new system.

2. Draw a block diagram to show how the transfer function could be implemented on the Analog computer. Show all the steps used between the selection of the transfer function and the creation of the block diagram. Also, photocopy the attached blank Analog Computer patch panel and draw in the wiring which would be used to implement your transfer function.

3. Draw a block diagram to show how the transfer function would be implemented in dSPACE.

4. Devise an experiment using a sine wave input from a signal generator and the oscilloscope which will verify that your Analog computer model and dSPACE model are working correctly. Hint, consider the Bode plot of your transfer function.

5. Use Matlab/Simulink to predict the results of these experiments.

6. Use Matlab/Simulink to predict the step response of your system. In particular, to measure the percentage overshoot and rise time for your transfer function. Note that the rise time is the time taken for the step response to go from 10% to 90% of its final value.

5 Laboratory Procedure

The results you obtain during the laboratory session should be entered into the pro-forma which is handed out during the lab session. This should be handed in at the end of the lab session. There should be one report for each student.

5.1 Analog Computer 1. Using the results from your preparation, build an analog computer implementation of your chosen transfer function. (Choose one transfer function from among the group.)

20 2. Carry out the experiment you devised during your preparation using the signal generator and oscilloscope to verify that your system is working correctly. Note, because of the low frequencies used, make sure that you use DC coupling in the oscilloscope settings. Also, you can use the cursors feature of the oscilloscope to make accurate measurements.

3. Compare the results with your predictions.

5.2 dSPACE 1. Build the dSPACE model of your chosen system.

2. Carry out the experiment you devised during your preparation using the signal generator and oscilloscope to verify that your system is working correctly.

3. Compare the results with your predictions.

4. Carry out the same experiment purely in dSPACE using the simulink signal generator and ControlDesk instead of the real signal generator and the oscilloscope.

5. Compare the results with your predictions.

6. Determine the turnaroundTime time for your system on the dSPACE board.

7. Use dSPACE to find the step response of your system. In particular, find the percentage overshoot and rise time for your system.

8. Compare the results with your predictions.

5.3 dSPACE and the Analog Computer 1. Use dSPACE to find the step response of the Analog computer implementation of your system. In particular, find the percentage overshoot and rise time.

2. Repeat part 2 of the Section 5.1 but this time use dSPACE rather than the oscilloscope and signal generator. (c.f. part 4 of Section 5.2.)

21 + + - + SJ’ IC SJ’ IC - - SJ’ IC SJ’ IC

1 2 3 4 5 6 SJ 1 SJ 2 SJ 3 SJ 4

1 1 1 1

1 1 SJ SJ 7 8 1 1 1 1

22 5 6 1 1 1 1 1 1

.1 .1 1 .1 .1 B B .1 B B

.1 .1 B .1 .1 B .1 .1 .1 .1 B .1 .1 B

X Y X Y X SJ SJ X

SW OP SW OP SW OP SW OP

7 8