This paper presents an 8051 microcontroller-based control of ultrasound scanner prototype hardware from a host laptop MATLAB GUI. The hardware control of many instruments is carried out by microcontrollers. These microcontrollers are in turn controlled from a GUI residing in a computing machine that is connected over the USB interface. Conventionally such GUIs are developed using ‘C’ language or its variants. But MATLAB GUI is a better tool, when such GUI programs need to do huge image/video processing. 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 programming methods for achieving the smooth interfacing of microcontrollers with MATLAB GUI.
MATLAB ; MEX program ; Microcontroller ; Ultrasound scanner ; USB ; USBXpress
Microcontroller-based systems offer major advancement as an internal and external control. Microcontrollers can control majority of the internal devices in a typical circuit board. Moreover majority of the chips also have built-in interfaces that can be controlled by the microcontroller. They have USB interface through which it is interfaced with external devices such as a computer or a server [1] . A low-cost USB interface for operant research using Arduino and Visual Basic is presented in [2] . Many data acquisition systems use microcontroller and USB interface [3] . The microcontroller programming is done in traditional ‘C’ language. Microprocessors and microcontrollers provide the path for the integration of hardware and software [4] . Microcontrollers have far-reaching applications in the field of instrumentation [5] and [6] .
The application in the host computer or the server is generally written in languages like ‘C’ or its variants like C++, Visual C++, Java, etc. [7] . The microcontroller manufacturers provide interface programs in the form of windows dynamically linked libraries (DLL), which can be compiled along with the applications for interfacing with the microcontroller [8] and [9] .
For applications involving signal processing, image processing or video processing, MATLAB is a more suitable programming language [10] and [11] . The quality metrics and visual perception in ultrasound imaging under different imaging conditions using MATLAB test bench were studied in [12] . In MATLAB, there are many built-in functions and routines that enable faster rollout of the application [13] . MATLAB has a very large database of built-in algorithms for mathematical modeling, image processing, simulations and computer vision applications [14] and [15] . MATLAB has the ability to read in a wide variety of both common and domain-specific image formats.
However the major challenge is in interfacing the MATLAB application with the microcontroller to get the best of both worlds. Such requirements involve live reading of images, videos, and direct processing and display [16] . One application where we came across the challenge is while developing a prototype for a medical ultrasound scanning machine [17] and [18] . The application was made in MATLAB to take advantage of the rich image and video processing capabilities [10] and [19] . The hardware has USB interfacing to the microcontroller for configuration of the various parameters of the internal chips and for performing different operations [20] , [21] and [22] . The microcontroller interfaces with different internal chips, such as ADC, transmit side FPGA (TxFPGA), receive side FPGA (RxFPGA), etc. [23] and [24] . The block schematic of microcontroller interfaces is shown in Fig. 1 . The ADC has custom serial bus programming whereas FPGAs used Serial Peripheral Interface (SPI) programming. The interface programs toward these devices were also developed for the microcontroller as well as the FPGAs.
|
Fig. 1. Block schematic of the experimental setup. |
Neither MATLAB nor the microcontroller manufacturers provide the interface logic for interworking. Hence interworking between the MATLAB GUI and the microcontroller is a challenging task. The novel method used for interfacing using a C language interface function called MEX program is described in this paper.
The logical block schematic of the MATLAB GUI and microcontroller interfacing with USB is given in Fig. 2 , which indicates the microcontroller side as well as the MATLAB GUI side logic used for the study. A Silicon Laboratories C8051F340 microcontroller 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 integrated USB receiver and USB controller. It is 48 IO pins configured as 5 IO buses of 8 IOs each. The microprocessor in the ultrasound scanner prototype interfaces with a bank of ADCs and FPGAs. The microprocessor firmware is written in C language. One IO Bus is used as the programming header for programming the microcontroller. The firmware is transferred to the microcontroller using the programmer hardware by M/s Silicon Labs. The development required the USBXpress API provided by M/s Silicon Labs for including in the microcontroller firmware, firmware development, USBXpress driver installation in the host computer, installation of C++ compiler (Visual C++ used), development of the MEX file, development of the MATLAB GUI, and compilation and linking of the MEX file from MATLAB.
|
Fig. 2. Microcontroller MATLAB interface. |
The Silicon Laboratories USBXpress provides the host and device software solution for interfacing communication bridges to the USB. A high-level Application Program Interface (API) for both the host software and device firmware is used to provide USB connectivity. The USBXpress includes windows device drivers, device driver installer, host interface function library (host API) provided in the form of a DLL, and device firmware interface function library. Some of the important functions performed by the host API are given in Table 1 . While performing each function, the function returns the status of the operation like SI_SUCCESS or SI_DEVICE_NOT_FOUND or SI_INVALID_PARAMETER, along with any return values to take suitable corrective steps in read or write logics. The API is used in an interrupt driven mode. The c8051340.h and USB_API.h files supplied as part of the application are added to the project in addition to the “main” firmware file. While building the target, the USBXpress library file, USBX_F320_1.LIB is linked as an external object.
Function name | Function |
---|---|
USB_Clock_Start | Initializes the USB clock |
USB_Init | Enables the USB interface |
Block_Write | Writes a buffer of data to the host via USB |
Block_Read | Reads a buffer of data from the host via USB |
USB_Int_Enable | Enables API interrupts |
USB_Disable | Disables USB interface |
USB_Suspend | Suspends the USB interface |
In the developed prototype, the microcontroller configures the different chips like ADC, FPGA, etc., through the control from the MATLAB GUI. Hence the microcontroller firmware implements the USB interface logic as well as the interface logic for the other devices. The header and the source files developed for the interfacing with the ADC, TxFPGA, RxFPGA and PHY device using the four IO Buses are included in the firmware. Even though the ADC side does not require any separate software logic, the FPGA side requires the hardware logic written in languages such as Verilog or VHDL. Similar interface logic is written in the FPGA side also for the read and write operations using the SPI interface. The SPI interface has read, write, chip enable, Master in Slave Out (MISO) and Master Out Slave In (MOSI) pins for the interconnection. The 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 about the specific implementation. The USB_API.h for the USB interface functions and other files like C8051F340_def.h, compiler_defs.h, stddef.h, stdio.h etc. are included in the compilation. The flowchart of the firmware is given in Fig. 3 .
|
Fig. 3. Flowchart of microcontroller firmware. |
M/s Silicon Labs has provided the USBXpress DLL as ‘SiUSBXp.dll’. This acts as the interface between the USBXpress driver in the host computer and the MEX file. The important functions supported by 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 will return the number of target devices. This number is used when calling SI_GetProductString to build a list of device serial numbers or product description strings. To access a device, it is opened by a call to SI_Open using an index determined from the call to SI_GetNumDevices. The SI_Open function will return a handle to the device that is used in all subsequent accesses. Data I/O is performed using the SI_Write and SI_Read functions. When I/O operations are complete, the device is closed by a call to SI_Close. These functions are called for reading and writing data to the USB interface from the MEX program file.
Function name | Function |
---|---|
SI_GetNumDevices | Returns the number of devices connected |
SI_GetProductString | Returns a descriptor for a device |
SI_Open | Opens a device and returns a handle |
SI_Close | Cancels pending IO and closes the device |
SI_Read | Reads a block of data from the device |
SI_Write | Writes a block of data to the device |
SI_SetTimeouts | Sets read and write block timeout |
SI_CheckRXQueue | Gets the number of bytes in the device Rx Queue |
The core of the work is in the development of a MEX (MATLAB executable) file in C language whose functions are called from MATLAB. Also the MEX integrates the USBXpress DLL for connectivity with the microcontroller. Thus the MEX file acts as the interface between the MATLAB and the microcontroller. The MEX header file contains the function declarations. The MEX C++ file includes the ‘SiUSBXp.h’ file for the MEX file, which in-turn calls the functions of the ‘SiUSBXp.dll’. The flowchart of a function for reading the TxFPGA parameters is given in Fig. 4 .
|
Fig. 4. MEX function flowchart for reading a register value. |
Similarly the other required functions are also built in the MEX file. The required Silicon Laboratories library files SiUSBXp.dll, SiUSBXp.h, SiUSBXp.lib and SiUSBXp.exp are placed in the same project folder. The MEX file is compiled into a DLL by using MATLAB linked Visual C++ compiler. The MEX file can be compiled directly from the project using the Visual C++ application also. The DLL created in this case is with name ‘USConfig.dll’. The library file ‘USConfig.lib’ containing all the function names is also placed in the same folder of the project.
The MATLAB program directly calls the MEX functions from the MATLAB file or command prompt using ‘loadlibrary’ and ‘calllib’ functions of MATLAB. These functions are suitably included as part of the MATLAB GUI code wherever required.
USBXpress comes with its own driver that needs to be installed on the host computer. Once the driver is installed, the host computer automatically recognizes the microprocessor when it is plugged in.
A prototype developed for the ultrasound scanner with USB interface toward the MATLAB GUI is shown in Fig. 5 . The prototype has the Silicon Laboratories C8051F340 microcontroller, Xilinx FPGAs and ADCs (AD9272) from Analog Devices. It has the microcontroller programming header as well as the USB interface. The different components above in the hardware are marked in Fig. 5 .
|
Fig. 5. Ultrasound scanner prototype hardware. |
The MATLAB GUI is shown in Fig. 6 . The various ADC, FPGA, PHY, etc. configurations are performed from this GUI using the button click functions of the GUI buttons. These functions in turn call the MEX interface functions and pass the required values toward the microcontroller interface. The AD9272 configurations include the LAN Gain, VGA Gain, AAF upper and lower cutoff frequencies, enabling/disabling of different test patterns, etc. The enabling of different ultrasound channels are performed by configuring the pulsers through the TxFPGA by way of microcontroller. All these configuration parameters are coded as binary values and passed to the microcontroller. The various register values in these devices for their individual configuration are also read and written through this interface.
|
Fig. 6. MATLAB GUI for configuration of various scanner parameters. |
Finally the start and stop of ultrasound scan with the prototype 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 is taken using a phantom with an inclusion as shown in Fig. 7 . The image is taken using a linear array transducer probe at 4 MHz. The receive beamforming, image and video processing algorithms like smoothening, sharpening, histogram equalization etc. are performed in MATLAB. The receive beamforming involved delay and sum algorithm of the simultaneously received channels. The position of the inclusion as well as the depth of the phantom is marked in Fig. 7 .
|
Fig. 7. Ultrasound image of a phantom with inclusion captured in the prototype. |
The MATLAB interfacing with microcontroller is a major breakthrough in the design of the ultrasound machine. This enabled various signal, image and video processing requirements to be easily carried out using the MATLAB built-in functions [13] . The raw data captured were digitized and sent to MATLAB for further processing. Thus many of the hardware processing were transferred to software algorithms in MATLAB, like the beamforming, etc., in host computer, thus reducing the size and complexity of the hardware. The software processing of Doppler ultrasound system with USB-based high data rate communication is presented [21] , where the digital signal processing is shifted from hardware to software algorithms. This also helped in the development of an ultrasound machine suited for tele-medicine applications [23] .
This interfacing has larger implications in other wide areas of microcontroller control and programming, and hence is a very innovative approach. This also has many applications in areas of sensors, including medical electronics. There are large numbers of implementations of microcontroller interfacing with native ‘C’ or Java applications. However there are no such implementations available for the interfacing of the microcontroller with MATLAB.
In this application, the data received from the ultrasound transducers are captured as Ethernet packets through the Ethernet interface. As a future step, capturing the packets through the USB interface can also be implemented.
The authors thank the Department of Science and Technology, Government of India for providing financial support for this project with Grant Number SR/WOS-A/ET-24/2008 . The authors also state that the sponsor does not have any role in study design; collection, analysis and interpretation of data; writing of the report; and in the decision to submit the article for publication.
Published on 10/04/17
Licence: Other
Are you one of the authors of this document?