Opto 22

From Chemical Engineering @ UP wiki
Revision as of 11:45, 25 August 2009 by 137.215.117.195 (Talk)

Jump to: navigation, search

OpTo is how we send/receive information from the rigs.

In the PM&C laboratory, all analog to digital conversion is handled by the OPTO22 units in the central box in the laboratory. The control units for each group of AD modules is known as a Brain, and is connected to the network so that all the computers on the local network (and maybe even the Internet in the future) are able to access the values of the readings and write outputs to the rigs.

A Simulink example shows how to access a rig through Matlab. Basically you need an opto22.m file in the appropriate Matlab directory refering to the point number on the opto. You also need the rtclock.dll and rtc.mdl files to keep everything synchronised. Make sure that you also have the rtclock.c-file. If you have trouble with this procedure, follow any one of the three methods below to syncronize real time with simulation time.

Matlab has a separate product called "Real-Time Workshop" to syncronize real time with simulation time. The Real-Time Workshop can create stand-alone executable files which will run in real-time when under a Real-Time Operating System/embedded system. For more on this product, please see:

http://www.mathworks.com/products/rtw/. 

It is also possible to turn you own PC into a Real-Time Operating System, with the Real-Time Windows Target. For more information about this product, please have a look at the following URL:

http://www.mathworks.com/products/rtwt/.



If you are only interested in slowing your model down within Simulink to view results, please see the following:



There are three example folders in the attached zip file.



-----------------Example 1:--------------------------


An example of a MATLAB function which goes into a "busy wait" loop which kills time to slow down the simulation until the real-time clock catches up to the Simulink clock:



(1) Open the folder example1

. (2) Run the model rtc.mdl.



------------------Example 2:--------------------------


An example of a C-MEX S-function that compares simulation time with the system clock time to slow down the simulation speed:



(1) Open the folder example2

. (2) Execute the command 
MEX sfun_time.c

. (In the MATLAB command-line). (3) Run the model rtc_C.



-------------------Example 3:------------------------


A MEX-file which syncs a simulation to the PC internal clock or the UNIX system clock. This is an older example the was created for Simulink 1.3c:

(1) Open the folder example 3. 

(2) Execute the command
 CMEX rtclock.c 
in MATLAB 4.x 
or 
MEX rtclock.c 
in MATLAB 5.x and above.

 (3) Run the M-File rtc.m to create a new model with a "Real-time clock" block created from the C-file above.



In all of these examples the sine function acts as "simulation". The other simulation can just be dragged into the system where you want to syncronize.

Please note that all of the above examples will allow the system will run approximately Real-Time, but not exactly. If you need the simulation to run in exact Real-Time, please look at the Real-Time Workshop along with a Real-Time Operating System.

Before your PC will communicate through the LAN you need to run the opto22 service. Start by coping the .dll from here (right click and save as...) to c:\windows\system32. Then run cmd and start the service with

regsvr32 MatLabOpto

You will get a success message.