circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

July 2006, Issue 192

Dual-Axis Level Sensor
Philips ARM Design Contest 2005 Winner


by Stefan Morley


Start System Overview LCD Analog Software Implementation Hand that Feeds Where to Now? Sources and PDF

IMPLEMENTATION

I added a calibration routine for getting the unit level. I considered various forms of calibration. One of three approaches can be taken. You can use a look-up table to give exact degrees to relative counts based on a physical calibration by stepping through a number of angles and interpolating the values.

The second approach is similar, but it works on a curve fit of a selection of angles and the relative values from the sensor to arrive at an interpolated value. Then the angle can be worked out mathematically. The datasheets suggest that the sensors are linear for a fair proportion of their stated range ±60 arc degrees. The combination of my circuit’s RC components, the sensor’s RC elements, and the pulses that drive the unit mean that there will be nonlinear elements in the resultant signal.

The third approach uses the unit only as a rough guide for an angle, but accurately determines when the sensor is level.

Adding a calibration routine entails pressing a button. After an initial settling period (the button press will disturb the current reading), the current relative count information is stored. Then the unit is rotated 180° and similar measurements are made. The difference between the two readings in both the x- and y-axes divided by two becomes the point that is level. This calibration can happen on any angular surface, but the best results are achieved when the unit is reasonably level. The calibration routine takes out the unit’s error and the error associated with the mounting of the sensor with respect to the base of the unit. The other way the calibration can be used is to not rotate the unit at all. This effectively centralizes the bubble irrespective of what the real angle is.

I added a routine that gives the appearance of increasing the gain. What I effectively did was make each bit have more weight to move the bubble to a greater degree based on a gain setting. As a result, there is a fixed number of pixels plus and minus from the center on the display that I can move the bubble over. The new result is scaled by the pseudo gain. The bubble is drawn at these new coordinates. To do this, I had to create bounds for the coordinates of the bubble; otherwise, it would have ended up with a wraparound effect where the bubble disappeared off one side and appeared on the other.

There is another use for this routine. It gives a good visual indication of the unit’s stability. Without averaging routines having been incorporated, the unit is stable to within ±1 counts. The situation would only improve with averaging and a suitable board layout. Give consideration to the noise induced from the microcontroller and how this relates to the ADC.