Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Questions about the MSP430 Tempsensor

$
0
0

I am writing a program that is supposed to read the temperature from the MSP430's internal sensor, then display it through the LED's by making the red one blink the 10's digit and the green one blink the 1's digit. Pushing the button should toggle between Farenheit and Celcius, default Fahrenheit. 

 

My question is about the output of the analogRead(TEMPSENSOR) function. I know that the output of the function is an int between 0 and 1023 that maps to a range of 0 to 3 volts. What I don't understand is how that output translates to a temperature.

 

I tested the function by just printing the output of analogRead(TEMPSENSOR) to see what reading it put out, and it fluctuated between 511 and 512 (translating to 1.4819 to 1.4848 volts). 

 

Any help or insight would be much appreciated.

 

Code I have written so far:

void setup()
{
  Serial.begin(9600);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(TEMPSENSOR, INPUT);
  pinMode(PUSH2, INPUT_PULLUP);
  
}

void loop()
{
  int Temperature, Units, Tens, t
  
  int Reading = analogRead(TEMPSENSOR);
  
  digitalWrite(GREEN_LED, LOW);
  digitalWrite(RED_LED, LOW);
    
  Serial.println(Reading);
  delay(500);
  
  Temperature = Reading          //Convert the tempsensor reading to a temperature in Fahrenheit 
  
  if (buttonState == LOW)                 
  {
    Temperature = (5/9)(Temperature-32);
  }

  Units = Temperature%10
  Tens = (Temperature-Units)/10
  
  for(t=0, t<Tens, t++)
  {
    digitalWrite(RED_LED, HIGH);
    delay (250);
    digitalWrite(RED_LED, LOW);
    delay(250);  
  }
  delay(5000);
  
  for(t=0, t<Units, t++)
  {
    digitalWrite(GREEN_LED, HIGH);
    delay (250);
    digitalWrite(GREEN_LED, LOW);
    delay(250);  
  }
  delay(5000);
}

Obviously it won't work right now as "Reading" hasn't been converted to "Temperature" yet.

 

Thanks again for any help!


Viewing all articles
Browse latest Browse all 2077

Trending Articles