Pages: [1]   Go Down
Author Topic: problem with simultan analog reading  (Read 523 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!
when i read 2 analog inputs simultaneous (i tried with delay up to 0.1s), the measured value jumps around with a difference of +/- 0.1 V.
With just one analog read I get nice and constant values.

How can i Read more than one analog Inputs without getting jumping values?

Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12579
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when i read 2 analog inputs simultaneous

Do you mean consecutively? It's not possible to perform two analog reads simultaneously.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sure ... you're right.
my code:

// Tempmessung mit LM35

int val_LM35 = 0;
int u_LM35 = 0;
float LM35_temp = 0;

// Temperaturmessung mit Wasser-NTC

int val_NTC = 0; // Eingangswert
int u_NTC = 0;   // Spannung
float NTC_temp = 0; // Temperatur

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
}

void loop()
{
// Vergleichstemperatur mit LM35 messen...
  val_LM35 = analogRead(0);
  u_LM35 = val_LM35*5000.0/1024;
  LM35_temp = u_LM35/10 ;
  Serial.print("Temp: ");
  Serial.println(LM35_temp);
 
// Temperatur mit NTC messen
val_NTC = analogRead(2);
u_NTC = val_NTC*5.0/1024;

NTC_temp   =  +   0.2514 *pow(u_NTC, 6)   // Formel mit excel erstellt
              -   3.7812 *pow(u_NTC, 5)   // Fehlerdiagnose sieht excel-file
              +  22.4840 *pow(u_NTC, 4)
              -  70.0990 *pow(u_NTC, 3)
              + 133.2200 *pow(u_NTC, 2)
              - 196.9600 *    u_NTC
              + 275.8900 ;
         
// int NTC_temp = NTC_temp;   //Für Ausgabe ohne Komma

Serial.print("NTC_temp: ");
Serial.println(NTC_temp);
Serial.println(" C");
Serial.println("");


delay(1000);
}



Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this
Code:
// Tempmessung mit LM35

int val_LM35 = 0;
int u_LM35 = 0;
float LM35_temp = 0;

// Temperaturmessung mit Wasser-NTC

int val_NTC = 0; // Eingangswert
int u_NTC = 0;   // Spannung
float NTC_temp = 0; // Temperatur

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
}

void loop()
{
// Vergleichstemperatur mit LM35 messen...
  (void) analogRead(0);
  val_LM35 = analogRead(0);
  u_LM35 = val_LM35*5000.0/1024;
  LM35_temp = u_LM35/10 ;
  Serial.print("Temp: ");
  Serial.println(LM35_temp);
 
// Temperatur mit NTC messen
(void)analogRead(2);
val_NTC = analogRead(2);
u_NTC = val_NTC*5.0/1024;

NTC_temp   =  +   0.2514 *pow(u_NTC, 6)   // Formel mit excel erstellt
              -   3.7812 *pow(u_NTC, 5)   // Fehlerdiagnose sieht excel-file
              +  22.4840 *pow(u_NTC, 4)
              -  70.0990 *pow(u_NTC, 3)
              + 133.2200 *pow(u_NTC, 2)
              - 196.9600 *    u_NTC
              + 275.8900 ;
         
// int NTC_temp = NTC_temp;   //Für Ausgabe ohne Komma

Serial.print("NTC_temp: ");
Serial.println(NTC_temp);
Serial.println(" C");
Serial.println("");


delay(1000);
}
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
val_LM35 = analogRead(0);
  u_LM35 = val_LM35*5000.0/1024;
  LM35_temp = u_LM35/10 ;
  Serial.print("Temp: ");
  Serial.println(LM35_temp);
 
// Temperatur mit NTC messen
val_NTC = analogRead(2);

If you really care about "reading them simultaneously", put those two reads next to each other so they are done closely.

And try to minimize the use of floating point math.
Logged

USA
Offline Offline
Sr. Member
****
Karma: 13
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you meant to say
Code:
float u_NTC = 0;   // Spannung

This calculation
Code:
int u_NTC = 0;   // Spannung
...
val_NTC = analogRead(2);
u_NTC = val_NTC*5.0/1024;
will yield only the values 0,1,2,3 and 4 for u_NTC, with u_NTC declared as int
Logged

Pages: [1]   Go Up
Jump to: