Contact

If you are interested in experiments described here, don't hesitate to contact. Detailed documentation, circuit schematics, datasheets and source/binary codes will be available using file sharing service. Also, I would like to know your results. For contact use an IM service on website where this blog was referred from.

2014-03-30

Microcontroller Unit Software

The microcontroller unit acts as an universal device for several experiments and tasks. It is not possible to predict all the functions and features needed in future, so both, the hardware and also the software is modular. The software consists from HAL, the Hardware Abstraction Layer, which isolates all the internal and external peripherals from application, next is the UART Communication Module and the Application Module. Maybe, there will be more in future.

The Application Module contains calls for initialisation all the system and then it is branched into 16 application functions. The function is selected by the DIP switch combination, which is read once after system RESET. Every from the application functions have its own purpose, isolated from others.

Up to now, we have implemented these application functions:

00 - Hand Control Mode

In this mode, there is unlimited loop, when the air pressure is measured in the time interval given by TIME_MARK constant (usually 20 - 100 ms). Data are put on the UART interface in 4digit HEX format. Sending the message is indicated by the yellow LED flash.

When the ADC converter is saturated during measurement, the red LED will glow until another, not saturated value is get. This acts as a overload indicator.

Also the FET switches can be toggled, one button is used for the FET switch selection and second for selected FET switch toggling.

01 - Pressure Record Mode

After RESET and initialisation, the green (init ok) and yellow (waiting) LED glows. The program is waiting for the key press to start. When one of the buttons is pressed, the recording loop will begin.

In the loop, the air pressure is measured in the sampling frequency given by the TIME_MARK constant (usually 20 - 100 ms). When the actual sample is different than previous, result is sent onto UART, together with the time mark number. Message format is simple - two decimal long integers on the line, separated by comma character. Sending of the message is indicated by the yellow LED flash.

When the ADC converter is saturated during measurement, the red LED will glow until another, not saturated value is get. This acts as a overload indicator.

During the loop, both buttons can be used for FET output toggle - you can switch on and off the air compressor or draining valve.

Air Compressor and Valve test

At some experiments, we need a small, but reliable pressurized air source. As a simple solution, a 6 V DC air compressor was tested, taken from a personal blood pressure meter.

The small air compressor from personal blood pressure meter
The DC motor is marked as WRF-370C-22170 and the air pump KPM27C-6C2. Its disadvantage is the air leakage through the compressor, when it is stopped. So there is impossible to make a stable air pressure with it.


Small electromagnetic 3-way valve coil needs 24V / 40mA

We attempted to get rid of the air leakage using electromagnetic valve added after the compressor, but this also was not successful. The leakage was smaller but it was not cancelled.


In the video the air pressure source is used to operate a piston actuator from an old medical machine. The pressurized air source works, but use it for measurement purposes is impossible.

First Measurements on Toys

We are ready to first real test of the air pressure measurement in the vinyl inflatable toy. The first question is, how big is the air pressure in the toy when it is loaded by human body. Next, we are curious, if the pressure is bigger in larger or in smaller air chamber, when the load is the same. Also, we would like to know how big is this difference.

The toy inflation
So next, we inflated a nice INTEX black whale toy and connected it's air valves to our new pressure sensor. The sensor was connected using old air mattress pump nozzle and aquarium 4 x 1 mm hose approximately 2 m long. We believe, that this will not make any significant distortion of pressure changes.

The pressure sensor connection
The pressure was measured in both air chambers, in the large body and in the smaller tail. At beginning, the air pressure was near the same which was given by the air pump used. Next. both chambers were loaded by human body weight and then released several times. All air pressure changes were recorded.

The air pressure in the body recorded

The air pressure in the tail recorded

One can see that the air pressure in the tail can achieve bigger levels, approximately 6.5 kPa peak in our experiment. In comparison, the body achieves only near 3.5 kPa. Also, note the negative peak when the chamber was released, more visible at big body air chamber. Time mark in both charts was set to 20 ms.

Pressure Sensor Calibration

We have all equipment ready, so we go to calibrate the pressure sensor. The U-tube manometer and the electronic pressure sensor were connected together and the air pressure source was added to.

The U-tube reference manometer setup
In the first concept, the small 6V electric compressor from a personal blood pressure meter would be used as a pressure source. But, there was strong problem with the air leakage when the compressor stops. This was not solved by using any of electromagnetic valves after the compressor.

The piston actuator as a reference pressure source

Finally, the piston actuator from old medical machine was used as a very reliable pressure source and it gave exactly the range we need for sensor calibration. There was no leakage in this setup, so if we set the pressure value by the piston move, it will remain without any further change.

A little strange, but reliable connection to U-tube
Water columns balanced in the U-tube
Water columns unbalanced in the U-tube
Finally, we take several values of the pressure represented as a water column heigh difference in the pipes and as the counts value from the electronic sensor. Data from the U-tube manometer were converted into kPa and arranged in the table along with data from the sensor. Then the data was fitted by line and its constants were obtained.


Then, constants were implemented into microcontroller in the main unit. We can measure the air pressure in Pa directly now. Constants was implemented in long integer multiplied by 1000.

Low Cost Air Pressure Sensor

For our experiments we tried to use a low cost air pressure sensor US9116 (UniSense) taken form personal blood pressure meter. It measures the air pressure in the connected pipe as a difference to atmospheric pressure. It is connected as a standard tensometer bridge, so it will need a power supply and an instrumentation amplifier connected to its output. The output voltage around 43.5 mV will be produced by the air pressure 40 kPa.

The low cost air pressure sensor
There was a difference found between datasheet and real sensor, pin 5 is not unconnected, but must be connected to power supply together with pin 3. It feeds one of the bridge branches.

The disadvantage is in very subtle construction, so you cannot expect precise measurement. Also, the tensometers are based on semiconductors, which brings better sensitivity, but error performance is very poor. For now, we will use it while we must look for better sensor.


RS485 Implementation

Standard communication library for the UART (RS232 or virtual COM port) PC connection was modded for the RS485 support. The difference is in electrical layer, where the line is half-duplex. The transmitter must be switched on an off when transmitting the message. Because I use an old library for UART communication of AVR microcontrollers using circular buffer, which is writen in different style than my, it was a tricky task to make all working well :-)

The example of message transmitted over RS485
Now, we have a fast and reliable communication with PC over thin wire pair. The USB/RS485 interface must be used on the PC side. This solution allows us to use longer communication distances (in comparison to USB) and possibility to connect another units on the same line. We will not use any wireless connection, because we need a power cables too.


The PC side USB/RS485 interface with the FTDI chip

The serial terminal receiving data messages

We are ready to communicate now :-)

Microcontroller Unit

For all our experiments, a simple bread-boarded microcontroller unit was built. It contains the ATmega32 16 MHz AVR RISC microcontroller, which have enough Flash and RAM for our tasks. Also its internal peripherals are suitable and I/O pin count is good. The board also contains voltage regulators (+5V for unit, +6V regulated for air compressor and original valve), 4 N-FET switches, 3 LEDs (red, yellow, green for standard indication), 2 programmable buttons and RESET button, ISP programming interface, UART RS485 interface (for communication with PC over a longer distance), 4 DIP switches for operation mode (application) selection and instrumentation amplifier for air pressure sensor. There are also reserved pin groups for I2C bus connected sensors and for the standard 2 x 16 characters LCD display.

Bread-boarded microcontrolelr unit
The metal shield in the right bottom corner contains the instrumentation amplifier, which is very EMC sensitive. The pressure sensor is placed on the bottom side of the board, where access will be better to it. All mechanical parts will be placed on second stage under this board.

In the first experiments, the unit will remain on bread-board. The PCB will be made after the configuration will be verified in praxis. Several changes will be made in the actual form before.