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.

PIC18f452 ADC problem

Status
Not open for further replies.

icefire91

Newbie level 6
Joined
Sep 2, 2011
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
I am using a LDR to sense light. i have attach a picture how i connect it up to the adc.
The problem is when i connect it up to MCT the mct analog input is 0V, it just cannot sense any voltage. But when i connect the adc up to a voltage source it work perfectly normal.
The resistance of the LDR is huge without light it will be at 1.2M OHM

#pragma config OSC = HS, OSCS = OFF
#pragma config PWRT = OFF, BOR = ON, BORV = 45
#pragma config WDT = OFF, LVP = OFF
#pragma config DEBUG = OFF, STVR = OFF
//////////////////////////
#include <P18F458.h>
#include<stdlib.h>

void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}


void main(void)
{
#define LOW 990
#define MID 952
#define HIGH 727

unsigned long i;

TRISAbits.TRISA1=1;//for analogue input
TRISBbits.TRISB7=0;
TRISBbits.TRISB6=0;
TRISBbits.TRISB5=0;
TRISBbits.TRISB4=0;
while(1)
{
ADCON0 = 0x89; //AN1 for analogue input
ADCON1 = 0xC4; //Vdd as Vref
ADCON0bits.GO = 1; //start conversion
while(ADCON0bits.DONE == 1);
i=(ADRESL+ADRESH*256);
if( i > LOW )
{
PORTBbits.RB7 = 1;
PORTBbits.RB6 = 0;
PORTBbits.RB5 = 0;
PORTBbits.RB4 = 0;
Delay(3000);
}

if( LOW > i && i > MID)
{
PORTBbits.RB7 = 0;
PORTBbits.RB6 = 1;
PORTBbits.RB5 = 0;
PORTBbits.RB4 = 0;
Delay(3000);
}

if( MID > i && i > HIGH)
{
PORTBbits.RB7 = 0;
PORTBbits.RB6 = 0;
PORTBbits.RB5 = 1;
PORTBbits.RB4 = 0;
Delay(3000);
}


if( i < HIGH)
{
PORTBbits.RB7 = 0;
PORTBbits.RB6 = 0;
PORTBbits.RB5 = 0;
PORTBbits.RB4 = 1;
Delay(3000);
}


}
} adc.png
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top