Professional Documents
Culture Documents
( SPRING 2008 )
TABLE OF CONTENTS
Pages
Subject ....................................................................................................................................1
1. Introduction .......................................................................................................................1
2. Purpose of the Report
2.1 ADVANTECH PCI 1710 Daq Device............................................................................1
2.2 Fundamentals of Real-Time Toolbox in Matlab........................................................2
2.2.1 Real Time Windows Target (RTWT) Toolbox..................................................2
2.2.2 What does Real-Time mean?............................................................................3
2.2.3 Real Time Workshop Toolbox and Real-Time Kernel (OS) built in Matlab.3
2.3 How to interface ADVANTECH PCI 1710 Daq Device with Simulink.......................5
2.4 Difficulties to Use the PCI 1710 DAQs Connector .................................................11
2.4.1 Tools...................................................................................................................11
2.4.2 Making Our Own Printed Circuit.....................................................................11
2.4.3 Notes about the Mixture ..................................................................................12
In our project we used Advantechs PCI 1710 Daq Device with the following
properties.
Before beginning the adjustment of configurations in Simulink for PCI 1710 we will
introduce the fundamental process and idea of how a PC (particularly Matlab) communicates
with a PCI Daq device over Windows Operating System in real-time and how Simulink
manages real-time application using Real Time Windows Target Toolbox under Windows
which is a non-real time Operating System. Then we will issue interfacing the PCI 1710 Daq
device with Simulink step by step.
2.2.1 Real Time Windows Target (RTWT) Toolbox
Figure shows a simple block diagram of an embedded system being tested using HILS.
You must install the real-time kernel once to use it. Installing the kernel configures it to
start running in the background each time you start your computer. To install the kernel:
In the MATLAB Command Window, type:
rtwintgt install
And precede the installation by pressing y.
Since we are to run Simulink models under the real-time kernel, Simulink needs to
convert the created models which consist of blocks into C code to generate an executable file
to be run under the real-time kernel. More precisely, we need to convert the Simulinks blocks
into C code to be used with the real-time kernel. Here the Real-Time Workshop Toolbox
comes into the consideration.
Real-Time Workshop generates and executes stand-alone C code for developing and
testing algorithms modeled in Simulink. The resulting code can be used for many real-time
and non-real-time applications. You can tune and monitor the generated code using Simulink
blocks and built-in analysis capabilities, or run and interact with the code outside the
MATLAB and Simulink environment.
Basically Real-Time Workshop provides the utilities to convert our Simulink model
into C code by the Real-Time Workshop Code Generation Software. Then it uses Open
Watcom C/C++ Compiler to compile and create a real-time executable file with .rwd extension
to be run with the real-time kernel. This compiler is supplied with the Real-Time Windows
Target software and no other compilers are needed or can be used.
Simulink External Mode Interface Module provides communication between Simulink
software and the real-time application. This module talks directly to the real-time kernel and is
used to start the real-time application, change the block parameters, and retrieve scope data.
So Simulink External Mode allows us to change parameters by editing the block diagram and
observe the effect of these changes while running a simulation in external mode, in real-time.
New parameter values are automatically transferred to real-time application while it is
running. That is the exact meaning of the word real-time. But note that not all parameter can
be changed in real-time. When some parameters have been changed the code needs to be
recompiled.
Parameters are changed from the Block Parameter Dialog Boxes. Opening a dialog box
for a source block causes Simulink to pause. While Simulink is paused, you can edit the
parameter values. You must close the dialog box to have the changes take effect and allow
Simulink to continue. Example parameters: amplitude of a gain, frequency of a sine wave.
Scope blocks can be used to visualize the signals in real-time applications to view the changes.
Here is the basic procedure of how a real-time application is run and configured:
We create a real-time application in the same way as we create any other Simulink model by
using the standard Simulink Blocks. The Real-Time Workshop code generation software
creates C code from our Simulink model. Then the Open Watcom C/C++ Compiler compiles
the C code to an executable that runs with the real-time kernel. When running our models in
real-time , RTWT software captures the sampled data from one or more input channels, uses
the data as input to our block diagram model, immediately processes the data and sends it back
to the outside world through an output channel on our I/O board.
2.3. How to interface ADVANTECH PCI 1710 Daq Device with Simulink
Creating a Model
You need to create a Simulink model before you can run a simulation
or create a real-time application.[1]. Here is the Simulink Model, let name it
deneme.mdl
Configuring a Model
After you create a Simulink model, you can enter configuration and
simulation parameters for use by Real-Time Workshop code generation software for
creating C code and building a real-time application.. These parameters control many
properties of the model for simulation and code generation. This section
contains the essential information you need when setting configuration
parameters for a Real-Time Windows Target application. After you create a
Simulink model, you can use the rtwinconfigset function to specify a default Real-Time
Windows Target configuration set for the model.[1]. But for the sake of understanding the
procedure we will follow the configuration manually.
Entering Configuration and Simulation Parameters Manually
The configuration parameters give information to Simulink software for running a
simulation in real-time.
1 In the Simulink window, and from the Simulation menu, click Configuration Parameters.
In the Configuration Parameters dialog box, click the Solver tab. The Solver pane opens.
2 In the Start time field, enter 0.0. In the Stop time field, enter the amount of time you want
your model to run. For example, enter 10.0 seconds.
3 From the Type list, choose Fixed-step. Real-Time Workshop code generation software does
not support variable step solvers.
4 From the Solver list, choose a solver. For example, choose the general purpose solver ode5.
5 In the Fixed step size field, enter a sample time. For example, enter 0.001 seconds for a
sample rate of 1000 samples/second.
6 From the Tasking Mode list, choose SingleTasking. (For models with blocks that have
different sample times, choose MultiTasking.)
Your Solver pane looks similar to the next figure.
12 Select the system target file for building a Real-Time Windows Target application, and
click OK.
The system target file rtwin.tlc, the template makefile rtwin.tmf, and the make
command make_rtw are automatically entered into the Real-Time Workshop pane.
Your Real-Time Workshop pane looks similar to the figure.
13 Click Apply to apply the changes to your model and OK for closing the pane.[1]
Creating a Real-Time Application
After you enter parameters into the Configuration Parameters dialog box for use by the
Real-Time Workshop code generation software, you can build a real-time application.
1 In the Simulink window, from the Tools menu, point to Real-Time Workshop, and then
click Build Model. (ctrl+B). The build process does the following:
The Real-Time Workshop code generation software creates the C code source files deneme.c
and deneme.h.
The make utility make_rtw.exe creates the makefile deneme.mk from the template makefile
rtwin.tmf.
The make utility make_rtw.exe builds the real-time application deneme.rwd using the
makefile deneme.mk created above. The file rtwin_model.rwd is a binary file that we refer to
as your real-time application. You can run the real-time application with the Real-Time
Windows Target kernel.
2 Connect your Simulink model to your real-time application.
Entering Additional Scope Parameters for Signal Tracing
Simulink external mode connects your Simulink model to your real-time application.
This connection allows you to use the Simulink block diagram as a graphical user interface to
your real-time application.
After you have created a real-time application, you can enter scope parameters for
signal tracing with Simulink external mode:
1 In the Simulation window, from the Simulation menu, click Configuration Parameters.
2 Select the Real-Time Windows Target node.The Real-Time Windows Target pane opens.
3 Select the External mode check box. The Real-Time Windows Target pane should appear
as follows.
4 Click OK.
5 In the Simulation window, and from the Tools menu, click External Mode Control Panel.
The External Mode Control Panel dialog box opens.
6 Click the Signal & Triggering button. The External Signal & Triggering dialog box opens.
7 Select the Select all check box. From the Source list, choose manual. From the Mode list,
choose normal.
8 In the Duration field, enter the number of sample points in a data buffer. For example, to
specify a sample rate of 1000 samples/second and a stop time of 10 seconds, enter 10000
9 Select the Arm when connecting to target check box.
The External Signal & Triggering dialog box looks like this:
10 Click Apply to apply the changes to your model and close to close the pane.
4 In the Simulation window, and from the Simulation menu, click Disconnect From Target.
2.4. Difficulties to Use the PCI 1710 DAQs Connector
The PCI DAQ card has 68-pin connector, shown above, which includes; analog ,digital
inputs and outputs, grounds and timer/counter pins.
Firstly, we had a problem to test it because in order to connect a cable to this connector i.e.
a digital meters cables were connected to it directly to measure the analog outputs. While
doing this, we were trying to be careful to get rid of short-circuit.
In short-circuit case between any pins , it will cause to get out of usage of the DAQ card.
Furthermore, like that, we cannot connect on it more than two cables. In electronics shopping
center in Turkey, an appropriate connectors are not sold. In short, we could not connect the
cables to the DAQ card efficiently and we have decided to make a circuit interface connector.
2.4.1. Tools
a) 34 double connectors ( klemens )
b) 68-Pin Shielded cable
c) A computer
d) A laser Printer
e) Enough size Copper board
d) A clothes Iron
e) 300ml Etchant (Hydrogen Peroxide H2O2)
f) 900ml Hydrochloric Acid (Tuz ruhu)
g) A plastic cup
i ) Any pcb program( we used Ares Professional program)
j) A clean A4 photo paper
2.4.2. Making Our Own Printed Circuit
We must indicate that it seems easy to implement and not to take long time. But, really it is a
hard work.
First of all, we bought the connectors and we guessed how long distance is there between
connectors pins. Using Ares program, which is together Proteus, we designed the ways for PCB boards
and put enough bigger dot to make a hole there.
As a second step, we printed it any paper to check whether it suits to our connector and our
copper board. After trying a few times, it suited and this was what we wanted and then we cleaned the
copper board and the photo paper. All in all, we printed it on the cleaned photo paper. Please note that,
just laser printed is worked for it because of its special chemical, we mean that any other printer will
not work for PCB.
As a next step, we carefully tape to hold the printed photo paper on the cleaned copper board in
one position without any movement. After this step, using a very hot iron, for a long time, we put the
Iron on our copper board because we waited to make the track pattern to transfer from the paper to the
copper board. Actually, we succeed this part at a second time. At first trying, we did not make it
enough hot and put the Iron on it for long, and without waiting it gets cool after transferring the track
to it, we made the copper board and the printed paper left each other. Fortunately, at the second time,
we put the Iron on them for long time, and then, we put it in water, then we observed that in water, the
copper left the paper easily.
Then, we put it in the mixture of 300ml- Hydrogen Peroxide and 900-Hydrochloric Acid
using a enough large plastic cup. Therefore, the tracks are appeared.
Finally, we cleaned and dry the board without damaging the tracks. In addition, we made a hole
on the dot where we put the Clemens and connect to the cable. After making holes on it, we found out
the cables sort to solid it and then we solid it and Clemens on it and tested them whether there is a short
circuit or not. In conclusion, there was no problem and we succeed it and its picture is below;
In this part of our project, we control the speed of the DC motor as rpm (root per
minute) with PI control.
The motor features;
R=3.6; which is the total of winding Ra and Terminal Rk, ohm
L=5.6*10^-3; which is the inductance, henry
J=.055*10^-3; which is the armature inertia,
beta=.021; which is the static friction loss
K1=.105; which is a constant
The motor state-space according to the above values:
A=[-R/L 0 -K1/L ; 0 0 1 ; K1/J 0 -beta/J]
B=[1/L ; 0 ;0]
C=[0 0 1]
D=[0]
P1=tf(ss(A,B,C,D))
A=
1.0e+003 *
-0.6429
0
1.9091
0
0
0
B=
178.5714
0
0
C=
0
D=
0
Transfer function:
3.409e005
-0.0187
0.0010
-0.3818
Output
Error
This table, which is above, may help to find the Kp and Ki coefficients.
Designing Simulink model for the real time speed control application:
In this part of our studying, we follow this steps;
1-Put the analog output instead of state-space
State-space substitute our DC motor
2- Connect the analog input as negative feedback with conversions
-Tachometer gives us the speed of the motor as voltage
-If its output is 14V, this means it is rotating at 1000rpm
-Using this information, we multiply tacho output with 1000/14
-If we want to show the speed as rad/second, then we multiply it again with 1/60
If one wishes, the one does not have to convert rpm to rad/sec, but this time the one should not
divide reference rpm with 60.
2.
Analog inputs give us a value between 0 and 1, if we multiply with 10, we get the
correct decimal value.
This correct decimal value is multiplied by 6. Because, our taco out is normally
maximum 30V, and our DAQ analog input should be in 5V. By using op-amp, we divide
it with 6. In short, to get the this correct value again, as software, we multiply it with 6.
This circuit is used as voltage divider which is shown below. For instance, if the
input is 24, the output is 4. The first op-amp output is -4V and then the second output is
4V. We have to use the second op-amp to make it positive due to the fact that DAQs
GNDs are short circuits.
So, final our .mdl file is shown below, and it is all mentioned above.
Here we have implemented the seven segments block diagrams in the Seven Segment
Block Diagram. We have taken the modulus of the time with respect to 0.1s. Then we have
divided the time into 4 equal time periods (0.025 0.050 0.075 0.100). If we are in the period of
0.000 - 0.025 seconds we choose the first seven segment and print the least significant decimal
value, then in the second period we choose the second seven segment and print the second
least significant value. This is called the scanning and we perform this process in the
simulation time interval. We have implemented this scanning process in the so called
Subsystem Blocks.
2.7 Results: Comparison of the actual systems outputs and simulation output
These values are taken at 500,1000 and 1500rpm respectively.
3.
CONCLUSION
Digital Control Systems Laboratory challenged us to improve our hardware and software
implementation abilities. There were lots of handicaps that we faced and overcame.
In the first place we have dealt with the software implementations of Advantech PCI
1710 Daq Device with Matlab. We have firstly tried to use the Daq device with Matlab *.m
files but then we have seen that using Simulinks Block Diagrams gave us more flexibility
about interfacing the Daq device and Matlab. Here the Real-Time Windows Target ToolBox
under Simulink supplies us Analog Input, Analog Output, Digital Input, Digital Output Blocks
to directly use the Daq device.
Matlab interacts with the
Advantech 1710 Daq device according
to the left side figure. This interaction is
basically supplied with the Simulinks
Real-Time Windows Target Blocks. In
the application we have done, our sensor
is Tachometer which gives us the speed
as voltage. Our actuator is Current
Driver which drives the motor.
After we have learnt about Matlabs abilities we then discovered that lots of real-time
applications can be implemented with Matlab and Simulink. Matlab includes lots of tools such
as RTW, RTWT, xPC, and many. Such tools connect the applications to the real world easily
via Daq device. Actually, these connections can be done with C, but with much more effort.
In the next step, that is after we were able to use the Simulinks I/O blocks we have dealt
with the speed control of a DC Motor with the PI control. The simulations and the actual
results concerning the systems error and tachometer output have fitted in the acceptable
range. Then we have implemented the software and hardware setup to show the motors speed
in rpm at 4 digit seven segment display.
Referances:
[1]RTWT User Guide
[2]http://www.biltek.tubitak.gov.tr/merak_ettikleriniz/index.php?kategori_id=6&soru_id=3705
[3]http://homepage.eircom.net/~ei9gq/pcb.html
[4]University of Virginia, Course Lectures