Exemple #1
0
main()
{
	auto float 	Tc,		//temperature celcius
					Tk,		//calculated temperature kelvins
					Tkstd,	//standard temperature kelvins
					Tf,		//temperature farenheit
				 	Bt,		//given thermistor beta			// B=(-alpha*T^2)  ???
					Rs,		//given series resistor
					Rtstd,	//given thermistor resistance at standard temperature
					Draw,		//raw data value
					Gain,		//gain
					Dmax;		//max raw data value

	brdInit();

	//assign variables as float values for calculation
	Tc = 25.0;						//standard temp in Celcius
	Tkstd = Tc + 273.15;  		//convert to Kelvins
	Bt = 3965.0;					//thermistor beta
	Rs = 1000.0;					//series resistor
	Rtstd = 3000.0;				//standard temp resistance
	Dmax = 2047.0;					//max value on ADS7870
	Gain = 1.0;						//actual gain multiplier

	while(1)
	{
		//first-time call of this function will take 1 second to charge up cap
		//use single-ended and gain of 1
		do {
			sDelay(1);
		 	Draw = anaIn(7, SINGLE, GAIN_1);
		} while(Draw == 0);

		//calculate temperature in kelvins
		Tk = (Bt * Tkstd) /
			(Tkstd * (log(fabs((-Draw * Rs) /
			(Rtstd * (Draw - (Dmax * Gain)))))) + Bt);

		Tc = Tk - 273.15;				//convert to celcius
		Tf = 1.8*(Tk - 255.37);		//calculate fahrenheit

		printf("Temperature at %.2f C (%.2f F) from data %d\n", Tc, Tf,(int)Draw);
	}
}
Exemple #2
0
/*
 * Long delay
 */
void lDelay(void) {
  unsigned char i;
  for (i = 0; i < 100; i++) {
    sDelay();
  }
}