You are on page 1of 6

Engineering Science and Technology, an International Journal 19 (2016) 964–969

Contents lists available at ScienceDirect

Engineering Science and Technology,


an International Journal Press: Karabuk University, Press Unit
ISSN (Printed) : 1302-0056
ISSN (Online) : 2215-0986
ISSN (E-Mail) : 1308-2043

j o u r n a l h o m e p a g e : h t t p : / / w w w. e l s e v i e r. c o m / l o c a t e / j e s t c h
H O S T E D BY

Available online at www.sciencedirect.com

ScienceDirect

Full Length Article

Microcontroller USB interfacing with MATLAB GUI for low cost


medical ultrasound scanners
Jean Rossario Raj a,*, S.M.K. Rahman a,b, Sneh Anand a,b
a Center for Bio-Medical Engineering, Indian Institute of Technology, New Delhi, India
b Biomedical Engineering Unit, All India Institute of Medical Sciences, New Delhi, India

A R T I C L E I N F O A B S T R A C T

Article history: This paper presents an 8051 microcontroller-based control of ultrasound scanner prototype hardware
Received 13 December 2015 from a host laptop MATLAB GUI. The hardware control of many instruments is carried out by
Received in revised form microcontrollers. These microcontrollers are in turn controlled from a GUI residing in a computing machine
1 January 2016
that is connected over the USB interface. Conventionally such GUIs are developed using ‘C’ language or
Accepted 12 January 2016
Available online 1 February 2016
its variants. But MATLAB GUI is a better tool, when such GUI programs need to do huge image/video pro-
cessing. However interfacing MATLAB with the microcontroller is a challenging task. Here, MATLAB
interfacing through an intermediate MEX ‘C’ language program is presented. This paper outlines the MEX
Keywords:
MATLAB programming methods for achieving the smooth interfacing of microcontrollers with MATLAB GUI.
MEX program © 2016, Karabuk University. Publishing services by Elsevier B.V.
Microcontroller
Ultrasound scanner
USB
USBXpress

1. Introduction language [10,11]. The quality metrics and visual perception in


ultrasound imaging under different imaging conditions using
Microcontroller-based systems offer major advancement as an MATLAB test bench were studied in [12]. In MATLAB, there are
internal and external control. Microcontrollers can control major- many built-in functions and routines that enable faster rollout of
ity of the internal devices in a typical circuit board. Moreover majority the application [13]. MATLAB has a very large database of built-in
of the chips also have built-in interfaces that can be controlled by algorithms for mathematical modeling, image processing, simula-
the microcontroller. They have USB interface through which it is in- tions and computer vision applications [14,15]. MATLAB has the
terfaced with external devices such as a computer or a server [1]. ability to read in a wide variety of both common and domain-
A low-cost USB interface for operant research using Arduino and specific image formats.
Visual Basic is presented in [2]. Many data acquisition systems use However the major challenge is in interfacing the MATLAB ap-
microcontroller and USB interface [3]. The microcontroller pro- plication with the microcontroller to get the best of both worlds.
gramming is done in traditional ‘C’ language. Microprocessors and Such requirements involve live reading of images, videos, and direct
microcontrollers provide the path for the integration of hardware processing and display [16]. One application where we came across
and software [4]. Microcontrollers have far-reaching applications the challenge is while developing a prototype for a medical ultra-
in the field of instrumentation [5,6]. sound scanning machine [17,18]. The application was made in
The application in the host computer or the server is generally MATLAB to take advantage of the rich image and video processing
written in languages like ‘C’ or its variants like C++, Visual C++, Java, capabilities [10,19]. The hardware has USB interfacing to the
etc. [7]. The microcontroller manufacturers provide interface pro- microcontroller for configuration of the various parameters of
grams in the form of windows dynamically linked libraries (DLL), the internal chips and for performing different operations [20–22].
which can be compiled along with the applications for interfacing The microcontroller interfaces with different internal chips, such
with the microcontroller [8,9]. as ADC, transmit side FPGA (TxFPGA), receive side FPGA (RxFPGA),
For applications involving signal processing, image processing etc. [23,24]. The block schematic of microcontroller interfaces is
or video processing, MATLAB is a more suitable programming shown in Fig. 1. The ADC has custom serial bus programming
whereas FPGAs used Serial Peripheral Interface (SPI) program-
ming. The interface programs toward these devices were also
developed for the microcontroller as well as the FPGAs.
* Corresponding author. Tel.: +91 9811084119; fax: +91 1126862037.
E-mail address: bmz108120@cbme.iitd.ac.in (J.R. Raj). Neither MATLAB nor the microcontroller manufacturers provide
Peer review under responsibility of Karabuk University. the interface logic for interworking. Hence interworking between

http://dx.doi.org/10.1016/j.jestch.2016.01.008
2215-0986/© 2016, Karabuk University. Publishing services by Elsevier B.V.
J.R. Raj et al. / Engineering Science and Technology, an International Journal 19 (2016) 964–969 965

Tx FPGA

Address / Data
bus Interface
Serial
USB Interface
Interface Micro
ADC controller

SPI MDIO
Interface Interface

Gigabit
Rx FPGA Ethernet Phy

Fig. 1. Block schematic of the experimental setup.

the MATLAB GUI and the microcontroller is a challenging task. The The USBXpress includes windows device drivers, device driver in-
novel method used for interfacing using a C language interface func- staller, host interface function library (host API) provided in the form
tion called MEX program is described in this paper. of a DLL, and device firmware interface function library. Some of
the important functions performed by the host API are given in
2. Materials and methods Table 1. While performing each function, the function returns the
status of the operation like SI_SUCCESS or SI_DEVICE_NOT_FOUND
2.1. Interfacing architecture or SI_INVALID_PARAMETER, along with any return values to take
suitable corrective steps in read or write logics. The API is used in
The logical block schematic of the MATLAB GUI and an interrupt driven mode. The c8051340.h and USB_API.h files sup-
microcontroller interfacing with USB is given in Fig. 2, which indi- plied as part of the application are added to the project in addition
cates the microcontroller side as well as the MATLAB GUI side logic to the “main” firmware file. While building the target, the USBXpress
used for the study. A Silicon Laboratories C8051F340 microcontroller library file, USBX_F320_1.LIB is linked as an external object.
is used. It operates at a maximum speed of 48 MHz with 4 k of on-
board RAM (XRAM) and 64 k flash memory. The microcontroller has 2.3. Microcontroller firmware
integrated USB receiver and USB controller. It is 48 IO pins config-
ured as 5 IO buses of 8 IOs each. The microprocessor in the In the developed prototype, the microcontroller configures the
ultrasound scanner prototype interfaces with a bank of ADCs and different chips like ADC, FPGA, etc., through the control from the
FPGAs. The microprocessor firmware is written in C language. One MATLAB GUI. Hence the microcontroller firmware implements
IO Bus is used as the programming header for programming the the USB interface logic as well as the interface logic for the other
microcontroller. The firmware is transferred to the microcontroller devices. The header and the source files developed for the inter-
using the programmer hardware by M/s Silicon Labs. The develop- facing with the ADC, TxFPGA, RxFPGA and PHY device using the four
ment required the USBXpress API provided by M/s Silicon Labs for IO Buses are included in the firmware. Even though the ADC side
including in the microcontroller firmware, firmware develop- does not require any separate software logic, the FPGA side re-
ment, USBXpress driver installation in the host computer, installation quires the hardware logic written in languages such as Verilog or
of C++ compiler (Visual C++ used), development of the MEX file, de- VHDL. Similar interface logic is written in the FPGA side also for the
velopment of the MATLAB GUI, and compilation and linking of the read and write operations using the SPI interface. The SPI inter-
MEX file from MATLAB. face has read, write, chip enable, Master in Slave Out (MISO) and
Master Out Slave In (MOSI) pins for the interconnection. The
2.2. USBXpress API USB_API.h includes the definitions needed by common code to
control the state of the USB peripheral, but this doesn’t need to know
The Silicon Laboratories USBXpress provides the host and device about the specific implementation. The USB_API.h for the USB in-
software solution for interfacing communication bridges to the USB. terface functions and other files like C8051F340_def.h,
A high-level Application Program Interface (API) for both the host compiler_defs.h, stddef.h, stdio.h etc. are included in the compila-
software and device firmware is used to provide USB connectivity. tion. The flowchart of the firmware is given in Fig. 3.

USBXpress USBXpress
Micro USB USBXpress MEX
Library (API) Driver MATLAB
controller DLL supplied Program in
supplied by installed in GUI
Firmware by SiLabs C (DLL)
SiLabs Laptop

Microcontroller Program Laptop Program

Fig. 2. Microcontroller MATLAB interface.


966 J.R. Raj et al. / Engineering Science and Technology, an International Journal 19 (2016) 964–969

Table 1 Table 2
USB API device interface functions. USB DLL interface functions.

Function name Function Function name Function

USB_Clock_Start Initializes the USB clock SI_GetNumDevices Returns the number of devices connected
USB_Init Enables the USB interface SI_GetProductString Returns a descriptor for a device
Block_Write Writes a buffer of data to the host via USB SI_Open Opens a device and returns a handle
Block_Read Reads a buffer of data from the host via USB SI_Close Cancels pending IO and closes the device
USB_Int_Enable Enables API interrupts SI_Read Reads a block of data from the device
USB_Disable Disables USB interface SI_Write Writes a block of data to the device
USB_Suspend Suspends the USB interface SI_SetTimeouts Sets read and write block timeout
SI_CheckRXQueue Gets the number of bytes in the device Rx Queue

2.4. USBXpress DLL


These functions are called for reading and writing data to the USB
M/s Silicon Labs has provided the USBXpress DLL as ‘SiUSBXp.dll’. interface from the MEX program file.
This acts as the interface between the USBXpress driver in the host
computer and the MEX file. The important functions supported by 2.5. MEX interface
the DLL are given in Table 2. The user initiates communication with
the target USB device(s) by making a call to SI_GetNumDevices. This The core of the work is in the development of a MEX (MATLAB
will return the number of target devices. This number is used when executable) file in C language whose functions are called from
calling SI_GetProductString to build a list of device serial numbers MATLAB. Also the MEX integrates the USBXpress DLL for connec-
or product description strings. To access a device, it is opened by a tivity with the microcontroller. Thus the MEX file acts as the interface
call to SI_Open using an index determined from the call to between the MATLAB and the microcontroller. The MEX header file
SI_GetNumDevices. The SI_Open function will return a handle to contains the function declarations. The MEX C++ file includes the
the device that is used in all subsequent accesses. Data I/O is per- ‘SiUSBXp.h’ file for the MEX file, which in-turn calls the functions
formed using the SI_Write and SI_Read functions. When I/O of the ‘SiUSBXp.dll’. The flowchart of a function for reading the
operations are complete, the device is closed by a call to SI_Close. TxFPGA parameters is given in Fig. 4.

Start

USB_Clock_Start
USB_Init
Port Initialisation
Timer Initialisation

Initial Configuration of
Interfaces and Devices

Wait for Interrupt

Device Suspend
Interrupt Stop
Type
USBXpress
Block Read

Case 1
T Write to TxFPGA
F
Case 2 Write to RxFPGA
F T
Case 3 Write to ADC
T
F
Case 4 Write to PHY
F T
Case 5 Read from TxFPGA
F T
Case 6 Read from RxFPGA
F T Block
Case 7 Read from ADC Write
F T
Case 8 Read from PHY
F T

Fig. 3. Flowchart of microcontroller firmware.


J.R. Raj et al. / Engineering Science and Technology, an International Journal 19 (2016) 964–969 967

SI_GetNumDevices
F Ethernet
Case Success Return Error
MAC
T
SI_GetProductString Ethernet
T
F PHY
Case Success Return Error
T
Rx FPGA
SI_SetTimeouts
Micro
T
F controller
Case Success Return Error
T
SI_Open

F
Case Success Return Error
T
SI_Write
F Tx FPGA Receiver & ADC
Case Success Return Error
T
Fig. 5. Ultrasound scanner prototype hardware.
SI_CheckRXQueue
<1
Bytes in Queue

microcontroller interface. The AD9272 configurations include the


SI_Read
LAN Gain, VGA Gain, AAF upper and lower cutoff frequencies,
F
Case Success Return Error enabling/disabling of different test patterns, etc. The enabling of dif-
T ferent ultrasound channels are performed by configuring the pulsers
SI_Close through the TxFPGA by way of microcontroller. All these configu-
F ration parameters are coded as binary values and passed to the
Case Success Return Error microcontroller. The various register values in these devices for their
T individual configuration are also read and written through this
Return Data
interface.
Finally the start and stop of ultrasound scan with the proto-
Fig. 4. MEX function flowchart for reading a register value.
type is also controlled through the microcontrollers by configuration
of the FPGAs in transmit and receive directions. For phantom testing,
an Agar–Agar phantom was prepared. The ultrasound scan image
Similarly the other required functions are also built in the MEX
is taken using a phantom with an inclusion as shown in Fig. 7. The
file. The required Silicon Laboratories library files SiUSBXp.dll,
image is taken using a linear array transducer probe at 4 MHz. The
SiUSBXp.h, SiUSBXp.lib and SiUSBXp.exp are placed in the same
receive beamforming, image and video processing algorithms like
project folder. The MEX file is compiled into a DLL by using MATLAB
smoothening, sharpening, histogram equalization etc. are per-
linked Visual C++ compiler. The MEX file can be compiled directly
formed in MATLAB. The receive beamforming involved delay and
from the project using the Visual C++ application also. The DLL
sum algorithm of the simultaneously received channels. The posi-
created in this case is with name ‘USConfig.dll’. The library file
tion of the inclusion as well as the depth of the phantom is marked
‘USConfig.lib’ containing all the function names is also placed in the
in Fig. 7.
same folder of the project.
The MATLAB program directly calls the MEX functions from the
MATLAB file or command prompt using ‘loadlibrary’ and ‘calllib’ func- 4. Conclusion and discussion
tions of MATLAB. These functions are suitably included as part of
the MATLAB GUI code wherever required. The MATLAB interfacing with microcontroller is a major break-
USBXpress comes with its own driver that needs to be in- through in the design of the ultrasound machine. This enabled
stalled on the host computer. Once the driver is installed, the host various signal, image and video processing requirements to be easily
computer automatically recognizes the microprocessor when it is carried out using the MATLAB built-in functions [13]. The raw data
plugged in. captured were digitized and sent to MATLAB for further process-
ing. Thus many of the hardware processing were transferred to
3. Results software algorithms in MATLAB, like the beamforming, etc., in host
computer, thus reducing the size and complexity of the hardware.
A prototype developed for the ultrasound scanner with USB in- The software processing of Doppler ultrasound system with USB-
terface toward the MATLAB GUI is shown in Fig. 5. The prototype based high data rate communication is presented [21], where the
has the Silicon Laboratories C8051F340 microcontroller, Xilinx FPGAs digital signal processing is shifted from hardware to software al-
and ADCs (AD9272) from Analog Devices. It has the microcontroller gorithms. This also helped in the development of an ultrasound
programming header as well as the USB interface. The different com- machine suited for tele-medicine applications [23].
ponents above in the hardware are marked in Fig. 5. This interfacing has larger implications in other wide areas of
The MATLAB GUI is shown in Fig. 6. The various ADC, FPGA, PHY, microcontroller control and programming, and hence is a very in-
etc. configurations are performed from this GUI using the button novative approach. This also has many applications in areas of
click functions of the GUI buttons. These functions in turn call the sensors, including medical electronics. There are large numbers of
MEX interface functions and pass the required values toward the implementations of microcontroller interfacing with native ‘C’ or
968 J.R. Raj et al. / Engineering Science and Technology, an International Journal 19 (2016) 964–969

Pulser channel enabling ADC configuration

Read or Write Configuration Register Values

Fig. 6. MATLAB GUI for configuration of various scanner parameters.

Java applications. However there are no such implementations avail- References


able for the interfacing of the microcontroller with MATLAB.
In this application, the data received from the ultrasound trans- [1] C.-H. Huang, M.-F. Chiu, J.-F. Chou, USB interface data transmission device and
ducers are captured as Ethernet packets through the Ethernet USB interface data communication system. Google patents, 2012.
[2] R. Escobar, C.A. Pérez-Herrera, Low-cost USB interface for operant research using
interface. As a future step, capturing the packets through the USB Arduino and Visual Basic, J. Exp. Anal. Behav. 103 (2015) 427–435, doi:10.1002/
interface can also be implemented. jeab.135.
[3] A. Bora, K.C. Sarma, Design of a USB based multichannel, low cost data
acquisition system using PIC microcontroller, Int. J. Comput. Appl. 59 (2012)
Acknowledgments 5–8.
[4] A. Al-Dhaher, Integrating hardware and software for the development of
microcontroller-based systems, Microprocess. Microsyst. 25 (2001) 317–328,
The authors thank the Department of Science and Technology, doi:10.1016/S0141-9331(01)00124-7.
Government of India for providing financial support for this project [5] V. Kaundal, A.K. Mondal, P. Sharma, K. Bansal, Tracing of shading effect on
underachieving SPV cell of an SPV grid using wireless sensor network, Eng. Sci.
with Grant Number SR/WOS-A/ET-24/2008. The authors also state
Technol. (2015) doi:10.1016/j.jestch.2015.03.008.
that the sponsor does not have any role in study design; collec- [6] B. Mondal, M. Meetei, J. Das, C.R. Chaudhuri, H. Saha, Quantitative recognition
tion, analysis and interpretation of data; writing of the report; and of flammable and toxic gases with artificial neural network using metal oxide
gas sensors in embedded platform, Eng. Sci. Technol. 18 (2015) 229–234,
in the decision to submit the article for publication.
doi:10.1016/j.jestch.2014.12.010.
[7] D.T. Martinez, T.U. Ganiron Jr., C.S. Lacsamana, Development of
hardware interfacing system for Visual C++, Int. J. Adv. Appl. Sci. 2 (2013)
201–204.
[8] T. DeBoer, P. Carbone, J. Waldman, D. Johnson, R. Dautel, System and method
for communicating with a microcontroller. Google patents, 2013.
[9] P.C. Pradhan, R.K. Sahu, S. Panda, Firefly algorithm optimized fuzzy PID controller
for AGC of multi-area multi-source power systems with UPFC and SMES, Eng.
Sci. Technol. (2015) doi:10.1016/j.jestch.2015.08.007.
Reflection by
[10] J. Ferrer-Buedo, M. Martínez-Sober, Y. Alakhdar-Mohmara, E. Soria-Olivas, J.C.
inclusion
Benítez-Martínez, J.M. Martínez-Martínez, Matlab-based interface for the
simultaneous acquisition of force measures and Doppler ultrasound muscular
images, Comput. Methods Programs Biomed. 110 (2013) 76–81, doi:10.1016/
j.cmpb.2012.09.009.
Reflection from [11] R. Gupta, J. Bera, M. Mitra, Development of an embedded system and MATLAB-
bottom surface based GUI for online acquisition and analysis of ECG signal, Measurement 43
Phantom with inclusion
(2010) 1119–1126, doi:10.1016/j.measurement.2010.05.003.
[12] X. Zhao, J. Zhou, W.-F. Loke, M. Chirala, C. Zhang, Quality evaluation of ultrasound
imaging using a MATLAB test-bench, in: SPIE Medical Imaging, International
Society for Optics and Photonics, 2013, p. 867516.
[13] J. Blahuta, T. Soukup, P. Čermák, D. Novák, M. Večerek, Semi-automatic
ultrasound medical image recognition for diseases classification in neurology,
in: Advances in Intelligent Analysis of Medical Data and Decision Support
Fig. 7. Ultrasound image of a phantom with inclusion captured in the prototype. Systems, Springer, 2013, pp. 125–133.
J.R. Raj et al. / Engineering Science and Technology, an International Journal 19 (2016) 964–969 969

[14] N. Sandeep, C. Sulochana, Dual solutions for unsteady mixed convection flow [19] J.J.R. Raj, S. Rahman, A. Sneh, Electronic hardware design for ultrasound transient
of MHD micropolar fluid over a stretching/shrinking sheet with non-uniform elastography, Int. J. Eng. Sci. Technol. 4 (2012) 3700–3704.
heat source/sink, Eng. Sci. Technol. 18 (2015) 738–745, doi:10.1016/ [20] D. Jones, Smartphone-compatible ultrasound probe, J. Diagn. Med. Sonogr. 30
j.jestch.2015.05.006. (2014) 200–204, doi:10.1177/8756479314534523.
[15] S. Padmanaban, E. Kabalci, A. Iqbal, H. Abu-Rub, O. Ojo, Control strategy and [21] B.-E. Byambasuren, M. Oyun-Erdene, S.-Y. Nam, D.-H. Kim, S.-M. Han, Design
hardware implementation for DC–DC boost power circuit based on of USB-based high rate data communication for transcranial Doppler ultrasound
proportional–integral compensator for high voltage application, Eng. Sci. system, Int. J. Control Autom. 5 (2012) 97–106.
Technol. 18 (2015) 163–170, doi:10.1016/j.jestch.2014.11.005. [22] Y.-S. Lee, J.-H. Yang, S.-Y. Kim, W.-S. Kim, O.-K. Kwon, Development of a rapid
[16] J.J.R. Raj, S. Rahman, S. Anand, Application of a novel software algorithm for control prototyping system based on Matlab and USB DAQ boards, J. Inst. Control
information reduction in high frame rate ultrasonography, Int. J. Comput. Appl. Robot. Syst. 18 (2012) 912–920, doi:10.5302/j.icros.2012.18.10.912.
Technol. Res. 3 (2014) 729–733, doi:10.7753/ijcatr0311.1016. [23] N. Li, J. Guo, H.S. Nie, W. Yi, H.J. Liu, H. Xu, Design of embedded bio-impedance
[17] J.J.R. Raj, S. Rahman, S. Anand, Acquisition of lossless data in transient window analyzer based on digital auto balancing bridge method, in: Applied Mechanics
through ethernet in high frame rate machines, in: 2015 2nd International and Materials, Trans Tech Publication Ltd, 2012, pp. 396–401.
Conference on Computing for Sustainable Global Development (INDIACom), [24] J. Raj, S. Rahman, S. Anand, Interfacing high frame rate data through ethernet
IEEE, New Delhi, 2015, pp. 591–596. without loss for tele-medical applications, in: 2015 International Conference
[18] M. Tiouririne, S. Nguyen, J.A. Hossack, K. Owen, F. William Mauldin Jr., Handheld on Signal Processing and Communication (ICSC), IEEE, 2015, pp. 51–55.
real-time volumetric imaging of the spine: technology development, J. Med.
Eng. Technol. 38 (2014) 100–103, doi:10.3109/03091902.2013.877989.

You might also like