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.
Showing posts with label virtual. Show all posts
Showing posts with label virtual. Show all posts

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.

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.