temperature printing problem

I got only flow meter printings, but my temperatures are not printing together. the temperature only works when I put “*/” to isolate flow code.

int analogPin0 = 0; // lm35 está ligado a entrada analogica 0
int analogPin1 = 1;
int analogPin2 = 2;
int analogPin3 = 3;
int valAnalog0, valAnalog1, valAnalog2, valAnalog3 ; // variavel para armazenar o valor analogico lido
float T0, T1, T2, T3;
int tmp0, tmp1, tmp2, tmp3;
volatile int frequencia1;
volatile int frequencia2;   //measuring the rising edges of the signal
float Q1, Q2;                               
int fluxo1 = 2;    //The pin location of the sensor
int fluxo2 = 3;


void Hz1 ()     //This is the function that the interupt calls
{ 
  frequencia1++;  //This function measures the rising and falling edge of the hall effect sensors signal
} 
void Hz2 ()
{ 
  frequencia2++;  //This function measures the rising and falling edge of the hall effect sensors signal
} 
void setup()
{
Serial.begin(9600); // programa a serial para comunicação em 9600 bps
analogReference(INTERNAL); // passando de 5,0V para1 1,1V o sistema pra aumentar a resolução
pinMode(fluxo1, INPUT); //initializes digital pin 2 as an input
pinMode(fluxo2, INPUT);
attachInterrupt(0, Hz1, RISING); //and the interrupt is attached
attachInterrupt(1, Hz2, RISING);
}


void loop()
{
 tmp0 = 0; 
 for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
 valAnalog0 = analogRead(analogPin0); // Le o pino de entrada analogica 0
 tmp0 = tmp0 + valAnalog0;
 }
 tmp1=0; 
 for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
 valAnalog1 = analogRead(analogPin1); // Le o pino de entrada analogica 0
 tmp1 = tmp1 + valAnalog1;
 }
 tmp2=0;
 for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
 valAnalog2 = analogRead(analogPin2); // Le o pino de entrada analogica 0
 tmp2 = tmp2 + valAnalog2;
 }
 tmp3=0;
 for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
 valAnalog3 = analogRead(analogPin3); // Le o pino de entrada analogica 0
 tmp3 = tmp3 + valAnalog3;
 }

T0= (( 1.1 * tmp0 * 100.00) / 1024) / 10 ; // better to change readings to 2, 3, 5, 10, 15..
T1= (( 1.1 * tmp1 * 100.00) / 1024) / 10;
T2= (( 1.1 * tmp2 * 100.00) / 1024) / 10;
T3= (( 1.1 * tmp3 * 100.00) / 1024) / 10;

 frequencia1 = 0;	//Set frequencia1 to 0 ready for calculations
  EIMSK = 3;		//Enables interrupts
  delay (3000);	        //Wait 3 seconds
  EIMSK = 0;		//Disable interrupts
  Q1 = -7.0295319E-03 + 3.92917841E-02*frequencia1; // this equation have been linearized on that conditions: 3000ms acquisition time, (0,4 - 12,0)L/min. range, horizontal position sensor. fluid water. temp. 21C.
  if (Q1<0)  {
    Q1=0;
  }

  frequencia2 = 0;	//Set frequencia2 to 0 ready for calculations
  EIMSK = 3;		//Enables interrupts
  delay (3000);	        //Wait 3 seconds
  EIMSK = 0;		//Disable interrupts
  Q2 = -7.02295319E-03 + 3.92917841E-02*frequencia2;
  if (Q2<0){
    Q2=0;
  }

Serial.print ("Qh= ");
Serial.print (Q1, 3); //Prints the number calculated above
Serial.print (" [L/min.]   "); //Prints "L/min." 
Serial.print ("Qc= ");
Serial.print (Q2, 3); //Prints the number calculated above
Serial.print (" [L/min.]        "); 
Serial.print("Thi= ");
Serial.print(T0,3); // Envia os dados pela porta serial
Serial.print(" [C]    ");
Serial.print("Tho= ");
Serial.print(T2,3); // Envia os dados pela porta serial
Serial.print(" [C]        ");
Serial.print("Tci= ");
Serial.print(T3,3);
Serial.print(" [C]   ");
Serial.print("Tco= ");
Serial.print(T1,3);
Serial.println(" [C]    ");






delay(500);


}

is there any interrupt problems to solve?

I am not familiar with the use of EIMSK but is there any reason why you don't just use the interrupts()/nointerrupts() or cli()/sei() functions ?

Tom Carpenter

Re: joining 2 codes together
« Reply #3 on: May 29, 2013, 12:01:47 pm »
Bigger Smaller Reset Quote
Assuming you are using an Atmega328, try replacing:

sei() with
Code:
EIMSK = 3;

and

cli() with
Code:
EIMSK = 0;

That way you only disable the external interrupts, rather than the all of the other many interrupts like those used for delay() and Serial.print()

I did not undestand

how do I can handle 2 different interrupts?

Why did you start a new thread when there was already one dealing with your questions ?

I don’t want bring to life old topics

But then you had to refer back to it anyway.

As to your printing problem, pardon me if this is a stupid question, but are the temperature values simply too far to the right in the serial monitor window to be seen ?

hi KELI, I don't know how far to the right you refer, but it could be another problem. By the way, I will post a picture right below. I think my thermistors got crazy or I have broken them. Do you have an idea about that responses differences?

I was said by TonHadron, that changing my analog variable declaration to A0, A1,... that could solve the problem and that was right

So the temperatures are printing after all now that we can see the righthand side of the Serial monitor window.
What is it that you think is wrong with the output ?

UKHeliBob:
So the temperatures are printing after all now that we can see the righthand side of the Serial monitor window.
What is it that you think is wrong with the output ?

theoretically, the temperatures should be the same (Tamb.) when I have an empty system, but I notice Tci > Tco > Thi > Tho . The major difference is something like 1.5 C between Tci and Tho.
If I can not fix it, I have to explain what that difference means about. Can my cable lengths affects it all, cable crossings or just being near? I have welded a plug into the edge of the wires connecting the thermistors.

Before installing the sensors, I have tested the thermistors Fig(a) then, I picked up a brass fitting and I have made a hole in it. I put the thermistor inside (with pins out) and closed the hole with epoxi resin.

So, I haven't figure out why the temperature sensor is showing 1.5C variation when manufacturer's accuracy graph says 0,5C variation in 0 - 100C range.

Try temporarily swapping the pins used to read the temperatures and running the program. Do the temperatures reported still follow the same pattern ?