6 posts / 0 new
Author
Message

Hello, I need to use 2 ADC inputs, but when I see the Serial monitor, The value of the ADC0 is represented in the variable of the ADC1.

void casos(){

g++;

switch(g) {

case 1:

char string1[8];

itoa(Temperatura_Serial, string1, 10);  //convert integer to string, radix=10

break;

case 2:

char string2[8];

condiciones();

break;

g=0;

}
}

I have this routine, but the ADC1 is not working. Any solution?

You never wait for the ADC to finish! You need to poll the ADSC bit to see when the adc has finished.

Kartman wrote:
You never wait for the ADC to finish! You need to poll the ADSC bit to see when the adc has finished.

case 2:

{

char string2[8];

condiciones();
}

break;

Is it correct?

Kartman wrote:
You never wait for the ADC to finish! You need to poll the ADSC bit to see when the adc has finished.

Or this?

void casos(){

g++;

switch(g) {

case 1:

{

char string1[8];

itoa(Temperatura_Serial, string1, 10);  //convert integer to string, radix=10
}

break;

case 2:

{

char string2[8];

condiciones();

}

break;

g=0;

}
}

You can keep on guessing or you can Google the solution in 10 seconds.

Here's what I found:

{
// select the corresponding channel 0~7
// ANDing with ’7′ will always keep the value
// of ‘ch’ between 0 and 7
ch &= 0b00000111;  // AND operation with 7
ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing

// start single convertion

// wait for conversion to complete
// till then, run loop continuously

}

Kartman wrote:

You can keep on guessing or you can Google the solution in 10 seconds.

Here's what I found:

{
// select the corresponding channel 0~7
// ANDing with ’7′ will always keep the value
// of ‘ch’ between 0 and 7
ch &= 0b00000111;  // AND operation with 7
ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing

// start single convertion

// wait for conversion to complete