## Measuring Acceleration Using a PIC Microcontroller

Keywords: 16f84, pic tutorial, pic microcontroller, g force, acceleration machine

Motivation and Audience:Motivated by one of the article from circuit cellar, I want to trace the author's steps to see how the G-Force machine work. The author wrote an article on how to build a machine, that measure acceleration using a PIC 16F84 and a acceleration sensor.

Audience will require expience in programming PIC Microcontroller (intro to microcontroller) and basic electrical background

Part List

US-based vendors include Jameco, Digikey, JDR and Radio Shack.

The Parts

Figure1

ADXL202AE is a 2-axis accerlerometer with analog or digital output. The digital sifnals whose duty cycles (ratio of pulsewidth to period) are proportional to acceleration. The duty cycle can be measure by using a microprocessor counter. Algorithm is posted later in this tutorial. The duty cycle period is adjustable from 0.5ms to 10ms by adjusting the resistor attach to Rset.

Acceleration experienced by the ADXL202 may be calculated by the following formular:
Acceleration(g) = (Duty Cycle -Duty cycle at Zero(g)) / (Duty Cycle per g)

if the nominal duty cycle output of the ADXL202 is 50% at zero g and 12.5% duty cycle change per g. Therefore to calculate acccerlation from the duty cycle:

Acceleration(g) = ( ( T1/T2 ) - 50% ) / (12.50%)

Figure xxxx Copyright to Nick Vaillant, Spartan Embeded Technology

Figure xxxx

Duty Cycles: think of this as a square wave, the longer the pulse of the wave is, the higher is that value. And have a counter count how many time of certain interval that the pulse stay high and low will give us the value.

The duty cycle = (pulse interval) / (period).
The period is set using a resistor at T2 (Rset)

Voltage Regulator LM78L05:

The voltage regulator will ensure a correct level of voltage supply to component.

Figure2 and Figure3

The LCD: We are using a DCM-16L207 LCD. This LCD has 2 line, 16 character per line display. The x207 has capability of displaying ASCII characters.

Note: The Lcd has port 1 -> 14, the circuit use port 14 -> 11 for 4 bit data transfering, port 6,5,4 for LCD control, port 2 for drive voltage and port 1 for ground. Missing from the circuit is port 3 which drop through a resistor or a potential resistor to controll the contrast of the LCD. Missing this resistor will leave the LCD blank and you won't see anything. I use a 3.5K Ohm for this, anything near it will be ok.

insert picture of LCD here

Building the circuit

Figure4 Copy right of Ross Tsukashima, Circuit Cellar Magazine, issue 154 May 2003

Building the circuit require time and determination. Since the ADXL202 sensor is very small, having a mounted board for this chip will make work easier. I didn't think of it when I build this circuit so you can see that my board is kind of messy. But as long as I have the sensor oriented correclty, this won't affect the performance

Figure5
Note: As you can see, I have made mistake not connect any resitor to pin3 of the LCD, it take me some delay to figure out this mistake. When debug your circuit, all part are significant. I kind of take that for granted and didn't check the LCD carefully.

The test run

Figure6 Image display the calibration routine

Figure7

The Programs

You can find the program by downloading it from here,GFORCE3.asm,GFORCE3.hex,GFORCE3.pbp. The author write this program using Picbasic Pro Compiler, which you can find an evaluation copy here PicBasic Complier.

Final Words

Building this tutorial was a good experience. I get to learn about the ADXL202 sensor, PWM, DCM the LCD and best of all, I get to play with more electrical toys.

References