# Analogue signal aquisition using PIC microcontroller

Discussion in 'Programmer's Corner' started by AustinCann, Mar 10, 2011.

1. ### AustinCann Thread Starter New Member

Jan 30, 2011
12
0
Hello
There is one confusion before I implement my code in hardware.
I read the pic microcontroller I am using is 10 bit. The signal I am acquiring through pin configured as analgoue vary from 0 to 5 volt. I want to activate few leds if certain condition is met. Knowing that ADC converts the signal into 1024 steps where each step is equal to roughly 0.00489.
Question is what value could I use in the software within decision statements such as if/else. Do I use values straight as 2, 3, 4 or corresponding quantized step value such as 512 for 2.5, 216 for 1.25. In other word which one of the following statement is correct.

1)
if(acq_volt>2.5)
PORTB=0X01;

2)
if(acq_volt>512)
PORTB=0X01;

Many thanks for help

2. ### debjit625 Well-Known Member

Apr 17, 2010
790
186
Look when you read ADC value you will get a value between 0 to 1023 for a 10bit ADC, but if you want to met some condition in your code at any voltage level (from 0 - 5) rather then binary value (from 0 - 1023) you have to convert the binary adc value to a voltage level like this.

Code ( (Unknown Language)):
1.
3. if((adc_value * 0.00489) > 2.5)
4. {
6. }
7.
Code ( (Unknown Language)):
1.
4. {
6. }
7.
A little math will do it

Good luck

AustinCann likes this.