Inclinometer

by Nicholas on June 7, 2009

in hardware, software

During my second year at UBC, one of the projects we had to do was an Inclinometer. The idea behind this was to design a capacitor using a petri-dish and aluminum foil covering half the petri-dish and using water as the dielectric. Because the capacitor had only half the water to fill it and only half of petri dish had aluminum, the capacitance across the capacitor would be different with different angles. When the dielectric between the capacitor plates is 100% water, the inclinometer’s angle is treated as zero degrees. When none of the water is between the plates and is all of it is between the plastic sides, then it is considered to be at 180 degrees. The capacitance is used by a LM 555 Astable circuit, which in turns generates a frequency for the microprocessor. The microprocessor measures the frequency in Hertz, converts it to an angle in degrees through a pre-generated lookup table arrived at experimentally, then displays it on a 4-digit 7-segment display.

inclin1.jpg

inclin2.jpg

DESCRIPTION

Capacitor

The capacitor was made with a petri dish, aluminum tape, electrical tape, and wires connecting it to the LM555 timer. The dish was pasted together with silicon and aluminum tape put on exactly half the surface area on the circle. The aluminum tape semi-circles are lined up with each other making two parallel metal plates forming the basis of a capacitor. A hole was then drilled in the petri dish, so it could be filled with a dielectric. The amount of water that is between the aluminum tapes will affect the capacitance that is sent it to the astable circuit. After the capacitor was built, slight leakage occurred over time. Tape was applied to the sides of the capacitor, sealing it and giving it a slick design. See Appendix B for pictures.

Measured diameter: 0.14m
Measured thickness: 0.015m
Water dielectric constant at 20o: 80.1

Capacitive surface area: 0.5 ( π r2 ) = 0.0049π /2 m2
Theoretical Cmax = ЄS /d = (80.1) (8.85 E -12) (0.0049 π ) / (0.015) (2)

= 3.637 E -10 F

Measured Cmax ~= 90 pF

Astable Circuit

The circuit is based on the LM555 timer IC, connecting it to two resistors and a capacitor. This in turns creates a frequency as an output that is sent to the microprocessor. The circuit is built in the following manner (See Figure 2).

Figure 2 Astable Circuit [1]

To derive the formula for the oscillator we use the formula equations:

vC = VCC – (VCC – VTL ) e –t/C(RA+RB)

Where we have t = 0 is when the interval TH begins. Having vc = VTH = 2VCC/3 at TH and VTL = VCC/3, then:

TH= C(RA+RB) ln2

vC = VTHe-t/CRB

This is for the beginning of the interval TL. Then we substitute vC = VTL=VCC/3 at t = TL

TL = CRB ln 2

Combining TL and TH, we have T = 0.69 C (RA + 2 RB) Equation (1)

The value chosen for the resistors was ideally 20k Ohms. R2 was constant but R1 was a variable resistor and 14.7 k Ohms in series, making analog adjustments more accessible when dealing with calibration. The petri-dish capacitor did not have a capacitance high enough to show a readable frequency in some cases, so we put a 0.47 nano-Farads capacitor in parallel.

Using the Equation (1), we can figure out the capacitance that we need to get a certain frequency and vice versa.

7 Segment LED Display

The 7 Segment display is connected to the microprocessor as follows:

inclin3.jpg

Figure 3 Microprocessor to HEX display Circuit

This is from part of a bigger circuit designed by Dr. Jesús Calviño-Fraga found in Appendix A. After an input frequency is sent to the microprocessor via pin 10, it’s processed result is output to the display. To reduce the number of pins needed, the display is multiplexed with four transistors, using the persistence of vision effect to create the illusion of steady numbers. The 330 resistors regulates the current going into the LED’s and the 4.7k and 2.2k resistors is to regulate if the LED’s are on or off according to the output sent by the microprocessor. We tested the segments by sending different signals to the pins and used the datasheet [2] to troubleshoot it when some segments were not functioning. For the final version of our hardware, we simplified the circuit to a bare minimum, removing the 330 and 4.7k resistors. This increased the current drained, but made the project much more compact in case we had time to reassemble it in an enclosed container.

Software

The frequency measurement code was based on the freq.asm example file provided with the project. The 7 segment display control code was also based on an example file, disp925.asm. The blocks in between were written from scratch. The byte to 4-digit decimal conversion was done with a successive loop algorithm [3] that incremented digits while subtracting 100s, 10s, and 1s from the byte – it took a while to figure out, but the end result was short and succinct. The frequency to angle code, however, is hideously long and makes up most of the program.
Lookup Tables

The lookup tables were used by the frequency to angle code to quickly convert a measured frequency to a corresponding angle. They were based on experimentally obtained data points, which were then processed in Excel. The processing consisted of plotting a graph, adding a trend line, then using the equation of the trend line to extrapolate the full range of frequencies from 0 to 180 degrees. The resulting frequencies were then all split into high and low bytes (to accommodate the 8051’s 8-bit architecture) and put into two separate tables, which could be copy and pasted directly into .asm files. A third table was generated for the digit after the decimal point; this way, using three separate lookup tables, we were able to search them all without overflowing byte-sized registers.

The method of collection was with the Windows hyper terminal program. After loading the frequency hex file into the microprocessor, we took measurements. If we collect the values from the oscilloscope, they were different from the ones that were read from hyper terminal. Because the value that the chip receives is the same as the one read on hyper terminal, the oscilloscope values that were taken had to be discarded.

Frequency to Angle

The measured frequency was in 16 bits, which caused a problem for the 8-bit processor. A 180-degree 2-byte lookup table couldn’t be covered with a 1-byte offset. An additional challenge was our goal of getting a 4 significant figure result – which, if done with one lookup table, would need one 2 * 1800 bytes long. This would push the resourses of the LPC925 to their limits.

We chose an alternate method: we split our lookup table into three parts. The first two took care of the integer angle – no decimal point. Lookup table one, 181 bytes long, stored the high byte of 16-bit frequencies which most closely corresponded to certain angles. The code compared the high byte of the incoming frequency to lookup table one, and found the first value where the two were equal. Then lookup table two – the low byte – was compared. A value just under the input frequency was found, and its’ position in the table became the angle.

Overflows were an issue we ran into. If an input frequency was too high, it was easy to overflow the lookup tables and get into unknown memory. The processor usually froze at that point, forever displaying a single value. Overflow checks had to be added.

On the low byte lookup, care had to be taken to watch for the point where the table overflowed and started again from zero. Safeguards against this were put in.

Finally, once the integer lookup was working, decimal support was added. A third lookup table was created. The input frequency minus the frequency in the first two lookup tables was checked against the third lookup table. Its’ position relative to the values there gave the digit after the decimal point. Again, overflow checks were added – although this time there was existing code to base them on.

Evaluation
Testing the circuit as a whole required each independent part to be functional. After the microprocessor can be flashed, the circuit built, and the 555 timer working the way it was supposed to, we fitted each part together and tried the code. Because the angle displayed seems to vary after each slight change in environment such as distance away from the power supply, it was then that we added a varying resistor into our circuit. This varying resistor, along with 14.7k Ohms in series, became the second 20k Ohms resistor part of the 555 timer.

When we finished testing the circuit built on the two breadboards, we reformatted all the wiring and took out all unnecessary resistors, which turned out to be most of them (See Appendix C). The only resistors left on the breadboard were the 2.2k resistors that controlled the circuit for the display and the resistors that controlled the frequency on the 555 timer. One unexpected problem we encountered was that the thickness of the brown wire did not fit into some of the pin holes on the breadboard. This resulted in a disfiguration in the wiring colour scheme. Some of the wires that were supposed to be brown now become red. After reformatting the breadboards, we kept one for solely having the purpose of programming the chip, and a second breadboard was to run the program with the 555timer. Because the 3.3 k Ohms resistors were taken out, the LED segments were brighter, making it easier to see.

After having the first three digits, our group wasn’t satisfied until we could achieve the fourth digit. We then added the third lookup table, which calculated the digit after the decimal point by looking at how far above the 0-180 degree lookup frequency the measured frequency was.

Our project, in the end, become very neat and had a very easy way to calibrate to 90 degrees with the varying resistor. The design on the whole was easy to follow, and the code (after much, much debugging) was reliable and error-proof.

Ways of Improvement

In the end, we ran into two significant problems when it came to accurate degree measurements: interference and calibration. At the last minute, a change was made to increase the update speed of the display by a factor of two. This was done by doubling the frequency of the LM555 square wave generator, which had unforeseen effects on the capacitor’s reliability. Moving a hand near one of the plates changed the reading by at least ten degrees – holding it in the wrong way caused shifts.

This problem added to, and amplified the errors caused by our calibration procedure. Our hardware was separated onto two boards: one housed the computer communication components, while the other was a standalone inclinometer. We transferred the microcontroller back and forth when we had to flash it – and did our calibration measurements on the computer communication board. Significant differences in current draw and possibly interference between the two boards led to faulty lookup tables.

Future versions should isolate the capacitor with a shield. Soldering the circuit on a printed circuit board to reduce parasitic capacitance could also help.

Conclusion
Our project had some hiccups during the presentation, but the causes were isolated and simple solutions exist. We’re confident that, with a few modifications, better-than-required accuracy could easily be achieved. The most time consuming part was the assembler code – now that that’s done and proven to be reliable, remaining modifications can be fairly minor.

An important difficulty we found is that the values below 20 degrees and above 160 degrees did not follow the rather linear pattern that was shown in the 20 – 160 degree range. We tried to incorporate this irregularity by using polynomial fitting curves, but that negatively affected the linear section… In retrospect, a mix of both approaches would have worked best, with linear fitting for the central part and polynomial for the edges.

{ 3 trackbacks }

Web News Site » Blog Archive » DIY electronic inclinometer: Measure tilt using water!
August 18, 2009 at 12:58 pm
Shop Club Blog » DIY electronic inclinometer: Measure tilt using water!
August 18, 2009 at 11:58 pm
DIY electronic inclinometer: Measure tilt using water! - machine quotidienne
August 19, 2009 at 12:12 am

{ 0 comments… add one now }

Leave a Comment