Analogue signal aquisition using PIC microcontroller

Thread Starter

AustinCann

Joined Jan 30, 2011
12
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)
acq_volt=Adc_read(1) // acquire through channel one of adc module
if(acq_volt>2.5)
PORTB=0X01;

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

Many thanks for help
 

debjit625

Joined Apr 17, 2010
790
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.
"adc_value" is a variable where you store your 10bit ADC value after ADC conversion.

Rich (BB code):
adc_value = Adc_read(1);
if((adc_value * 0.00489) > 2.5)
{
  //your code 
}
Rich (BB code):
adc_value = Adc_read(1);
if(adc_value > 512)
{
  //your code 
}
A little math will do it

Good luck
 
Top