Automateddatacollection(tuneaalexandru) [302169]

AUTOMATED DATA COLLECTION

Bachelor Thesis

Petru Alexandru TUNEA

Supervisors:

Deian Cosas

Vlad Constantinescu

Prof. Dr. Eng. Ioan Silea

Introduction

Context

Data acquisition represents the process of collecting signals that measure environment conditions and converting to numeric values that can be interpreted by a computer. [anonimizat].

A complete, responsive and efficient data acquisition system includes two major components:

Hardware

Sensors(convert physical parameters to electrical signals)

Signal conditioning circuitry(manipulation of signals in a way that prepares them for the next stage of processing)

Analog to digital converters (convert analog signals into digital values)

Computer running software

Process data received from hardware

Filter data

Create reports and analyses

Save recorded data

Figure 1: Generic data acquisition system (1)

[anonimizat], velocity and acceleration.

Vibrations can cause problems such as:

Reducing lifetime of products

Machines failure

Increase costs of maintenance

Disturbing production process

Measuring vibrations supports:

Improving the quality of the product

Safety management in factories

Products maintenance

Detecting operational problems in design stage

Calculating life time of different components

Thematic

Statement: Design and build a [anonimizat], [anonimizat]-cost hardware components.

[anonimizat].

Implementation and testing of the data acquisition system was made in one of the Saguaro laboratories under the careful coordination of supervisors: Deian Cosas and Vlad Constantinescu.

The team who elaborated tis project was composed of two members: Petru Alexandru Tunea and Gheorghe Robert Catalin Dumitriu. Both members are students at “Politechnica” [anonimizat]. The entire project was developed under the leadership of Professor Doctor Engineer Ioan Silea.

[anonimizat].

Figure 2: Tri-Axial Accelerometer Test Tool (2)

[anonimizat].

[anonimizat] 200mm and 300mm FABs to measure the vibration induced to wafer lots by their material handling systems. [anonimizat].

Figure 3 Tri-Axial Accelerometer Test Tool placements on wafer lots (2)

This device can be used as a stand-alone unit or with the GCI Information Center to provide automated recording using RFID technology. It simultaneously acquires and records vibration data on the X, Y, and Z axes during automated or manual transportation. The device works on battery and has an LCD and a keypad to provide access for configuration.

The device can be optionally configured to record 512 time-domain data points per axis per second directly onto an installed SD Card. Recording capacity is limited by available space on the SD Card. An RS-232 port is provided for data upload using a standard terminal. Data is uploaded as formatted ASCII text that can be imported into popular spreadsheet applications for analysis.

The device comes with an Analysis application called VibPlot. This application duplicates the on-board data reduction available in the Tri-Axial Accelerometer Test Tool, and it provides additional analysis features, such as three dimensional waterfall plots, and color spectrograms.

Figure 4 VibPlot interface (2)

VibPlot provides tools to perform frequency analysis on the recorded time domain data. VibPlot provides additional analysis features, such as three dimensional waterfall plots, and color spectrograms. The time domain data can be displayed, along with graphs.

Theoretical Foundation

I2C and RS-232 communications

I2C communication

The Inter-integrated Circuit or simply I2C protocol is a protocol meant to allow multiple slave digital integrated circuits to communicate with one or more master integrated circuits. It is only used for short distance communication within a single device. It is very similar to RS232 serial communication because it requires only two signal wires to exchange information.

Those two mere wires can support up to 1008 slave devices. It also supports multi-master system. Most I2C devices can communicate at 100 KHz or 400 KHz. For each 8bits of data to be sent, one more extra bit of meta-data (ACK/NACK bit) must be transmitted as well.

Figure 5: I2C communication block diagram (3)

I2C signals

Each I2C bus is composed of two signals: SCL and SDA. The SCL represents clock signal and SDA represent data signal. The clock signal is always generated by bus master. Some slave devices may force the clock low at times to delay the master sending more data. This phenomenon is called clock stretching. The I2C bus drivers can pull the corresponding signal line low, but cannot drive it high. Each signal line has a pull-up resistor on it, to restore the signal to high when no device is asserting it low.

I2C protocol explained

Figure 6: I2C protocol (3)

Via I2C communication, the messages are split in two types of frames: an address frame (master indicates the slave address which message to be sent) and one or more data frames (8 data bits passed from master to slave or slave to master). Data is placed on the SDA line after the SCL goes low and is sampled after the SCL goes high again.

For initiating the address frame the master leaves the SCL high and pulls the SDA low. This operation notifies all slave devices that a transmission is about to start. If more than one master device exists on the bus, the first one that succeeds to pull SDA line low wins the control over the bus.

The address frame is always sent first in any new communication sequence over I2C bus. For a 7-bit address, the address is clocked out most significant bit first, followed by an R/W bit indicating if it follows a read or a write. The R/W bit value is 1 for read and 0 for write.

After the address has been sent, the next step is transmitting data. The master will continually generate clock signal at a regular interval and data will be placed on the SDA line by master device or by slave device depending if the R/W bit indicate a write or a read operation. The number of data frames is arbitrary and most slave devices will auto increment internal register.

After all data frames have been sent the master will generate a stop condition. This stop condition is defined be a transition from low to high on the SDA line. During this time the SCL line always remains high. To avoid false-stop conditions the SDA line should not change it value when SCL line is high.

RS-232 communication

Synchronous Communication

This communication requires that both the sender and the receiver share the same clock. The sender always provides a timing signal that notifies the receiver when to start the reading. Synchronous Communication generally has higher speed and greater error checking capabilities.

Asynchronous Communication

Contrary to Synchronous Communication this communication has no timing signal or clock. To synchronize data communication it inserts a start/stop bit in each byte of data. Asynchronous Communication is simpler and cheaper than Synchronous Communication.

RS-232/RS-485/RS-422/TTL represents the forms of Asynchronous Communications.

RS-232 protocol is a standard communication protocol that helps linking computer and its other peripherals to allow serial data exchange. RS-232 defines the voltage for the path used for data exchange between devices. Because RS-232 does not define elements like data encoding, data frames or error protocols, it is used together with a single integrated circuit called UART (universal asynchronous receiver/transmitter).

Figure 7 RS232 working together with UART (4)

Figure 8 Typical RS232 systems (4)

DTE (data terminal equipment) – It converts user signals or reconverts received signals. For DTE a male connector is used.

DCE (data communication equipment) – It stands between DTE and data transmission circuit. For DCE a female connector is used. The female connector has holes that hold the male connector (DTE).

For communication between DTE and DCE a minimum of three signals is required. These signals are: transmission line, reception line and ground.

Internal devices communications are represented by two conditions: ON condition (represented by 1) and OFF (represented by 0). These conditions in the binary system are termed a Bit. A byte has 8 bits, which represents decimal number 0 to 255 or hexadecimal number 0 to FF. A byte is the basic unit for Asynchronous communication.

Baud Rate represents the communication speed. It measures the number of bits transferred per second. For example 115200 baud means 115200 bits per second.

Figure 9: RS232 communication packets (10)

Communication packets like the one in the above figure refer to a single byte transfer, including Start/Stop bits, Data bits and Parity. For standard ASCII code (0-127) 7 data bits is enough but for extended ASCII code (128-255) 8 data bits are required.

Parity is a simple way for error-checking. The serial port verifies if the data packet contains an even or an odd number of logic-high bits. For an even number, serial port set the parity bit to logic 1 and for an odd number set the parity bit to logic 0. With this setting the receiver can determine if the data package is corrupted or not.

Start bit is sent first in a data packet and has a positive voltage (logic 0).

Stop bit is used for signaling the end of a data packet. It also helps to synchronize different clocks on the serial devices.

Handshaking also known as Flow Control is used to prevent receiver overloading. Handshaking signals help the receiver to be able to tell the sending device to delay or stop the data transmission until the receiver is not overloaded. Three types of handshaking exist and they are: Software handshaking, Hardware handshaking and both.

Checksum represents additional bytes added at the end of the data string to check the data integrity of the package.

Data formats

Serial devices use Binary for communication (only two numbers 0 and 1).

Binary is the base-2 numbering system. A byte of data consists of 8 binary digits.

Hexadecimal is the base-16 system, which consists of 16 digits: 0 to 9 and the letters A to F for 10-15. A byte of data can be represented by two consecutive hexadecimal digits.

Decimal is the base-10 system, which consists of 10 digits: 0 to 9.

Octal is the base-8 system, which consists of 8 digits: 0 to 7. It is very useful because it can easily be translated into binary format. Each octal digit can be represented by 3 binary digits.

ASCII (American Standard Code for Information Interchange) is a character encoding based on the English alphabet. ASCII codes are often used in communications.

Microcontrollers

A microcontroller is a compact microcomputer designed to control the operation of embedded systems like robots, motors, printers, home devices and various other devices. A typical microcontroller includes processor, memory and peripherals. (6)

Features of a microcontroller:

Cheapest methods to control electronic devices and processes

Operating at a low clock rate frequency

Low power consumption.

Architecture varies greatly with respect to purpose from general to specific, and with respect to microprocessor, ROM, RAM or I/O functions.

Has a dedicated input device and often has a display for output.

Usually embedded in other equipment and used to control features or actions of the equipment.

The programs used by microcontroller are stored in ROM.

Used in situations where limited computing functions are needed

Figure 10: Microcontroller general block diagram (5)

MSP432P401R LaunchPad versus Arduino UNO

First option for our system was Arduino UNO because we have experience with this microcontroller from university projects and is the common choice for people who want to develop an embedded project but why not step forward and discover new worlds. After a long period of searching and analysis we discovered MSP microcontrollers. In this family the MSP432P401R seems to be the perfect match for our requirements.

Advantages of using MSP432P401R instead of Arduino UNO

half the price of an Arduino UNO

32-bit ARM Cortex M4F microcontroller with clock speeds up to 48MHz while still maintained low power mode instead of 16MHz clock speeds Arduino UNO

has jumpers that allow to easily use the board as a standalone programmer once you move your chip off the LaunchPad

more integrated peripherals:

4 I2C, 8 SPI, 4 UART, 4 x16-bit Timers, 2 x32-bit Timers – MSP432P401R

more memory:

64 KB RAM- MSP432P401R / 2 KB RAM Arduino UNO

256 KB Flash- MSP432P401R / 32 KB Flash Arduino UNO

onboard emulator featuring Energy Trace

each peripheral can be enabled and disabled for an optimal power consumption

Figure 11: MSP432P401R and Arduino UNO

MSP microcontrollers

MSP microcontrollers from Texas Instruments are 16-bit and 32-bit mixed-signal processors designed for ultra-low power. They offer the lowest power consumption and the perfect mix of integrated peripherals for thousands of applications. MSP microcontrollers also come with a generous datasheet, and a very useful user guide.

Features of MSP microcontrollers:

Multiple low-power modes (clock system has the ability to enable and disable various clocks and oscillators which allow the microcontroller to enter various low-power modes)

Instant wakeup (allows microcontrollers to remain in low-power modes for the longest possible interval)

Real-time clock (precisely keeps real time and enables wakeup at specified intervals)

Direct memory access (enabling memory transfer with no CPU intervention)

Autonomous peripherals (Intelligent analog and digital peripherals can run autonomously in low-power modes)

Embedded FRAM (7)

Power consumption

The MSP microcontrollers offer the lowest power-consumption in the industry. The Embedded Microprocessor Benchmark Consortium is now offering the ULP Bench benchmark. In top 8 MSP microcontrollers reserve 3 places: 1st-place MSP432P401R, 4th-place MSP430FR5969, 7th-placeMSP430FR4133.

Figure 12: Top 8 Low Power MCU’s (7)

MSP432P401R LaunchPad

The MSP432P401R LaunchPad helps develop high performance applications that benefit from low power operation. It features the MSP432P401R – which includes a 48MHz ARM Cortex M4F, 95uA/MHz active power and 850nA RTC operation, 14-bit 1MSPS differential SAR ADC and AES256 accelerator.

This LaunchPad includes an emulator with Energy Trace Technology, which allows in debug mode to measure total system energy consumption without any additional tools. All pins of the MSP-EXP432P401R device are fanned out for easy access.

Figure 14 MSP432P401R LaunchPad (8)

Features:

Low-power, high performance MSP432P401R MCU

48MHz 32-bit ARM Cortex M4F with Floating Point Unit and DSP acceleration

Power consumption: 95uA/MHz active, and 850nA RTC standby operation

Analog: 24Ch 14-bit differential 1MSPS SAR ADC, Two Comparators

Digital: Advanced Encryption Standard (AES256) Accelerator, CRC, DMA, HWMPY32

Memory: 256KB Flash, 64KB RAM

Timers: 4 x16-bit, and 2 x 32-bit

Communication: Up to 4 I2C, 8 SPI, 4 UART

40 pin Booster Pack Connector, and support for 20 pin Booster Packs

Onboard XDS-110ET emulator featuring Energy Trace

buttons and 2 LEDs for User Interaction

Back-channel UART via USB to PC (8)

Figure 15 MSP432P401R LaunchPad block diagram (8)

Sensors

The term “sensor” appeared with the development of microelectronics and has various definitions. A sensor is a sophisticated device that is used to detect and respond to electrical or optical signals. The main role of a sensor is to convert the physical parameter (for example: vibrations, light, temperature, gas pressure, humidity) into a signal that can be measured electrically.

Sensor types and their applications:

Speed sensor

A device that is used to measure speed of an object is called speed sensor. There are many types of speed sensors (for example: wheel speed sensors, speedometers, LIDAR, ground speed radar and radar).

Applications:

Antilock Braking systems (ABS)

Electronic stability control (ESP)

Speed synchronization of multiple motors in industries

Temperature sensor

A device that is used to measure temperature is called temperature sensor. There are two major types of temperature sensors: contact type temperature sensors and non-contact type temperature sensors.

Applications:

Controlling temperature of industrial devices

Controlling temperature of different rooms

PIR (Pyro-electric) sensor

A device that is used to measure the infrared light radiation emitted from objects is called PIR sensor. Every object that has a temperature above absolute zero emits heat energy in the form of infrared radiation that is invisible to the human eye, but can be detected by PIR sensors.

Applications:

Automated doors opening and closing

Buildings security systems

Ultrasonic Sensor

A device that is used to convert ultrasound waves to electrical signals is called ultrasonic sensor.

Applications:

Distance measurement in inaccessible areas (11)

Figure 16: Different types of sensors (11)

MPU-6050

The MPU-6050 from IvenSense is the first motion tracking device created for low-power, low-cost and extremely high performance requirements of nowadays smart-phones and ultimate generation tablets.

MPU-6050 device includes 3-axis accelerometer, 3-axis gyroscope and a temperature sensor. This device can communicate only via I2C interface. Also it has an additional I2C built-in controller that allows MPU-6050 to be master device on a secondary I2C bus.

One of the most useful features of MPU-6050 is represented by an incorporated FIFO buffer. The MPU-6050 device can be programmed to put sensor data in this buffer and with interrupt feature can notify the master device when data is ready to be read.

Figure 17: MPU-6050 device (12)

Features:

Tri-axis accelerometer with programmable full scale range of ±2g,±4g,±8g,±16g

Tri-axis gyroscope with a sensitivity up to 131 LSB and a full scale range of ±250, ±500, ±1000, ±2000 (°/sec)

Digital output temperature sensor

VDD supply voltage range of 2.375 – 3.45 (V)

400 kHz fast mode I2C

10000 g shock tolerant

Accelerometer and gyroscope operating current: 3.8 mA

Embedded algorithms for run-time bias and compass calibration in library

Digital input on pin to support video Electronic Image Stabilization and GPS

Smallest and thinnest package for portable devices(4x4x0.9mm) (12)

Figure 18: MPU-6050 Block Diagram (12)

MEMS Accelerometer

Features:

Digital-output triple-axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g

Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external multiplexer

Accelerometer normal operating current: 500µA

Low power accelerometer mode current: 10µA at 1.25Hz, 20µA at 5Hz, 60µA at 20Hz, 110µA at 40Hz

Orientation detection and signaling

Tap detection

User-programmable interrupts

Free-fall interrupt

High-G interrupt

Zero Motion/Motion interrupt

User self-test

Registers used to configure accelerometer:

PWR_MGMT_1 – used to disable or enable sleep mode on MPU-6050 device

ACCEL_CONFIG – used to enable or disable accelerometer self-test and configure accelerometer full scale range.

XA_ST, YA_ST, ZA_ST values:

Logic “1”- enable accelerometer self-test

Logic “0”-disable accelerometer self-test

AFS_SEL values:

0 (Bit4-0,Bit3-0) set accelerometer full scale range to ± 2g

1 (Bit4-0,Bit3-1) set accelerometer full scale range to ± 4g

2 (Bit4-1,Bit3-0) set accelerometer full scale range to ± 8g

3 (Bit4-1,Bit3-1) set accelerometer full scale range to ± 16g

Accelerometer sensitivity:

± 2g – 16384 LSB/g

± 4g – 8192 LSB/g

± 8g – 4096 LSB/g

± 16g – 2048 LSB/g

Registers used to perform X, Y, Z axis values reading:

(13)

-For each value of accelerometer axis we used 2 registers “low” and “high” and the final value is obtained in 2-byte unsigned integer (uint16_t) format after using the following generic operation:

finalValue = ( highRegisterValue<<8 | lowRegister value)

MEMS Gyroscope

Features:

Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable full scale range of ±250, ±500, ±1000, and ±2000°/sec

External sync signal connected to the FSYNC pin supports image, video and GPS synchronization

Integrated 16-bit ADCs enable simultaneous sampling of gyros

Enhanced bias and sensitivity temperature stability reduces the need for user calibration

Improved low-frequency noise performance

Digitally-programmable low-pass filter

Gyroscope operating current: 3.6mA

Standby current: 5µA

Factory calibrated sensitivity scale factor

Registers used to configure gyroscope:

PWR_MGMT_1 – used to disable or enable sleep mode on MPU-6050 device

GYRO_CONFIG – used to enable or disable accelerometer self-test and configure gyroscope full scale range.

XG_ST, YG_ST, ZG_ST values:

Logic “1”- enable accelerometer self-test

Logic “0”-disable accelerometer self-test

FS_SEL values:

0 (Bit4-0,Bit3-0) set gyroscope full scale range to ±250 ș/s

1 (Bit4-0,Bit3-1) set gyroscope full scale range to ±500 ș/s

2 (Bit4-1,Bit3-0) set gyroscope full scale range to ±1000 ș/s

3 (Bit4-1,Bit3-1) set gyroscope full scale range to ±2000 ș/s

Registers used to perform X, Y, Z axis values reading:

(13)

-For each value of gyroscope axis we used 2 registers “low” and “high” and the final value is obtained in 2-byte unsigned integer (uint16_t) format after using the following generic operation:

finalValue = ( highRegisterValue<<8 | lowRegister value)

Digital-Output Temperature Sensor

Registers used to perform temperature values reading:

(13)

-The final temperature value is obtained in 2-byte unsigned integer (uint16_t) format after using the following generic operation:

fianalValue= ( highTempRegisterValue<<8 | lowTempRegister value)

Programming environments used

Code Composer Studio

We chose Code Composer Studio because it is an integrated development environment provided by Texas Instruments that supports all Texas Instruments Microcontrollers and embedded processors. It combines the advantages of the Eclipse software framework with advanced embedded debug capabilities to create in my opinion one of the best IDE for developing embedded software. Code Composer also comes with Power-Consumption-Tracer and Memory-Allocation features. We use this IDE to develop and test our embedded software.

Figure 19: Code Composer Studio Debug (14)

Microsoft Visual Studio

Microsoft Visual studio is an integrated development environment from Microsoft that is used to develop computer programs mostly for Windows. Uses software development tools and techniques such as:

Windows API

Windows Form

Windows Presentation Foundation

Windows Store

Microsoft Silverlight

Visual studio includes a code editor supporting InteliSense as well as code refactoring. Supports different programming languages like: C, C++, VB.NET, C#, F#, Python, Ruby, JavaScript, HTML etc.

We use Visual Studio to implement, design and test our desktop application called LiveCharting.

Figure 20: Microsoft Visual Studio Interface (15)

Tera-Term

Tera Term is an open-source, software implemented, terminal emulator program. We chose this program because it emulates different types of computer terminals, from DEC VT100 to DEC VT382, supports telnet, SSH 1 & 2 and serial port connections and it also has a built-in macro scripting language and a few other useful plugins.(16) This program helps us to test our serial communication between data acquisition hardware and LiveCharting application.

Figure 21: Tera Term Serial Port Setup window

Requirements and proposed solution

Technical Requirements

LiveCharting application Requirements:

Possibility to configure data acquisition hardware

Communicate with hardware through serial (RS232) communication

Collect sensor data from data acquisition hardware

Filter data received from data acquisition hardware

Display sensor data / Create real-time graph based on sensor data regardless of quantity

Embedded Application Requirements:

Implement and design modular software for data acquisition hardware

Collect data from sensors via I2C bus

Process data from sensors

Send processed data at configurable periods of time

Communicate with LiveCharting application through serial (RS232) communication

Data acquisition hardware description

Figure 22: Data acquisition hardware block diagram

The data acquisition hardware system will consist of:

Microcontroller module to receive and process data coming from sensors and send readable data values to LiveCharting application

Multi-Sensor module for real time data acquisition

Serial communication between microcontroller and LiveCharting application

Microcontroller module

Functionality:

Enables multi-sensor module

Configure multi sensor module sensitivity

Receive and interpret commands from LiveCharting application to set an optimal time interval for data acquisition

Receive data from multi-sensor module

Process and prepare data for sending

Send data through RS232 connection to LiveCharting application

Components:

MSP432P401R LaunchPad provided by Texas Instruments

Multi-sensor module

Functionality:

Accelerometer: measures the rate of change in linear velocity

Gyroscope: measures the rate of change in angular orientation

Temperature sensor: measures environment temperature

Send 2 x 8 bits data for each accelerometer and gyroscope axis value to microcontroller module for further transformation via I2c bus

Components:

MPU6050 chip (MEMS accelerometer, MEMS gyroscope and temperature sensor)

Software description

Software description for data acquisition hardware

For the embedded software we decided to use C programming because it is a highly portable language, a data structured language, has many standard built-in functions and offers the possibility to create our own libraries.

We designed a modular software platform that allows adding or changing the sensors in the future. For example to add a new sensor you only need to declare a data structure with new sensor parameters.

For more details about how to add a new multi-sensor module to the data acquisition hardware please read paragraph 5.1.4.

Figure 23: Embedded software flow diagram

Functionalities:

Initialize I2C communication

Configure I2C communication

Initialize UART communication

Configure UART communication

Initialize sensors

Configure sensors sensitivity

Initialize timers

Configure timers for up-mode

Configure timers

Use timers for acquisition and sending to LiveCharting application

Interprets commands received through UART

Motion detection function(Threshold) with configurable sensitivity

Use circular buffer to manipulate sensors data

Software description for LiveCharting application

For LiveCharting application we used:

C# – a simple, easy to use, modern, general purpose and object-oriented programming language

XAML( Extensible Application Markup Language) – which is an XML – based markup language used by Microsoft, that is found behind the visual presentation of an application

Functionalities:

Configure serial communication

Detect existing serial ports

Set baud rate

Establish serial connection

Configure hardware system:

Set Acquisition frequency (microseconds)

Set Sending interval(microseconds)

Set Threshold value for sensors

Enable data acquisition process

Disable data acquisition process

Data filtering

Reports about corrupted packets of data received from sensors

Reports about number of missing data in graph

Create real-time graph regardless of sensors number with following features:

Choose graph style

Set view time (milliseconds)

Start and Stop

Maximum values for each graph

Minimum values for each graph

Different color for each graph

Communication between systems

The LiveCharting application can communicate with data acquisition hardware only through RS-232 serial communication which supports a speed up to 115200 baud.

Implementation details

Data acquisition hardware structure

Hardware assembling

Figure 30 Data acquisition hardware schematic

In order to establish connection between MPU-6050 and MSP432P401R the following operation are required:

Connect 3V3 pin from MSP to VCC pin from MPU-6050

Connect GND pin from MSP to GND pin from MPU-6050

Connect P1.6 pin from MSP to SDA pin from MPU-6050

Connect P1.7 pin from MSP to SCL pin from MPU-6050

After these operations are done connect MSP432P401R LaunchPad to the LiveCharting application through serial (RS-232) communication.

Below is a picture of data acquisition hardware placed on a prototype robot.

Figure 31 Testing data acquisition system

Software structure of data acquisition hardware

Architecture

The software application is implemented C language. It was developed and tested in Code Composer Studio mentioned before in Theoretical Foundation. The source code is designed in a modular manner to foster future multi-sensor module adding or changing without modifying a major part of the source code.

Figure 24: Modules diagram for software application

The software application is composed of:

Sensors module

Device module

I2C0 module

UART Commands module

UART0 module

Utils module

Timers module

Function details

SENSORS module:

void InitSensors (IdSensors Name)

This function is just a pass though function that takes as parameter a device name specified in IdSensors enumeration and calls initialization functions for accelerometer or gyroscope defined in Device module.

Example of calling: InitSensors(mpu);

void ConfigSensors (RangeConfig range)

This function is just a pass through function that takes as parameter a range descriptions specified in RangeConfig enumeration and calls configuration functions for accelerometer or gyroscope device defined in Device module.

Example of calling: ConfigSensors(Range2G);

int32_t ReadSensors (MpuSensor Device)

This function takes as parameter the name of the wanted accelerometer or gyroscope axes specified in MpuSensor enumeration and returns the result of reading functions defined in Device module.

Example of calling: ReadSensors(xAxis);

DEVICE module:

void InitDevice (Device Id)

This function takes as parameter an id (example: mpu, gy80) specified in Device enumeration and calls initialization and configuration functions declared in I2C module.

Example of calling: InitDevice(Mpu);

void ConfigDeviceSensitivity (RangeConfig range)

This function takes as parameter the wanted sensitivity specified in RangeConfig enumeration and calls the final configuration function defined in I2C module.

Example of calling: ConfigDeviceSensitivity(Range2G);

int32_t ReadAccelerometer (AxisAccelerometer Axis)

This function takes as parameter the name of the wanted accelerometer axis specified in AxisAccelerometer enumeration and converts the result of the reading functions defined in I2C0 module (2 x uint8_t data format) into int32_t data format. This function also returns the converted value.

Example of calling: ReadAccelerometer(XAxis);

int32_t ReadGyroscope (AxisGyroscope Axis)

This function takes as parameter name of the wanted Gyroscope axes specified in AxisGyroscope enumeration and converts the result of the reading functions defined in I2C0 module (2 x uint8_t data format) into int32_t data format. This function also returns the converted value.

Example of calling: ReadGyroscope(XAxisG);

int16_t ReadTemperature (Temperature temp)

This function takes as parameter name of the temperature sensor defined in Temperature enumeration and convert the result of reading function defined in I2C0 module (2 x uint8_t data format) into int16_t data format. This function also returns the converted value.

Example of calling: ReadTemperature(Temp);

I2C0 module:

void InitI2c0 (uint32_t moduleBaseAdress, const eUSCI_I2C_MasterConfig i2cConfig, uint8_t i2cPort, uint8_t sdaPin, uint8_t sclPin, uint8_t primaryModuleFunction, uint8_t slaveAdress)

This function takes a series of parameters to initialize and configure I2C communication on MSP432P401R LaunchPad.

Parameters meaning:

moduleBaseAdress represents the address of EUSCI_MODULE from LaunchPad wanted for I2C communication

i2cConfig represents a structure that contains several parameters for I2C configuration

i2cPort represents the port from EUSCI_MODULE

sdaPin represents the SDA pin on MSP432P401R LaunchPad

sclPin represents the SCL pin on MSP432P401R LaunchPad

slaveAdress represents the address of slave device for I2C communication

Example of calling: InitI2c0(defaultSensor.moduleBaseAdress,defaultSensor.i2cConfiguration, defaultSensor.i2cPort,defaultSensor.sdaPin,defaultSensor.sclPin,defaultSensor.primaryModuleFunction,defaultSensor.slaveAdress);

void SendI2c0 (uint32_t moduleBaseAdress, uint8_t powerRegisterAdress, uint8_t powerRegisterData)

This function takes a series of parameters to write specified value into the given register.

Parameters meaning:

moduleBaseAdress represents the address of EUSCI_MODULE from LaunchPad wanted for I2C communication

powerRegisterAdress represents the address of the register

powerRegisterData represents the value to be write

Example of calling: SendI2c0(defaultSensor.moduleBaseAdress, defaultSensor.powerRegisterAdress,defaultSensor.powerRegisterData);

uint8_t ReadI2c0 (uint32_t moduleBaseAdress,uint8_t registerAdress)

This function reads and returns a specified register value.

Parameters meaning:

moduleBaseAdress represents the address of EUSCI_MODULE from LaunchPad

registerAdress represents the address of the register

Example of calling: ReadI2c0(defaultSensor.moduleBaseAdress,defaultSensor.xLowAdress);

UART COMMANDS module:

void InitUarts (UartMoudule name)

This function is just a pass though function that takes as parameter a UART module name specified in UARTMoudule enumeration and calls initialization and configuration functions for UART communication defined in UART0 module.

Example of calling: InitUarts (uartModule0);

void InitUartReceive (void)

This function configures UART module to be able to receive commands from the LiveCharting application. It configures baud-rate and writes different registers values to allow access to register mode on MSP432P401R LaunchPad.

Example of calling: InitUartReceive ();

void SendCharacterData (char c)

This function is just a pass through function that takes as parameter a character data and calls the sending character data function defined in UART0 module.

Example of calling: SendCharacterData (‘$’);

void SendStringData (char *s)

This function is just a pass through function that takes as parameter a pointer to a character array and calls the sending string function defined in UART0 module.

Example of calling: SendStringData (“$-282,45,1232#”);

void UartCommands (char comm[30])

This function takes as parameter a char array of 30 elements and processes different commands received from LiveCharting application.

Examples:

UartCommands (“start=”) -> start acquisition

UartCommands (“stop=”) -> stop acquisition

UartCommands (“setPeriodA1=2000”) -> set timer A1 period at 2 milliseconds

UartCommands (“setPeriodA0=1000”) -> set timer A0 period at 1 millisecond

UartCommands (“setThreshold=200”) -> set the minimum changes of linear velocity or angular orientation

void Add (void )

This function performs the following operations:

Reads accelerometer axis values

Add this values to a circular buffer

Example of calling: Add();

void Send(void)

This function performs the following operations:

Read existing data from circular buffer

Convert red data into string

Verify circular buffer status

Send via RS232 converted data

Example of calling: Send();

uint8_t WaitUntilStart (int threshold)

This function takes as parameter the threshold value and returns a uint8_t flag. It role is to detect if the sensor has set in motion. If motion is detected it sets the flag to 1 otherwise sets the flag to 0.

Example of calling: WaitUntilStart (250);

Uart0 module:

void InitUart (uint32_t uartModuleBaseAdress, uint8_t uartPort, uint8_t pin1uart, uint8_t pin2uart, uint8_t pin3uart, const EUSCI_UART_Config uartConfiguration, uint8_t primaryModuleFunction)

This function takes a series of parameters to initialize and configure UART communication on MSP432P401R LaunchPad.

Parameters meaning:

uartModuleBaseAdress represents the address of EUSCI_MODULE from LaunchPad wanted for UART communication

uint8_t uartPort represents the port from EUSCI_MODULE

pin1uart, pin2uart, pin3uart represents UART pins

uartConfiguration represents a structure that contains several parameters for UART configuration

Example of calling: InitUart(defaultUartModule.uartModuleBaseAdress, defaultUartModule.uartPort,defaultUartModule.pin1Uart,defaultUartModule.pin2Uart, defaultUartModule.pin3Uart,defaultUartModule.uartConfiguration,defaultUartModule.primaryModuleFunction);

void SendCharacter (uint32_t uartModuleBaseAdress, char character)

This function uses a specified EUSCI_MODULE to send a character over the UART.

Example of calling: SendCharacter(defaultUartModule.uartModuleBaseAdress,’$’);

void SendString (uint32_t uartModuleBaseAdress, char* myString)

This function uses a specified EUSCI_MODULE to send a string over the UART.

Example of calling: SendString(defaultUartModule.uartModuleBaseAdress,”$234,3,566#”);

UTILS module:

int32_t HexaToDecG (int32_t value,int32_t lbs)

This function converts read values from accelerometer to decimal values measured in G-force units.

Example of calling: HexaToDecG(dataReceivedHighLow,defaultSensor.lbs2G);

int32_t HexaToDecGyro (int32_t values)

This function converts read values from gyroscope into decimal values measured in degrees per second (°/s).

Example of calling: HexaToDecGyro(dataReceivedHighLowGyro);

char *IntToString (int32_t number)

This function implements a solution for standard “itoa” because the existing function uses too much memory. It converts integer values to string values.

Example of calling: IntToString(-288));

TIMERS module:

void startCrystalOscillator (void)

This function enables external crystal oscillator from MSP432P401R LaunchPad that allows the user to set timers period under 1 millisecond.

void InitTimers (void)

This function configures TimerA0 and TimerA1 for up mode.

void SetTimerA0_0Period(uint32_t periodConfigA0) and

void SetTimerA1_0Period(uint32_t periodConfigA1)

These functions set timers periods.

Example of callings: SetTimerA0_0Period(1800); SetTimerA1_0Period(2000);

void StartTimerA1_0 () and void StartTimerA0_0 ()

These functions allow the user to start the timers counter.

Example of callings: StartTimerA1_0(); StartTimerA0_0();

void StopTimerA0_0 () and void StopTimerA1_0 ()

These functions allow the user to disable timers.

Example of callings: StopTimerA0_0() ;StopTimerA1_0();

TIMERS diagram

Figure 25: Timers data management flow diagram

We use two timers and a circular buffer to be able to manage sensor data.

Timer_a_0_isr is used to set the acquisition frequency which means how often the microcontroller interrogates sensors for readings.

Timer_a_1_isr is used to set the sending frequency which means how often the microcontroller will send sensor data to the LiveCharting application.

Circular buffer is used to store sensor data.

timer_a_0_isr functionalities:

reading acceleration values using SENSOR module

add acceleration values to circular buffer

timer_a_1_isr functionalities:

read acceleration values from circular buffer

convert acceleration values into strings using UTILS module

send converted data over the UART using UARTCOMMANDS module

Circular buffer

Figure 26: Circular buffer (17)

A circular buffer (ring buffer) is a high performance first in, first out (FIFO) queue with fixed size. Items are never moved inside the buffer. The same as in any other queues values are added to the end of the queue and extracted from the start.

To identify the head and tail of a circular buffer two pointers are used. These pointers suffer updates every time when an adding or a removing operation happens. After the space in the buffer is used the next element is stored at the first item location in the buffer and the oldest item is overwritten. (17)

This buffer is used to manipulate the data received from sensors.

Sequence diagram

Figure 27 Sequence diagram for embedded application

In the above diagram we can see the embedded application modules:

SENSORS that represents just a pass through layer

ACCELEROMETER that makes sensor initialization, configuration and readings

I2C0 that contains functions from Texas Instruments library called “driverlib.h”.

UARTCOMMANDS that makes initialization, configuration and contains definitions for functions that interpret commands

UART0 contains functions from Texas Instruments library called “driverlib.h”.

Adding a new sensor

Adding a new sensor requires only small modification in Device module.

Here the user must create a new structure that contains details (slave address, registers for read, power management registers, configuration registers) about the new sensor and then use the already existing functions.

Example of MPU6050 structure:

Sensor sensorMpu=

{ .slaveAdress=SLAVE_ADRESS_MPU,

.moduleBaseAdress=EUSCI_B0_MODULE,

.powerRegisterAdress=POWER_REGISTER_ADRESS,

.powerRegisterData=POWER_REGISTER_DATA,

.i2cConfiguration=

{

EUSCI_B_I2C_CLOCKSOURCE_SMCLK,3000000,

EUSCI_B_I2C_SET_DATA_RATE_400KBPS,

EUSCI_B_I2C_NO_AUTO_STOP

},

.i2cPort=GPIO_PORT_P1,

.sdaPin=GPIO_PIN6,

.sclPin=GPIO_PIN7,

.primaryModuleFunction=GPIO_PRIMARY_MODULE_FUNCTION,

.xLowAdress=X_LOW_REGISTER_ADRESS_MPU_ACC,

.xHighAdress=X_HIGH_REGISTER_ADRESS_MPU_ACC,

.yLowAdress=Y_LOW_REGISTER_ADRESS_MPU_ACC,

.yHighAdress=Y_HIGH_REGISTER_ADRESS_MPU_ACC,

.zLowAdress=Z_LOW_REGISTER_ADRESS_MPU_ACC,

.zHighAdress=Z_HIGH_REGISTER_ADRESS_MPU_ACC,

.range2G=RANGE_2G_CONFIG_REGISTER_DATA_ACC,

.range4G=RANGE_4G_CONFIG_REGISTER_DATA_ACC,

.range8G=RANGE_8G_CONFIG_REGISTER_DATA_ACC,

.range16G=RANGE_16G_CONFIG_REGISTER_DATA_ACC,

.lbs2G=LBS_2G,

.lbs4G=LBS_4G,

.lbs8G=LBS_8G,

.lbs16G=LBS_16G,

.tLow=TLOW,

.tHigh=THIGH,

.xHighAdressGyro=X_HIGH_REGISTER_ADRESS_GYRO,

.xLowAdressGyro=X_LOW_REGISTER_ADRESS_GYRO,

.yHighAdressGyro=Y_HIGH_REGISTER_ADRESS_GYRO,

.yLowAdressGyro=Y_LOW_REGISTER_ADRESS_GYRO,

.zHighAdressGyro=Z_HIGH_REGISTER_ADRESS_GYRO,

.zLowAdressGyro=Z_LOW_REGISTER_ADRESS_GYRO

};

Software structure of the LiveCharting application

The LiveCharting application was designed in C# using WPF (Windows Presentation Foundation). WPF is a sub system of .NET framework used to create user interfaces for Windows operating system. WPF is used to create Windows client applications.

WPF contains a very large number of libraries that have all the functionalities you need to develop and test Windows client applications.

XAML is a declarative markup language provided by Microsoft to write user interfaces. You can create UI elements in XAML and then separate them from the run-time using code-behind files. XAML is used in WPF to represents the control and code with the help of C# and other .NET framework. XAML is similar to ASP.NET or Windows Forms.

For real-time charting we used WPF Toolkit Data Visualization nugget.

“WPF Toolkit Data Visualization” represents a collection of WPF features and components that are available outside of the ordinary .NET Framework.

Figure 28 WPF Toolkit Data Visualization example

Architecture

Figure 29 Data flow diagram

For every data packet received through serial communication a filter action is required. If a packet doesn’t respect our defined protocol, packet is discarded, a verify variable is incremented and the number of corrupted data is shown to the user. If a data packet passes the filtering it is added to the buffer. A valid packet of data looks like: $data1,data2,data3,….#.

At every millisecond a Timer calls several functions. At every tick the first packet of data from buffer is processed and the data packet is removed from buffer to prevent buffer overflow. Processing includes following operations for every data packet:

Remove “$”, “#”, “\r”, “\n” from data packet.

Split by “,” and add data to a string[].

Count the elements of string[] to be able to determine the number of needed graphs.

Create graphs.(only in first Timer tick)

Convert each data into double type. If conversion succeeds add data to a temporary buffer ( list of key-value pair)

Add data from temporary buffer to a global list of ObservableCollection type at a specified index, to update graph every millisecond.

Usage

LiveCharting application

Install

Step 1:

Copy LiveCharting.msi file on your computer.

Step 2:

Open LiveCharting.msi file

Click Next button to continue installation process

Click Cancel to exit installation process

Step 3:

Click Browse to select folder for installation

Click Next to continue with installation process

Click Cancel to exit installation process

Step 4:

Click Finish to complete installation process

User Guide

Hardware Tab

Serial port configuration:

port name (automatically detects available ports)

baud rate ( up to 115200)

Connect Button to initialize serial connection

Acquisition parameters configuration:

Acquisition frequency which means how often the microcontroller interrogates the multi-module sensor

Timer Send frequency which means how often the microcontroller will send data to the LiveCharting application

Threshold for automatically starting the sensor readings

After pressing the start acquisition button, the microcontroller only starts requesting sensor data after movement has been detected. Sensor data is read continuously until the stop acquisition button is pressed.

Live Charting Tab

The vertical axis of the graph shows the acceleration in milliG, and the horizontal axis shows the time in milliseconds.

Here the user can:

Enable or disable data points

Configure time interval to show in the chart

Start/Stop button for charting (this button only affects the graphical output, not the data acquisition)

View details about the maximum or the minimum value on each axis

Practical issues

Embedded software

Measurements

For an optimal configuration of acquisition timer and sending timer periods we must find out how long it takes for an acquisition operation over the I2C and for a send operation over UART. We used an oscilloscope to determine these times.

Figure 32 Reading time over I2C for one accelerometer value

Above measurement represents acquisition of a single accelerometer value over I2C. This operation lasts for 94 microseconds.

Figure 33 Sending time over UART for all 3 axis of accelerometer

Above measurement is done for a complete package of data including conversion from integer type to string type. Sending operation over UART lasts for 1.200 milliseconds.

Communication protocol

To communicate with data acquisition hardware, a communication protocol was implemented.

Example of command: “setPeriodA1=2000}”

Command meaning:

“}” represents end of a command

every string before “=” represent an action

every string after “=” represents a value for data acquisition hardware configuration

LiveCharting application

Data filter

Verify data received over UART to respect a predetermined data format.

Example of valid data format: “$data1,data2,….,dataN#”

(“$”-first character of string, “,”-separate data categories, “#” end character of string)

Dynamically create graph for each type of data received from microcontroller

When Start button is pressed the LiveCharting application sends a request to the data acquisition hardware and the microcontroller sends labels for all data categories to be charted. For example if the microcontroller will send 3 labels the LiveCharting application will create 3 graphs labeled with received names.

Conclusions and results

This project represents the basis for more complex applications, where, for example, other sensors, extra processing or automation is added.

We used this system on a robot prototype and the measurements generated the following results:

Figure 34: Robot movement from 0° to 60° measured with LiveCharting application

With the help of the above measurement we are able to determine:

Acceleration time of the robot: 580 milliseconds

Deceleration speed of the robot: 780 milliseconds

Traveling at desired speed time: 590 milliseconds

Minimum and Maximum value for each accelerometer axis

Acceleration values for the entire movement

This type of information is shown on the X and Y axis of the accelerometer. From the Z axis we deduce that the robot is not very well secured in position.

Figure 35: Robot movement from 60° to 0° measured with LiveCharting application

With the help of the above measurement we are able to determine:

Acceleration time of the robot: 180 milliseconds

Deceleration speed of the robot: 550 milliseconds

Traveling at desired speed time: 820 milliseconds

Minimum and Maximum value for each accelerometer axis

Acceleration values for the entire movement

This type of information is shown on the X and Y axis of the accelerometer. From the Z axis we deduce that the robot is not very well secured in position.

After comparing the results of two movements of the robot we find out that a movement from 0° to 60° lasts longer with 400 milliseconds than the reverse movement from 60° to 0°.

The most relevant finding is that, in both measurements, the acceleration time is much smaller than the deceleration. This fact represents an abnormal behavior of this robot prototype. This represents a confirmation of a problem observed before.

This type of measurements can help improve the quality of products in the future, troubleshoot issues, speeds up repairs and maintenance. Also the data acquisition system can offer support for detecting operational problems in the design stage and calculating the life time of the robot components.

The data acquisition system can be easily extended in the future:

Adding new sensors for more information

Implementing auto-stop function

Improve data filtering

Adding battery supply and implement low-power modes

Adding wireless connection between data acquisition hardware and LiveCharting application

Adding horizontal scrolling for charting

Export/ loading charting data to/from a excel file (LiveCharting application)

List of References

(1) https://www.edgefx.in/different-types-of-sensors-with-applications/

(2) http://www.getcontrol.com/products/triaxial_accelerometer_test_tool.html

(3) https://learn.sparkfun.com/tutorials/i2c

(4) http://www.engineersgarage.com/articles/what-is-rs232

(5) http://www.avr-tutorials.com/general/microcontrollers-basics

(6) http://internetofthingsagenda.techtarget.com/definition/microcontroller

(7) http://www.ti.com/lsds/ti/microcontrollers_16-bit_32-bit/msp/getting-started.page

(8) http://www.ti.com/tool/msp-exp432p401r

(9) http://www.ti.com/lsds/ti/microcontrollers_16-bit_32-bit/msp/getting-started.page

(10) https://www.commfront.com/pages/3-easy-steps-to-understand-and-control-your-rs232-devices

(11) https://www.edgefx.in/different-types-of-sensors-with-applications/

(12) http://www.invensense.com/products/motion-tracking/6-axis/mpu-6050

(13) https://www.cdiweb.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf

(14) http://www.ti.com/tool/ccstudio

(15) https://www.visualstudio.com/

(16) http://download.cnet.com/Tera-Term/3000-20432_4-75766675.html

(17) http://www.camera-sdk.com/p_54-how-to-implement-circular-buffer-video-recording-in-c-onvif.html

Similar Posts