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.

[PIC] adc conversion using pic 12f675

Status
Not open for further replies.

Gopi Vh

Newbie level 4
Joined
Jan 10, 2015
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
44
help me out i am not able to read the adc value .
i am reading adc value from analog channel 2
here my code is there


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* adc conversion*/
   unsigned char adc_value;
unsigned char sensor;
char *text="00000";
const gas_max = 642;
void main()
{
 
 ADCON0 =0x08;
ANSEL =0b00000110;
ADRESH =0;
ADRESL =0;
CMCON = 7;
 GPIO=0;        //clear all pins
TRISIO.B2=1;    //ip
TRISIO.B1=0;        //op
TRISIO.B0=0;        //op
TRISIO.B5 =0;     //op
 
while(1)
{
 
adc_value=adc_read(2);
 adc_value= (((unsigned int)ADRESH<< 8)| (ADRESL));
 sensor =(553 - (adc_value-61));
 delay_ms(200);
if(sensor < gas_max)
{
 
  GPIO.B1=1; //green led;
  delay_ms(20);
}
else
{
 delay_ms(20);
    GPIO.B0 = 1;  //red led
 
    GPIO.B5 = 1;    //buzzer
}
 
 
 
    }
   }

 
Last edited by a moderator:

Code:
ANSEL =0b00000100;

If you need one pin as just analog input(BN2) and rest as digital output.
 

hello,

and use an "int " to store and use the 10 bits adc result...
 

its not yet working
i am using that for gas sensor
i used the above correction but still its not reading the analog ip value from mc
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* adc conversion*/
   unsigned int adc_value;
unsigned int sensor;
char *text="00000";
const gas_max = 642;
void main()
{
 
 ADCON0 =0x08;
ANSEL =0b00000100;
ADRESH =0;
ADRESL =0;
CMCON = 7;
 GPIO=0;        //clear all pins
TRISIO.B2=1;    //ip
TRISIO.B1=0;        //op
TRISIO.B0=0;        //op
TRISIO.B5 =0;     //op
 
while(1)
{
 
adc_value=adc_read(2);
 adc_value= (((unsigned int)ADRESH<< 8)| (ADRESL));
 sensor =(553 - (adc_value-61));
 delay_ms(200);
if(sensor < gas_max)
{
 
  GPIO.B1=1; //green led;
  delay_ms(20);
}
else
{
 delay_ms(20);
    GPIO.B0 = 1;  //red led
 
    GPIO.B5 = 1;    //buzzer
}
 
 
 
    }
   }



try this code what is your output read result?
 

hello,

did you test ,before , your program ADC reading, by using a potentiometer ( <= 4,7K) powered by VCC.
Because you can have some probleme with your Gas sensor itself, needs high impedance ADC input to
give a correct signal.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top