You are on page 1of 6

Queron Williams 10031755

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

Working with a 3-axis Accelerometer


Brief: Design and develop a simple instrument to demonstrate the functionality of a modern accelerometer device. The device must be constructed on copper strip board with the components provided. The provided components included : Pic 18F14K22 i/p (20pin DIL) MCP23017 I2C Port Expander 74HC164 Serial In Parallel Out Shift Register LM317LZ Voltage Regulator MMA845Z 3-axis Accelerometer & 8pin dip adapter 24 (8xRed, 8xYellow, 8xGreen) Low current LEDs

Requirements: The pic must communicate with the Accelerometer through the I2C bus and provide the user with visual feedback of the readings. As there are not enough pins on the pic to connect the LEDs directly the port expander will be used to control 16 of the LEDs (two 8 bit ports). The remaining 8 LEDs will be driven with the shift register. This should provide three 8 segment bar graphs to feed information back to the user, one bar graph for each axis. The finished device must show continuously a representation of the static acceleration (due to gravity) on each axis as the accelerometer is rotated in the various axes. There should also be a Mode option (push-button input) to select between Dot Mode and Bar Mode on the bar graph displays.

Development: The first thing I did once given the task was to find data sheets for each of the provided components and copy all important relevant information on each component into a log book so it was easy to find in future. I also studied the application circuit diagram each component was provided with. I found that the voltage regulator did not output a constant current like regulators that I had used in the past and so I needed to calculate the correct value for 2 resistors that form a feed-back network as shown below. The equation to calculate R1 and R2 is as follows: ( ) ( )

Using this formula I calculated that to get Vout at 5V I needed a R1 of 230 and an R2 of 390. I also found from the data sheet that this regulator can provide up to 250ma current when operation is at 5V so I must use less than this in my final device.

Queron Williams 10031755 Current limiting resistors:

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

Whilst looking up the data sheet for the Leds I found that there maximum current was about 20ma each. This is quite standard for small leds however using 24 of these at this current would be too much total current for the provided regulator (not to mention it may damage the ICs). I decided to use a current limiting resistor with each led to regulate the current. I worked out that each led would need to use less than 10ma to fit within the 250ma limit of the entire circuit. The led.s are rated at a recommended voltage of 2.2 volts on the data sheet. This means from the 5v supply I must drop 2.8V across each resistor. V = I x R can be rearranged to R = V / I and this is used to calculate the required resistance. R = 2.8V / 0.01A = 280 The closest value we could get was 330. This was fine as it limits the current even further below our 250ma limit. 2.8V / 280 = 8.4ma per led. Across all 24 LEDs this gives a net current of 201.6ma (assuming all LEDs are on at once). This leaves over 45ma for the ics to run on which is far more than they require. After testing these values on the breadboard i found that the yellow was dimmer than the red and green. To make the brightness the same I had to lower the resistance to 120 on the yellow LEDs whilst its unlikely that the device will ever have all the LEDs on at once it may happen at some point and with this value the current limit could have been crossed so I decided to stay with the 330 resistors for all colours.

Queron Williams 10031755 Schematic Diagram:

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

I used eagle to design the schematic for my device as this made it very easy to change designs and make the schematic very clear and easy to read. I was able to find most of the components as parts within the eagle library; this made the process very quick and simple. The only part I was not able to find was the pic I have been using. Instead I substituted this with a standard 20Pin DIL as it has the same footprint and pin layout. This circuit was built and tested with a breadboard before finalising the circuit diagram.

This is the schematic for the final design of my device.

Queron Williams 10031755 Strip-board Design:

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

As I had already made the schematic in eagle for this project I decided to do my strip board design in the board layout tool as well. This design is linked to the schematic so changes that are made on one are also made on the other. This means that I cant forget to update te board if I update the schematic. To make the design easy to build on strip board I set the grid spacing to the same as the distance between strip board holes and placed the components manually. When wiring the rats nest I made sure that the strips of the strip board would be used as much as possible for vertical connections (shown in blue) and I would try to keep to number or jumpers as low as possible (shown in red).

This design was able to be copied directly on to strip board and made debugging very easy.

Queron Williams 10031755 The Program:

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

Each part of the program was written and tested individually before being combine to create the final program. My device supports both dot and bar mode and I have customised each for more accuracy. As standard it supports a maximum of 2g acceleration. Dot mode shows where over the range the current reading is. A dot in the centre shows no acceleration where as a dot towards the edge shows large acceleration. Dot mod also has the ability to show both positive and negative readings as it approaches the higher or lower ends of the bar graph. Bar mode can only show the amount of acceleration of each axis (not the direction). However it is far easier to read as no acceleration means no LEDs are on. In the original program the button was used to toggle between bar and dot mode.

Left: Dot mode showing 1g from gravity Right: Bar mode showing 1g from gravity

Extra Functionality: I decided to implement the ability to change the sensitivity of the accelerometer as I had noticed in the data sheet that it supports 2g/4g/8g modes. This required putting the accelerometer in standby, changing its configuration register then resetting it to its active state. One problem I found however was that it was hard to get to the mode you wanted with only one button. I solved this problem by adding a menu with the LEDs. now when the button is pressed it shows whether it is in bar or dot mode and what the sensitivity is currently set to. I was able to use the accelerometer to change modes whilst I this menu. Tilting the device toward you till the green light appears then tilting back to flat will toggle between bar and dot modes. In a similar way tilting the board to the left will increase the sensitivity mode and tilting to the right will decrease the sensitivity mode. Left: Menu showing 2g dot mode selected. Right: Menu showing 8g bar mode selected. Also the green confirmation led can be seen in this picture.

Queron Williams 10031755 Operation and code:

UFME69-20-2 Microcontroller-Based Systems

15/1/2012

This program was written in assembly. A detailed set of flow charts for the final program including the additional functionality will be enclosed at the end of this document. This includes flow charts of general operation and detailed flow charts for all functions within my program. I have also included a full copy of the final code.

Results and Conclusion: This project has gone well and I feel that I have achieved a high standard with my final product. The device I have produced is tidy and reliable. It meets all of the requirements of the task and also includes some extra features that make it clever and unique. I if I were to complete this task again there are some things I would do the same and things I would do differently. I think it was a good decision to start in eagle from the beginning as this made making small alterations to the circuit very easy however next time I think I would have this design made into a pcb rather than constructing it on strip board. This would enable the device to be a lot smaller and look amore professional. It would also make assembly a lot easier. Another thing I would do differently is that I would structure the code differently. One problem that I found was when the sensitivity was turned down the menu became hard to use. This was fixed by adding lots of checks for sensitivity and changing thresholds to match however this was not ideal. If I was to rewrite the software I would make it so that the mode was changed back to 2g mode whenever the menu is opened and as soon as the button is released it will return to the requested sensitivity mode. This would keep the thresholds for the menu far more consistent and make it easier to manage. I feel that I have learnt a lot whilst completing this assignment and look forward to applying these skills to other projects.

You might also like