Username:     
Password:     
             

Contest 2013/2014
Contest 2011
Contest 2009
Contest 2008
Alcoholmeter 1.0
 
The goal of this project is to provide a simple alcoholmeter, which is able to determine approximately the amount of consumed alcohol. With this information the application is able to determine if you may drive. The application shall provide a simple user interface, using the touch screen capabilities of the Primer2. This projects consists of two parts. 1. The first part is the extension board, that contains the sensor which measures the amount of alcohol measured in the air. 2. The second part shall be the application, that will provide the user interface and translates the measured values from the sensor. For users who would like to play with the application, but don't have the extension board - the application should even run without the extension board.

Code size:22 kB Author:androot
Source files included:yes Version:1.0
Use circleOS:yes (1.7) Creation date:2009-06-25 23:28:17
Hardware modification:yes Modification date:2009-06-26 08:45:04
Based on the STM32 Primer:Primer2
   
Downloads:2320 Views:27880
   
Vote:
Average ratings:0/5 (0 rates)

Download:    Alcoholmeter-Primer-2.zip (4956 KB)

Description:

Alcoholmeter

 

 

Foreword

 

The goal of this project is to provide a simple alcoholmeter, which is able to determine approximately the amount of consumed alcohol.

With this information the application is able to determine if you may drive.


The application shall provide a simple user interface, using the touch screen capabilities of the Primer2.

This projects consists of two parts.

1.    The first part is the extension board, that contains the sensor which measures the amount of alcohol measured in the air.

2.    The second part shall be the application, that will provide the user interface and translates the measured values from the sensor.


Both points will be described in detail below.


For users who would like to play with the application, but don't have the extension board - the application should even run without the extension board, but I don't know how the Primer2 will interpret the ADC values.

 

Extension board

 

This project is a simple extension board for the Primer2.

 

The major parts are:

·      Ethanol sensor – AF-63,

·      DC/DC step-up converter.

 

Other parts are:

·      turn on/off heather in sensor,

·      LEDs to indicate the state of the alcohol tester.

 

AF-63 is an easy to find and a low cost sensor. It must be warmed up before starting the test. The warming up time is about 10-20 seconds depending on its storage time and its humidity. To turn the heather on, set logic high level on port PC4 (pin 11). This state is represented by lighting red LED. After approximately 15 seconds the signal from the sensor should be stabilized. This will be checked by the application and the user may start to blow softly at the sensor. This state will be indicated by lighting up the yellow LED. The measuring time is 5 seconds.

 

Because the sensor does not have a pre-defined resistance value, the maximum value during the measurement shall be compared with the calculated bias value. The percentual difference shall be used as an indication to convert the voltage to the level of physical alcohol.

 

These ranges were taken from the diagram that was used within the AF-63 documentation.

 

The 2,8 [V] supply voltage from the Primer2 socket (pin 1) is boost up to 5 [V] and used to supply the heather and the AF-63  sensor.

 

The resistors divider R3 and R4 is responsible for the step-up voltage. Double, parallel capacitors C1, C2 and C3, C4 are necessary to improve the ESR parameter of both. The green LED indicates that the extension board has power supply from the Primer2.

 

The application will measure two ADC values from the extension board. The output voltage from the sensor is divided by a resistor divider. Which allows the application to choose between a better or worse sensivity. In case the sensor will detect a large amount of alcohol, the more sensitive signal will overflow the ADC converter.

 

The figure below shows the schematic of the extension board.


 


 

Application

 

The application can be divided in 4 parts:

1.    The touchscreen handler

2.    The touchscreen interface handler

3.    The ADC conversion

4.    The application

 

The touchscreen handler

The CircleOs 3.7 already contains a touchscreen handler module. However, this module also contains the drawing capability.

Therefore it has been decided to not use this original module and replace it with a almost identical module, which does not contain the drawing capability.


The new touchscreen handler also retrieves the calibration parameters from the OS backup registers.

One item, which had to be overcome, was not altering the ADC1 conversion which was used by the OS. Because the application has no access to ADC buffer, used within the OS, an other way has to be chosen to reach the ADC values.


The OS uses the DMA to store the recent ADC values. An application does not have access to this specific ADC buffer, but it has access to the DMA registers. The pointer to the ADC buffer can been retrieved from the DMA register.

This allows the application to use the full capability of the touchscreen, without altering the OS configuration.


To avoid unwanted pressing a touch press/release mechanic has been implemented.

The touchscreen Interface Handler

Since we would like to use the complete screen and not to use the original toolbar, it was decided to remove the toolbar handler from the scheduler.


The interface handler is responsible for drawing the proper interface and interpreting the position of the touch press, depending of the current state of the application.


This has been achieved by using a simple state machine. The different interfaces will be described later in this document.

 

The ADC conversion

The application needs to read two ADC channels from the extension board. ADC1 is already used by the OS, therefore ADC2 has been used for the application.


Due to the slow signal from the sensor, there was no need to use the full capability of the ADC. Everytime the OS calls the application handler, both ADC channels are sampled. The results are filtered through a 16 sample moving average filter. The result is used to determine
the stability of the signal and the measured alcohol value.

 

The application

The application initialize function will perform the following handlings:

·      Replace the touchscreen handler with the "alco_tscreen_handler" and initialize the new handler

·      Replace the toolbar handler with the "alco_iface_handler" and initialize the new handler

·      Disable the screen rotating capability

·      Disable the pointer

·      Initialize the ADC and GPIO pins that will be used

·      Enable the sensor heather


The application handler is a simple state machine, that mainly responsible is for gathering and interpreting the ADC samples.

·      Wait till the IFace handler will tell us that it is allowed to gather data

·      Wait till the sensor signal is stable

·      Gather data for the next 5 seconds and store the maximum value

·      Calculate the amount of alcohol using the maximum ADC value.



Application flow


The application has 6 different stages (and interfaces).  

Most interfaces will move to the next stage automatically or by a button. For the few interfaces which don’t have this capability, the “beer” button can be used to go to next interface.

The following section will give a short description of every stage.


Application Start Up:

·      The sensor heather is enabled and the application waits for the user to start the alcohol measurement.

·      The application asks the user its sex.

·      The application asks the user the country he's living in: (use the “beer” button to go to the next stage)

·      The application waits till the sensor signal is regarded as stable.

·      The application will show a “begin” button – after pressing this button, start softly blowing to the sensor.

·      The application displays a progress bar.

·      At the end application displays measured value of alkohol concentration. Red background - value to high to drive a car in selected country, green background - OK.