Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

I am having this problem in ADC MikroC; Comparission in IF statement is not working

Status
Not open for further replies.

atifsheikh_91

Member level 1
Joined
Dec 28, 2011
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,566
Compiler Used = MicroC for PIC
MicroController= Pic16f877a; (and tried other too).

hi all; I am designing a circuit in which ; a potentiometer is used to change the output of Portb; when the voltage is above 2.5 PORTB=1 and when it is low PORTB=0.

Please help me out ; i have chk a simple program with ADC ( given in MICROC) and it is working fine.

code is as

/* task is to make PORTB=1 when read>2.5 and PORTB=0 else; */

// I have tried different program ( without comparassion ) they are working fine
// but this comparission is not doing right operation





void main() {
float read;
ANSEL=0b00000001;
trisa=0xff;
TRISB=0X00;

portb=0x00;


ADC_Init();// ADC initiallized
while(1){

read=ADC_Read(0);
if(read>2.5)
{
portb=0xff;

}
else if(read<2.5)
{
portb=0x00;

}
}




}



Proteus Circuit is attached Capture.PNG


Please help me out
 

read doesn't represent a floating number voltage but a 10bit result .

The ACD result is 0 to 1023 where 0 represents 0 voltage and 1023 the Vref voltage.
To convert the result in voltage you have to use (ADCresult/1023) * Vref but in order to have an accurate result you need to store the result in a float.
An alternative is to multiply the result with 1000 so that the result becomes an integer, ((ADCresult*1000)/1023) * Vref , in that case the result will be in mV
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top