Pages: [1]   Go Down
Author Topic: temperature sensor problem  (Read 496 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
)
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 25, 2012, 10:44:59 pm by Arrch » Logged

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

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

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


Code:

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();
 
}
« Last Edit: November 25, 2012, 11:02:32 pm by haha54321 » Logged

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

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.
Logged

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

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...
Logged

Pages: [1]   Go Up
Jump to: