Other Parts Discussed in Thread: ENERGIA
Tool/software: TI C/C++ Compiler
Hi!
I am hoping to convert part of an Energia example into entirely C code for use in CCS (ADC examples should be included) to get external thermistor readings with the MSP430F5529 Launchpad. I don't have much experience in using C, but I need to know what should be added/changed to get the thermistor readings. Can anyone help me with this?
Here's the code from the example:
void setup()
{
// initialize serial communication over UART at 9600 baud
Serial.begin(9600);
}
void loop()
{
// >>> Thermistor Section <<<
// take in analog data from thermistor and run it through formulas
// and conversions
float ThermistorVal = analogRead(2);
float ThermistorTempC;
float ThermistorTempF;
ThermistorTempC = logf(10000.0 * ((1024.0 / ThermistorVal - 1)));
// = logf(10000.0 / (1024.0 / ThermistorVal - 1)); // for pull-up configuration
ThermistorTempC = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * ThermistorTempC
* ThermistorTempC ))* ThermistorTempC );
ThermistorTempC = ThermistorTempC - 273.15; // Convert Kelvin to Celcius
ThermistorTempF = (ThermistorTempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.print("Thermistor: ");
Serial.print("vin=");
Serial.print(ThermistorVal);
Serial.print(" ");
Serial.print("TempC=");
Serial.print(ThermistorTempC);
Serial.print(" ");
Serial.print("TempF=");
Serial.print(ThermistorTempF);
Serial.println();
}
Here's what I have so far in the conversion (some Energia code remains):
#include <msp430.h>
/*
* main.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
{
Serial.begin(9600);
}
while()
{
float ThermistorVal = analogRead(2);
float ThermistorTempC;
float ThermistorTempF;
ThermistorTempC = logf(10000.0 * ((1024.0 / ThermistorVal - 1)));
// = logf(10000.0 / (1024.0 / ThermistorVal - 1)); // for pull-up configuration
ThermistorTempC = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * ThermistorTempC
* ThermistorTempC ))* ThermistorTempC );
ThermistorTempC = ThermistorTempC - 273.15; // Convert Kelvin to Celcius
ThermistorTempF = (ThermistorTempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
printf("Thermistor: ");
printf("vin=");
printf(ThermistorVal);
printf(" ");
printf("TempC=");
printf(ThermistorTempC);
printf(" ");
printf("TempF=");
printf(ThermistorTempF);
printf();
return 0;
}