Docsity

Introduction to Sampling - Lab 0 | ECE 147B, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
University of California, Santa Barbara
Department of Electrical & Computer Engineering
ECE 147b: Digital Control
Lab 0: Introduction to Sampling
This lab is an introduction to the experimental equipment and a review of some of the
principles of sampling. No writeup is due.
1 Hardware
The control board used in this lab has 3 encoder inputs on the top row, and three PWM
outputs on the bottom row. The back has digital inputs and outputs.
2 Software
The functionality of the control board can be completely controlled via SIMULINK and Real
Time Workshop (RTW). RTW is a real-time Windows application that runs SIMULINK
generated code on a PC.
To use the control board, go to the Simulink Library Browser and
1. Select the Quarc/Generic/Data Acquisition library.
2. Select HIL Write PWM, HIL Read Encoder, HIL Initialize blocks from the selections
on the right.
3. Drag the selected block onto your Simulink Model.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Introduction to Sampling - Lab 0 | ECE 147B and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

University of California, Santa Barbara Department of Electrical & Computer Engineering

ECE 147b: Digital Control

Lab 0: Introduction to Sampling

This lab is an introduction to the experimental equipment and a review of some of the principles of sampling. No writeup is due.

1 Hardware

The control board used in this lab has 3 encoder inputs on the top row, and three PWM outputs on the bottom row. The back has digital inputs and outputs.

2 Software

The functionality of the control board can be completely controlled via SIMULINK and Real Time Workshop (RTW). RTW is a real-time Windows application that runs SIMULINK generated code on a PC.

To use the control board, go to the Simulink Library Browser and

  1. Select the Quarc/Generic/Data Acquisition library.
  2. Select HIL Write PWM, HIL Read Encoder, HIL Initialize blocks from the selections on the right.
  3. Drag the selected block onto your Simulink Model.
  1. Double click the HIL Initialize block, set board type to q3-controlpaq-fw, set board number to HIL-1 and save settings.
  2. Double click the HIL Encoder Input and HIL PWM Output blocks.
  3. Set board number to HIL-1, set sample time, (ie. 0.001), set channel numbers (note: matlab channel numbers run from 1-3, board numbers run from 0-2, so channel 1 in simulink corresponds to channel 0 on the board).

2.1 Data Logging

In the Real Time Windows Target, data is logged by scope blocks. Like an oscilloscope, to start the data logging procedure, a trigger is needed to initiate the process. A simple approach is to define a dedicated scope block, with one trigger signal entering it as illustrated below.

This shows a step function set with a step time of 0.001 seconds, which corresponds to one sample time. This set-up will save all but the very first data point. To record data, follow the procedure below.

  1. Place a STEP function block from the SOURCES library and a SCOPE block from the SINKS library in your model.
  2. Name the SCOPE block TRIGGER SCOPE so that it is easy to identify in a list.
  3. Set the step time of the STEP block to the time you wish to begin saving data. Set the Initial Value and Final Value to 0 and 1 respectively.
  4. Go to the TOOLS pull down menu and select EXTERNAL MODE CONTROL PANEL.
  1. Open all SCOPE blocks and configure them in the following way.
  2. Click the SCOPE PROPERTIES Icon, and select the DATA HISTORY tab
  3. Make sure Limit data points to last is UNCHECKED
  4. If you wish to save the data gathered by the scope, CHECK the Save data to workspace box, and give the Variable name a unique and meaningful name for easy reference later. In the FORMAT menu choose the ARRAY option.
  5. Hint : Once you have set these parameters as you like, you can RIGHT CLICK on a scope block, drag and drop, and a copy of that block will be placed where you let go of the mouse. The new block will have all of the parameters of the previous, except the Variable name, that will be different and should be changed to something meaningful.

2.2 Real Time Windows Target Simulation Parameters

You must configure the way that the RTW builds its real time executable C-code. Real time Simulink models can run only with a Fixed Step Size. The Target Language Compiler must also be set to Real Time Windows Target so that the generated code is made for running on a PC which is running Widows and Simulink on the same machine. To do this,

  1. Click on the SIMULATION pull down menu, and select CONFIGURATION PARAM- ETERS.
  1. Next, select the REAL-TIME WORKSHOP on the left.
  2. In the TARGET SELECTION area, click BROWSE, and scroll down to the bottom, and select rtwin.tlc from the menu. Verify that the other settings in the window match the screen shot below.
  3. This sets the windows machine as the target for the real time code.
  4. Click APPLY and OK
  1. Lastly, the model must be set to EXTERNAL mode. In the model toolbar to the right of the final simulation time an the play button, is a pull down menu that usually says NORMAL, click the menu and select EXTERNAL.
  2. The model must be BUILT first before it can be run. Building involves generating and compiling the real time code. To do this click on the TOOLS menu and under Real-Time Workshop select BUILD MODEL, or just hit CTRL+B.
  3. The Matlab command window will show all of the steps of the build process and indicate if it completes successfully or not.

3 Digital Filter

The following procedure gives a discrete-time controller with the same step response as an analog controller. The procedure is fairly intuitive when you think about it.

Take a continuous time filter,

P (s) =

a s + a

and examine its output, Y (s), in response to a step input. So,

Y (s) =

a s(s + a)

This corresponds to the time domain signal,

y(t) = 1 − e−at

Now suppose we sample this time domain signal with a sampling period of T. This is equivalent to choosing t = kT , where k will now be our discrete time index. So our sampled signal is

y(kT ) = 1 − e−akT

In the z domain, this is

Y (z) =

z(1 − e−aT^ ) (z − 1)(z − e−aT^ )

We would like for this to be the output of some system, call it P (z), when the input is a sampled step function. A sampled step function has the z transform

U (z) =

z z − 1

Therefore, we want to choose P (z) such that

Y (z) = P (z)U (z)

We can do this by examination, which yields

P (z) =

1 − e−aT z − e−aT

=

z−^1 (1 − e−aT^ ) 1 − e−aT^ z−^1

The discrete time filter can now be implemented. This discrete-time transfer function is referred to as the “step-equivalent”.