Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Develop code and algorithm for ADC tilt sensor

Kastun27

Newbie
Joined
Apr 8, 2021
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
14
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
2) ADC0831 ADC
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.
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
13,978
Helped
2,786
Reputation
5,570
Reaction score
2,693
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
104,275
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.
 

danadakk

Advanced Member level 3
Joined
Mar 26, 2018
Messages
867
Helped
169
Reputation
341
Reaction score
190
Trophy points
43
Activity points
4,103
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
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top