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.

Register Log in

floating value of ADC pic16f877

Status
Not open for further replies.

mamech

Full Member level 3
Joined
Nov 9, 2010
Messages
176
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,135
Hello

I tried to read from analog pin and read it on my computer using terminal program. I used the following code:

unsigned int temp_res;

void main() {
ADCON0 = 0x00;

TRISA = 0xFF;
TRISC = 0;
TRISB = 0;
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);


do {

temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
if (UART1_Data_Ready()) { // If data is received,

UART1_Write(temp_res); // and send data via UART
}

PORTB = ~ Portb;
Delay_ms(2000);
} while(1);
}

So I am reading the value on the pin and send it by serial to computer. I change the value of the analog i/p using a pot.

But there are a problem facing me. The value that I read on terminal program swings and does not stabilize even if I disconnected the pot and connected the supply directly.

Why does this happen?
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,200
Helped
1,142
Reputation
2,303
Reaction score
1,119
Trophy points
1,403
Location
Brazil
Activity points
53,587
Just to check : What C compiler are you using ?

+++
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,200
Helped
1,142
Reputation
2,303
Reaction score
1,119
Trophy points
1,403
Location
Brazil
Activity points
53,587
mamech

The structure of program seems be strictly apropriate.
However, we don´t know how the API ADC_Read were implemented in compiler.

Thus, I can sugest you research in that compiler if there exist a way to you monitor A/C SFR to check if conversion finish were achieved.


+++
 

mamech

Full Member level 3
Joined
Nov 9, 2010
Messages
176
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,135
Actually I do not know if what I am facing is normal or not. I attach a photo captured from my terminal program, while receiving fixed analog i/p value from potentiometer.



The value displayed is not stable even if there is no change.

Actually I do not think that the compiler is involved in this problem. I have some doubts:

1-The defined variable in microC is unsigned int, and it should be max 2^10 -1 value because the limitation of the ADC. The terminal program has only 2 suitable formats to show the :twisted:ed int 10 data?

2-What is the refere i/p value nce voltage that the ADC compare the with? Does it compares with VCC?

Thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top