#include #include "lcd.h" #include "delay.h" float CDEG, FDEG, XIN,Y, DKEL; float XIN7 = 297.7, XIN6 = 297.7, XIN5 = 297.7; float XIN4 = 297.7, XIN3 = 297.7, XIN2 = 297.7, XIN1 = 297.7; // Past values of the filter are initalized for deg C = 24.5 (corresponds to 297.7 // filter value), as a nominal starting temperature. This number comes about by the expression: // deg K = deg C + 273.2 or (24.5 + 273.2) = 297.7. After the filter has gone through // 8 iterations (4 for 4th order) for these values, plus another for the actual current deg C, the reading // will be fairly settled to the actual temperature. wlg const float A = 0.613, B = 0.2; // note that A has been changed from 0.0613 to 0.613 void main(void) { // clock config WDTCTL = WDTPW + WDTHOLD; // Stop WDT // set up Basic Timer IE2 |= BTIE; // Enable BT interrupt BTCTL = BT_ADLY_2000 | BT_fLCD_DIV256; // 128 Hz LCD, 2s Interrupt // set up ADC ADC12IE |= 0x0040; // Enable ADC6 interrupt ADC12CTL0 = ADC12ON + REF2_5V + REFON; // Aref = 2.5V, Aref on ADC12CTL1 = CSTARTADD_6 + ADC12SSEL_1 + SHP; // ADCCLK = ACLK, pulse mode; ADC12MCTL6 = SREF_1 + INCH_6; // Select sixth reg, Aref on, Aref = Vref+,Avss ADC12CTL0 |= ENC ; //set port pins //set P6.6/A6 as input P6SEL |= BIT6; //select adc function //call lcd func setupLCD(); // Enable interrupts and go to sleep forever _EINT(); // Enable interrupts // _BIS_SR(LPM3_bits); // Enter LPM4 while(1); // NOP } // Basic Timer interrupt service routine interrupt[BASICTIMER_VECTOR] void basic_timer(void) { ADC12CTL0 |= ADC12SC; // start conversion } // ADC interrupt service routine interrupt[ADC_VECTOR] void adc(void) { // ****************************************** // ****************************************** // The following code combines code writen by // Matt Mahin of UNF to get display output for the // AD590 Analog Device temperature sensor. // This code will work for deg F up to 199. For // deg F of 200 and greater, modifications need to // be made on handling the display. A separate lcd // file is developed for this case: It is; senhi.c // Prepared by W. L. Green ECE Department, University // of Tennessee; April, 2006 XIN = A*B*ADC12MEM6; // The sensor signal is brought in on the A to D // converter at ADC12MEM6; // A is a scale factor (0.163) that takes the input from the A/D // and produces a number on the display that corresponds to the // input to the A/D. // B is a scale factor the is the recipal of the gain of the op amp // used to raise the sensor output voltage. In my case an op amp gain // of 5 was used. Therefore, B = 0.2. // Filter the signal with a 4th order moving average // filter. DKEL = (XIN + XIN1 + XIN2 + XIN3)*0.25; // DKEL is deg Kelvin XIN3 = XIN2; // Update the coefficients of the filter XIN2 = XIN1; XIN1 = XIN; CDEG = (DKEL - 273.2); // converting from Kelvin to deg C // In this case DKEL is the sensor reading // in deg K. FDEG = 1.8*CDEG + 32.0; // converting from deg C to deg F lcd_word(100*CDEG, 2); // the l00 causes the first 3 digits of CDEG // to be displayed. The 2 causes a decimal // to be placed to the left of the second display // slot. //lcd_char(1,' '); // The 1 corresponds to the second position from // the right on the display. The ' ' places a // space in this position. Take out if you want // a number in this position. Play with it and see what // happens. lcd_char(0,'C'); // The 0 corresponds to the first position on the // right side of the display. The 'C' causes a C // to be displayed in this position wait_ms(2000); // Waits 2000 milliseconds then displays deg F lcd_word(100*FDEG, 2); // The l00 causes the first 3 digits of FDEG to be displayed. // The 2 moves the decimal to the left of the 2nd position. //lcd_char(1,' '); // See the above statement lcd_char(0, 'F'); // See the above statement wait_ms(2000); // Wait 2000 milliseconds. The program then moves // back to lcd_word(100*CDEG, 0) and continues as a loop }