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.

problem in ADC - help needed

Status
Not open for further replies.

ala aude

Newbie level 4
Joined
Dec 27, 2009
Messages
7
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
palastain
Activity points
1,329
problem in ADC

please can anyone help me un this code
// #pragma org all
void Tone1() {
Sound_Play(659, 250); // Frequency = 659Hz, duration = 250ms
}

void Tone2() {
Sound_Play(698, 250); // Frequency = 698Hz, duration = 250ms
}

void Tone3() {
Sound_Play(784, 250); // Frequency = 784Hz, duration = 250ms
}

void main ()org 0x800 {
unsigned y;
float x;
ADCON0=0b00000001;
ADCON1=0b00001101;

ADCON2=0b00000010;
TRISA = 0xff ;
TRISB = 0x00 ;
y=0;

for(;;){

y = adc_read(0) ;
// ADCON0=0b00000011;
x= ((y*1000*2.5)/9.8);\\convert to distance
ADCON0=0b00000001;
if (1<=x && x<30){
Sound_Init(&PORTB, 0);

//PORTB=0b00000001;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=0;
// delay_us(500);
//ADCON0=0b00000001;
}
else if(30<=x && x<80){
Sound_Init(&PORTB, 1);
Tone1();
//PORTB=0b00000010;
// PORTB.f0=0;
// PORTB.f1=1;
// PORTB.f2=0;
//delay_us(500);
// ADCON0=0b00000001;*/
}
else if(80<=x &&x<=120){
Sound_Init(&PORTB, 2);
Tone2();
//PORTB=0b00000100;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000100;
}
else {
Sound_Init(&PORTB, 3);
Tone3();
//PORTB.f0=1;
// PORTB.f1=1;
//PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000001;
}
}}
i used LV-MAXSONAR-EZ1 sensor and the if statment didint work in correct way and i want to convert the analog input to cm distance then test if statment i use pic18f2553 with 20Mhz
 

Re: problem in ADC

if (1<=x && x<30)

This wont work as expected, you need brackets.

if ((1 <= x) && (x < 30))
 

Re: problem in ADC

thx for your rep but the real problem is in the x=(y*1000*2.5)/(9.8);its take time bigger than the ADC reading because this i have always take the faild result
????idont know how to resolve this problem
the sensor give me 9.8 mV for evrey 1 inch,and when i use a tone this problem apear again. can you help me plz to solve his problem?!!!
 

Re: problem in ADC

can anyone help me in this problem please?
or if its correct way??!!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top