Go Down

Topic: temperature sensor problem (Read 813 times) previous topic - next topic

haha54321

I have an ekg running and displaying on a lcd using an arduino mega. Whenever I add a temperature sensor reading code, the ekg wont run anymore. I am not sure why. It doesn't seem like a temp sensor is taxing on the processing.
I am using LM61 temp sensor from TI.



this is the flow of the code. (whenever I take temp reading out, the ekg works correctly)
int tempsensorPin = 8;
void setup()
void loop (

int reading = analogRead(tempsensorPin);
float temp = (((reading * 5.0)-.6)*100)/1024;

for loop
(ekg reading and plotting)
)

Arrch

#1
Nov 26, 2012, 04:39 am Last Edit: Nov 26, 2012, 04:44 am by Arrch Reason: 1

It doesn't seem like a temp sensor is taxing on the processing.

The temp sensor is not, but floating point calculations are.

Without seeing all of your code and more information on your set-up, it's tough to say if that is the problem. I would try changing your temp calculation to int math and seeing if that affects it.

haha54321

#2
Nov 26, 2012, 05:00 am Last Edit: Nov 26, 2012, 05:02 am by haha54321 Reason: 1
I tried changing it to int, but it did not work.

This is the loop where I draw the ekg and update temp.


Code: [Select]


unsigned int weiterverarbeitung(volatile unsigned char high_byte, volatile unsigned char low_byte)
{
unsigned int value = ((high_byte&0x0f)*256)+(low_byte);

return(value);
   
}


unsigned long Start, Finished = 0;
float heart_rate = 0;
float RR_interval = 0;
unsigned int Delay = 9;
int thisdot = 0;
int prevdot = 0;





void loop() {

// this is the temp code that messes the ekg reading

int reading = analogRead(tempsensorPin);  //pin assigned earlier
int temp = (((reading * 5)-.6)*100)/1024;
GLCD.print(temp);

 for(int l=0; l<GLCD.Width; l++)
 {
   
   Finished = 0;
   unsigned int val = weiterverarbeitung(TXBuf[4],TXBuf[5]);  //extracting channel bytes
   unsigned int y = map (val, 0, 1023,200,0)-50;      //scaled
   thisdot = y;

   int slope = prevdot - thisdot;

   
   // Writes hear rate if slope is greater than 3
   if (slope >= 3 && Start == 0)
     {Start = millis();}
     else if(slope >= 3 && Start > 0)
   {Finished = millis();
       RR_interval = Finished - Start;        
     if(RR_interval>=150)  //refractory period
       {RR_interval = RR_interval/1000;  //convert to seconds
         heart_rate = 60/RR_interval;}
         
     Start = 0;
     
   }
     if(heart_rate<220)
             {GLCD.CursorToXY(0, 4);
             GLCD.SelectFont(Wendy3x5);
             GLCD.print("HEART RATE");
             GLCD.CursorToXY(5, 15);
             GLCD.SelectFont(System5x7);
             GLCD.print(heart_rate);
             
           }
   
   
   //Draw graph  
   GLCD.SetDot(l,y,BLACK);
   delay(Delay);
   
   prevdot = thisdot;
   thisdot = 0;
   slope = 0;
 }
GLCD.ClearScreen();

}

patduino

Hi haha,

I'm not sure which GLCD you are using, or if it is on a shield, but make sure that it doesn't use the same pin you are using for the temp sensor.  Just a thought...
There are 10 types of people in the world, those that understand binary, and those that don't.

Arrch


I tried changing it to int, but it did not work.

So you made a change but aren't posting the updated code so that we can make sure you're doing it correctly?

haha54321

I changed the calculation from:

int reading = analogRead(tempsensorPin);
float temp = (((reading * 5.0)-.6)*100)/1024;

to:

int reading = analogRead(tempsensorPin);  //pin assigned earlier
int temp = (((reading * 5)-.6)*100)/1024;
______-
I am using analog input 8 on a mega. it is not occupied or being used in the code.
What confuses me is that the temp reading is taken before the for loop, before the plotting of the ekg data, so it shouldnt have any effect on the graphing.

haha54321

I figure out how to make the graph show again. Somehow the temp sensor reading is causing interference and I had to change the mapping so that it shows on the lcd. Now the signal is just a constant sine like wave...

Go Up