two adc_read problem

General discussion on mikroC.
Post Reply
Author
Message
thinkpositivex23
Posts: 8
Joined: 01 Mar 2010 09:24

two adc_read problem

#1 Post by thinkpositivex23 » 13 Oct 2010 04:08

hello....
sorry i'm beginner in make a coding
i want to make two adc read by follow this coding

int TGSsens; // set variable name 'TGSsens' as TGS2600 sensor value
int temp = 0; // set variable name 'temp' as temperature value

void main()
{
ADCON0 = 0xFF;
TRISA = 0b11111111; // initialize Port A as IRsens pins

while(1) // create infinite loop
{

temp = ADC_Read(0); // Read from pin RA0
if ( temp >= 32 && temp < 48)
{
PortB.F6=1; // then RB6 will turn On

}
else
{ PortB.F6=0;} // if not RB6 off



TGSsens = ADC_Read(1); // Read from pin RA1
if ( TGSsens >= 205 && TGSsens < 52)
{
PortB.F6=1; // then RB6 will turn On

}
else
{ PortB.F6=0;} // if not RB6 off

}

but....while adc read at RA1, its not happen as well..
can other solve it.......

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: two adc_read problem

#2 Post by KaranSoin » 13 Oct 2010 07:14

Its not very clear what you are trying to do, but one very obvious mistake is

Code: Select all

if ( TGSsens >= 205 && TGSsens < 52) 
{
PortB.F6=1; // then RB6 will turn On

}
This is logically dead code. My guess is that you put && instead of ||

cheers

thinkpositivex23
Posts: 8
Joined: 01 Mar 2010 09:24

Re: two adc_read problem

#3 Post by thinkpositivex23 » 13 Oct 2010 08:33

sorry...my mistake...

i've change the coding
if ( TGSsens >= 205 && TGSsens < 52)
{
PortB.F6=1; // then RB6 will turn On

}

with
if ( TGSsens >= 52 && TGSsens < 205)
{
PortB.F6=1; // then RB6 will turn On

}

and its work as i expect...

thank a lot...

Post Reply

Return to “mikroC General”