PIC ADC Float value issue

Status
Not open for further replies.

mugheesnawaz

Member level 1
Joined
May 1, 2013
Messages
39
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,605
i am using pic 16f877A and using its adc AN0 for my input voltage.
i am using divide by 10 voltage divider (i.e if input is 24V, 2.3V will be fed to pic microcontroller).
now i want to display this 24V at the led output in binary but i am getting 23V output display.kindly help me i am getting rounded values of adc.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void main()
{
PORTA = 0x00;
PORTB = 0x00;
while (1) // endless loop
{
float a1,solarV1;
TRISA = 0xFF; // Set PORTA as input
TRISB = 0x00; // Set PORTB as output
ADCON1 = 0xC0; //All pins as Analog Input
a1=ADC_Read(0);
solarV1= (10*(5*a1)/1024);
PORTB = solarV1; //Lower 8 bits to PORTB
 
}
}

attached is the proteus design picture

 

It didnt help i added 0.5 but it isnt giving accurate result

it seems normal to display 23 for 2,3V as analog input value !
don't forget that simulator means ideal device for Analog input..
PIC ADC as a not so important input impedance with is in parralele with the R divisor input,
so not divide exactly by 10.

For 24V you must have 2,4V on your analog input ! don' t you ?
Replace R7 9K value , by 8,2K + pot 1K to adjust input voltage as Vin/10
and check after..
 

Why are you using a float type, when the output is an integer type output as binary?

Firstly, you need to ensure the ADC is properly configured, which it does not appear to be, as ADCON0 is not initialized.

Also where is the source for the ADC_Read() routine?


Configure the ADC output as left justified and output the high byte, ADRESH, to PORTB.
 

i have updated my code with adcon0 and adcon1 declared and adc is working properly and then i changed 9k to 8.2k it gave 24V to 2.61V this isnt divide by 10.and displayed on leds gave me 26
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…