circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Issue 163 February 2004
The Growth of the Atmel AVR Family



THERMISTOR

A negative temperature coefficient (NTC) thermistor is used as the lower leg of a voltage divider with a 10-kW resistor to VREF. Because the thermistor has a 10-kW resistance at 25°C, the voltage at the junction of the two devices (and the input to an A/D channel) will be 0.5 VREF at room temperature. The thermistor’s equation for temperature is:

where b is 3450, VREF is 1.263 V, TZERO is 273°K, TAMB is 298°K (273° + 25°), and VADC is the analog-to-digital conversion voltage.

To allow this project to proceed without some serious calculation routines, I used my trusty Radio Shack scientific calculator to solve for the VADC values for all the Fahrenheit temperatures between 40° and 99°F. The VADC values were then converted to the 8-bit conversion equivalents and stored in a look-up table.

The ADC is initialized for continuous single ended conversions of channel 0 using a division factor of 32 on the system clock. The ADC actually does a 10-bit measurement conversion and stores the value either left or right justified into a 16-bit extended I/O register. By using left justification, the high byte of the conversion is the high 8 bits of a 10-bit conversion (or an 8-bit conversion value). Eight of these conversions are added together, and the total is shifted right 3 bits to divide the total by eight and end up with an average. A low conversion value of 99 corresponds (coincidentally) to a high temperature of 99°F. A high conversion value of 180 corresponds to a low temperature of 40°F.

To find the actual temperature, the conversion average is compared to the first value in the TEMP_TABLE (with the first entry 180 = 40°F). If the table entry is greater than the conversion average, then the temperature variable, which is initialized to 40, is incremented and the next table value is grabbed and the comparison repeats until the TEMP_TABLE entry value is less than or equal to the conversion average. The temperature variable has now incremented to the temperature in degrees Fahrenheit that corresponds to the appropriate average A/D conversion value. To stay compatible with the thermostat conversion protocol that I discussed last month (“Global XPortation,” Circuit Cellar 162), the temperature is finally converted into two ASCII digits as TEMPH and TEMPL. You’ll notice that all variables are stored as ASCII values to remain compatible with the protocol. 

BUTTONS

Five user inputs provide local mode changes to the thermostat. The first button, Mode, increments the MODE variable through four possibilities: H, C, A, and O. Heat places the thermostat in Heat mode and asks the furnace for heat if the temperature falls below the heat set point by setting the HVACSTATUS to “H” (heating). HVACSTATUS returns to “I” (idle) when the temperature rises to heat set point + 4°F (an arbitrary delta I added here, but is not present in the virtual thermostat).

Cool places the thermostat in to Cool mode and asks the air conditioner for cool if the temperature rises above the cool set point by setting the HVACSTATUS to “C” (cooling). HVACSTATUS returns to “I” when the temperature falls to cool set point – 4°F (an arbitrary delta).

Auto places the thermostat into both Heat and Cool modes (i.e., it can call for heating or cooling as necessary). Obviously, if the heat set point and cool set point are too close, the systems will fight. Although this wasn’t implemented in the virtual thermostat, it is prevented here in the Change_Plus and Change_Minus routines by comparing the heat and cool set points. They are automatically adjusted to keep a two times delta distance between them. Off, or disable mode, shuts down the call for heat/cool operation by setting HVACSTATUS to “O.”

The second button, Fan, sets the FAN variable to either a one (on) or a zero (auto). The one value forces the furnace/air conditioner fan on; the zero value allows the furnace/air conditioner to determine the state of the fan based on its own criteria.

The third button, Set point, allows you to change the heat and cool set points. This button sets the display mode to one of three values: 0x00, 0x01, and 0x02. A display mode value of 0x00 indicates the LCD should display the actual temperature. A value of 0x01 indicates the LCD should display the heat set point. A value of 0x02 displays the cool set point.

After the heat set point or cool set point has been selected, the fourth button increments the set point by one. The fifth button decrements the set point by one.