Di. Josef Kollmitzer
09-06-1994, 07:11 PM
This is the summary of our QUERY about MATLAB DRIVEN A/D BOARDS
done in BIOMCH-L and comp.soft-sys.matlab newsgoups some weeks ago.

The original Text on Biomch-L was:

> Dear Biomch-l readers:
> We are developing EMG Gaitanalysis applications in MATLAB. I am looking for
> A/D-Boards for PC, able to be driven directly by MATLAB comands. I hope that
> someone out there solved the problem already and wrote drivers for any
> PC-A/D-Board.

================================================== ====================
>From "Christoph Reinschmidt"
In case you don't get any useful responses from Biomch-l,
you could also post your question to the usenet newsgroup
comp.soft-sys.matlab. I am sure that the readers of
comp.soft-sys.matlab can help you.
Biomch-l co-moderator

From: "Ben F. Willems"
We are currently using Labview (National Instruments in conjunction with
Matlab. Labview is used for data acquistion and Matlab is used for the
analysis. To tell you the truth, most of the types of analysis that you could
possibly do in Matlab you can do just as well in Labview. The way of
programming is just very different (everything is completely visually oriented
instead of the scripting you do in Matlab). The learning curve for Labview is
very short. We have learned and mastered it in less than three months and
that included the writing of our data acquisition software. We are using a 64
channel NI board with a total throughput of 200 kHz.
Anyway, a colleague of mine wrote an m-file in Matlab, because he had written
his whole (emg-) analysis in Matlab and we later on bought Labview. To save
time he wrote the converter for Labview to Matlab.
Organisation: Hospital for Joint Diseases
Occupational and Industrial Orthopaedic Center

From: Oyvind Stavdahl
A friend of mine, Finn Haugen at the Telemark Institute of Technology,
Norway, has developed a (so far) non-commersial software package called
MATLAB on-line. The package is written to work with an analog I/O card called
PCL812 and PC/AT/386/WINDOWS-MATLAB 3.5/MATLAB ver 4.0.
Finn Haugen's internet address is , I recommend
that you contact him.
Organisation: THE UNIVERSITY OF TRONDHEIM, Dept. Engineering Cybernetics

Just my 10 cents (in case no driver turns up):
If you wan't to communicate with an A/D board from within Matlab, I
would suspect the communication routines will have to be written in C
and compiled as a MEX file...
Company: University of Umea SWEDEN, Dept. Computing Science

================================================== =====================

From: Ernst B Zwick

Original text:

> I am working in an electromyographic research unit. For the acquisition
> of our signals we use several different software packages. As we do most
> of our signal processing in Matlab and developed our own toolbox for it
> we also would like to control an AD-Bord under Matlab and display the
> signals in a grahpics window.(real time?)
> We would really appreciate if somebody could mention existing routines or
> drivers to us which can operate with a comercially available Board.
> Any information or suggestion?

> Does anyone know of a package, which enables interaction between MATLAB and
> laboratory control and measurement instruments (for example, GPIB)?
> Such a package should do the following:
> 1. Receive input from the user (preferably, in a graphic interface) - for
> example, use a slider to specify the required temperature in the
> experiment.
> 2. Interact with the hardware (or with a program that controls it) to
> transmit
> the required parameters.
> 3. Collect data from a measurement instrument (or, receive it from a
> program that controls it).
> 4. Enable the user to choose (preferably, with graphic interface) which
> data to display, and plot that data.
> The data should be available for further computations.
> We would like to know about any package that does all or part of the above
> tasks.
> Thank you,
> Smadar Shatz

> How can I capture near real-time data in MATLAB?
> i've looked at the manual and FAQ and i don't see
> any discussion on this topic. Any tips will be
> helpful.felipe@puente.jpl.nasa.gov (Felipe Hervias)

From: Malachy DEVLIN - SPD
Organization: Signal Processing Division, University of Strathclyde. Glasgow
Just seen your posting about data acquisition and MATLAB, we currently
have a software product which integrates MATLAB and the TMS320C40 DSP
processor. It allows MEX to be recompiled with changes to run on this
processor, but as it is possible to get a range of acqusition modules for
this processor it is possible to grab data from a A/D convertor into
the DSP which can perform some real time processing (e.g. FFT) and present
this to MATLAB for display...

From: Christophe Flatau
..I am representing in Europe the DSP Technology which is just starting to
sell the product called SigLab which was described in the latest Newsletter
from MathWorks. This is a complete hardware/software solution which
provides a full link between the real-world data and MatLab. The software
that drives the SigLab is developed using the MatLab version 4.2 Graphic
User interface. The box is driven directly from MatLab by Virtual
Instruments which can program it to behave like an oscilloscope, spectrum
analyzer, arbitrary/function generator, network analyzer (frequency
response measurement), system identification (finding poles and zeros of a
system). All these measurements are done in the real-time by the SigLab
itself and the measurement results are in the MatLab compatible .mat
format. So the hardware box does the job that is usually done by an
advanced FFT Analyzer. It has two inputs and two outputs with 20KHz
bandwidth (51.2KHz sampling rate) and 90 dB dynamic range. These were the
good news, the bad news is that this software won't operate on your AD
board, it will only work with SigLab. If you are still interested please
send me the e-mail or call/fax at (33.1) 43 26 87 93.

From: "Jan Houska"
Organization: Czech Technical University
There are basically two possibilities. The first is Real Time Workshop
from The MathWorks. This is a package designed to generate C code from
Simulink model and then to compile the C code for your target platform
(the computer you want to run the controller on). Then you load the
resulting code onto your target computer and run it. Currently supported
platforms are PC with several data acquisition cards, dSPACE controllers
and VxWorks OS. It is basically meant for industrial control.
Another possibility, if you use MS-Windows, is to use Real Time Toolbox
from HUMUSOFT s.r.o. This one allows direct access to real time services
and data acquisition cards from Matlab, without the need of compiling and
loading anything. Plants with sampling periods about 100ms are perfectly
OK and tested. This again depends on the computer you use and also on your
A/D cards and version of Matlab. If you want more info please send me
e-mail. This solution is cheaper and more interactive but slightly less
robust, basically intended for university labs and not so critical
measurement and control.

From: haode@ifm.liu.se (Hans Odeberg)
We've done some work connecting measurement instruments to
Matlab in our student labs; it does however not contain *any*
menues or graphic interfaces whatsoever. You would have to do
that part yourself.
Currently supported cards are:
National Instruments GPIB card
Capital Equipment Corp. GPIB card
Data Translation DT2801 A/D + D/A + digital I/O card
Microstar labs DAP series A/D + D/A + digital I/O cards
Since it is a university product the price is zero, and the
level of support somewhere in that region too...

From: malcolm@interval.com (Malcolm Slaney)
Bill Stafford and Dick Lyon at Apple put together a set of MEX functions
that do GPIB data collection package for Matlab 3.5. I'm pretty sure that
it's still being used in a couple of analog VLSI labs for verifying chip
operation.Look in /pub/malcolm/GPIB* on ftp.apple.com for more details.

From: Rick Paxson pax@mathworks.com
Not without writing some code.
Take a look at the External Interface Guide p. 27
It gives you the structure of the mat-file so you
can use matlab's file I/O to scan for the size and name of
the matrices. You will probably still find matGetDir useful
to find out how many matrices are in there.

From: neurocomp@ludens.elte.hu
I'd like to introduce myself as a Matlab user who has exactly the same
which you outlined in your inquiry in newsgroup comp.soft-sys.matlab.
I don't have found yet the final solution, sorry, but have some information
which I append to this letter.
Would you be so kind, please, to forward the info and suggestions you will
receive from other users.
I'm glad to find your letter and hope we can help each other.

Our aim of Matlab application is the following (in nutshell): we want to
involve IBM PCs in our physiological education in such a manner that our
students work in Matlab for Windows environment.
The data sampling during the experiments we'd like to initialise by some
Matlab function with the aim of a driver for our self-devised interface
board (A/D, DMA controller, D/A, I/O ports, timer). For this reason we'd like
to devise this special driver for our board. (We have already drivers for
DOS). Therefore we asked for some important info on memory management from
the MathWorks which I appended (between double asterisk lines) to this
message. You may find useful in that case when you also intend to design
a driver.
There are however boards and drivers especially for Windows, e.g. GENIE
from Advantech. This info comes from the Imperial College, but they use
for DOS. So they don't have experiences with this board. They suggested to
solve multitasking problems by PIF editor (foreground/background settings)...

************************************************** *******************
************************************************** *******************

You can probably prevent MATLAB (and all other Windows programs) from
using certain areas of memory by specifying this to your memory
manager. However, the specifics of doing this are dependent on the
memory manager you use and the interface card you use. The best way
to find out how to do this would be to contact the makers of the
interface board.

To access the board from MATLAB, you will want to write a
MEX-function, using either the Microsoft C or Borland C compilers to
create a DLL MEX-function. For information about writing
MEX-functions, you should refer to the MATLAB External Interface
Guide. Also, appended to this email is a technical note from Borland
describing how to perform Direct Memory Access from within a DLL or
other piece of Windows code. This will show you how to do the actual
DMA from your MEX-function.

If you have further questions regarding this issue, please be sure to
mention the above Technical Support Reference number in your email
response to me.

Scott French
Technical Support Engineer
The MathWorks, Inc.

DATE : October 19, 1993

TITLE : Using Windows Exported Selectors

To allow access to various physical memory locations containing
information related to the system setup or hardware devices,
versions 3.x of Microsoft Windows exports several selectors (the
selectors are more specifically exported by the KERNEL module of
Windows). The exported selectors include the following:

Selector Base Description
======== ====== =========================================

__0000H 00000H Real Mode Interrupt Vector Table
__0040H 00400H BIOS DATA AREA
__A000H A0000H EGA/VGA Graphics RAM
__B000H B0000H MDA RAM - Hercules Graphics RAM
__D000H D0000H Miscellaneous
__E000H E0000H Miscellaneous
__F000H F0000H System/BIOS ROM

To access the physical memory using the KERNEL Exported Selectors
from your Borland/Turbo C/C++ Windows Applications, the following
approach may be used:

(l) Declare an extern far variable ( of type WORD )
corresponding to one or more of the selectors listed
above. For example:

extern WORD far _B000H; // KERNEL's MDA Selector

NOTE: Since the Borland C/C++ Compiler automatically
inserts a leading underscore the extern variable
has only one underscore.

(2) Declare a far pointer whose segment is initialized with
the LOWORD of the address of the external variable
mentioned in section (l) above. For example:


extern WORD far _B000H;

void far * GetMDARamPtr()
void *lpMDA = MK_FP(LOWORD(&_B000H), 0x0000);

The far pointer obtained from section (2) can be used to access
the physical memory from a Windows Application. Since the
selectors are exported by Windows KERNEL module, the IMPORT
library (IMPORT.LIB) provided with Borland C++/Turbo C++ for
Windows contains a reference to the selectors hence enabling the
linker to resolve the external variable defined in section (1).

The selectors (and far pointers) must be used with caution since
the Windows 3.0 does not enable any protection attributes on the
selectors exported by Kernel.

The following code provides an example of the technique described
above. The current "Video Mode" is read from the BIOS Data Area
(@0040:0049) using the 0040H selector and displayed using the
Windows API function MessageBox.

/* ************************************************** *********
/* Using Windows Exported Selectors Example */
/* ************************************************** *********


extern WORD far _0040H; // Kernel Selector: BIOS Data Area
extern WORD far _B000H; // Kernel Selector: MDA Video RAM

int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR CmdLine,
int nCmdShow)
char szBuff[80], cVideoMode;
char far *lpBDARam = (char far *)MK_FP(LOWORD(&_0040H), 0);

cVideoMode = *(lpBDARam + 0x49); // Video Mode: 0040:0049

wsprintf(szBuff, "Video Mode ( _0040H:0049H): 0%Xh (%d)\n"
"Use __B000H to write mode to Mono Screen?",
cVideoMode, cVideoMode);
MessageBox(NULL, szBuff, "Video Mode",

( 13898 )

************************************************** **********************
************************************************** **********************

From: Daniel Berinson
It is possible to call standard C code from Matlab using the
mex file facility. This works by linking a the Matlab external
library with your own code and once setup is quite transparent
to the Matlab script programmer, who just calls the appropriate
routines like a typical m-file. For instance, the C code
initialises and queries the AD-board, returning the values as
an array to Matlab. You can use just about any commercial board.