Hi, I'm very new to this and I'm liking it very much! I have a problem with the analog readings though. I connected a battery (1.5v) to ground and analog input 0. The value it reads is 368 (~1.8V). I tested the battery and the most precise value I get is 1.58 V (from a calibrated tester). Is this normal? such a big discrepancy? The code is as simple as it gets so that can't be it. I have a duemilanove with atmega 328p. This is the code anyhow:
int valor;
void setup(){
Serial.begin(9600);
}
void loop(){
valor=analogRead(0);
Serial.println(valor,DEC);
delay(1000);
}
The other problem I've been having is with two ISR interrupts (in another application). The part of the code that handles the interrupts is this:
void fotoPuerta(int puertos) {
pinMode(2, INPUT); //Poner los digitales como input
pinMode(3, INPUT);
EICRA = B00001111;
switch(puertos) //Selecciona cuales se van a medir
{
case 1:
EIMSK |= B00000001; //Activa Interrupcion en puerto 2.
break;
case 2:
EIMSK |= B00000010; //Activa Interrupcion en puerto 3.
break;
case 3:
EIMSK |= B00000011; //Activa Interrupcion en ambos.
break;
}
delay(1000);
//Serial write loop para los valores
do {
if (k<=(i-1) && k<=150){
mandarFoto1(ValTiempo0[k]);
k++;
if(k==i){
k=0;
i=0;
}
if (l<=(j-1) && l<=150){
mandarFoto2(ValTiempo1[l]);
l++;
if(l==j){
l=0;
j=0;
}
}
}
}
while(parar==0);
EIMSK =0; //Detiene las interrupciones
parar=0;
}
//////////// Funciones para las interrupciones ////////
ISR(INT0_vect){
ValTiempo0[i++]=micros();
}
ISR(INT1_vect){
ValTiempo1[j++]=micros();
}
The problem is that it messes up my analog meassures (not in this code) when I use both interrupt functions (with one it doesn't seem to be a problem, so it is very strange). It sends all of the adc to 1023.
I should say I've tried both situations with two different boards. Don't really know what is happening so if someone could please help me it would be great. Thanks. ![]()