icefire91
Newbie level 6
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);
}
}
}
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);
}
}
}