# Develop code and algorithm for ADC tilt sensor

#### Kastun27

##### Newbie
Hello everyone. I'm trying to figure out a method to output an angle from -90° to 90° on a 4-digit seven-segment LCD display via ADC and PIC16F84. Here are my components:

1) PIC16F84
3) AY0438 LCD driver
4) Varitronix VI-422-DP-RC-5 four-digit LCD
5) SCA60C tilt sensor

I'm using MPLAB and have managed to get this setup to display an input analog voltage from 0-5V using some basic code and a lookup table, but I'm a little stumped on how to output -90° to 90° from my tilt sensor. The SCA60C outputs 0.5V - 4.5V from -90° to 90°, with 2.5V at 0°. I'm assuming the output won't be the greatest considering it's an 8-bit micro, but close will suffice. I suppose 0-180° would work as well if it's easier, but I figured I could just use the middle segment of the 4th digit on the display for the negative values if possible.

##### Super Moderator
Staff member
Somewhere along the line you want to convert numbers to BCD (binary coded decimal). Thus to display 90 you have two digits, 9 (binary 1001) and 0. These are multiplexed into the LCD driver and then out to the LCD.

ADC gives you binary format. Software can convert it to BCD. Also software converts negative numbers to 2's complement binary. Or else it recognizes how to handle a negative number by displaying absolute value, and turning on a suitable segment as you plan.

You have a basic classic linear straight line relationship between V and Angle,
y = mx + b, plug your datasheet values into that, you get two equations in
two unknowns, and solve for b, the offset, and m, the slope. y being the angle, and
x the voltage.

Then convert that to segment data, digit by digit using a LUT, and send out to the
display.

Regards, Dana.0

Replies
12
Views
2K
Replies
2
Views
771
Replies
11
Views
7K
Replies
45
Views
73K
Replies
0
Views
1K