emcs design documentation - ese381

22

Upload: saket-ati

Post on 14-Apr-2017

139 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EMCS Design Documentation - ESE381

Page 2: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 1

Contents What is it?…………………………………………………………………………….. 2 In the box …………………………………………………………………………….. 2 Features …………………………………………………………………………….. 2 Top Level Design……………………………………………………………………. 3 Modular Software……………………………………………………………………. 4 Local Operation Mode FSM …………………………………………………… 5 Remote Operation Mode FSM …………………………………………………… 8 Keypad …………………………………………………………………………….. 11 EAR DOG Module LCD ……………………………………………………………. 13 Honeywell HumidIcon Temperature and Humidity Sensor …………………. 14 Pressure Sensor …………………………………………………………………….. 16 MAX1270 Analog­to­Digital Converter …………………………………………… 17 XBee Wireless Module ……………………………………………………………. 19 Troubleshooting …………………………………………………………………….. 21 Contact Information ……………………………………………………………. 21

Page 3: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 2

Welcome to your SAAT system

What is it? This system is an Environmental Monitoring and Control System (EMCS) that can

monitor the temperature, humidity and pressure of the room as well as adjust the temperature and humidity to a set level. Our system has two different operation modes: local mode and remote mode. In local mode, the measurands can be displayed on an LCD screen built into the system and the setpoints for temperature and humidity can be modified using the keypad. In remote mode, the same operations can be executed over the internet remotely from any internet capable device. This is the biggest advantage of the system.

In the box Environmental Monitoring and Control System (EMCS) unit Power adapter (9V output) Control signals connector for AC, Furnace, Humidifier and Dehumidifier

Features Read the temperature Read the humidity Read the pressure Set the temperature to control the AC or Furnace Set the humidity to control the humidifier or dehumidifier In­built wifi unit to perform all operations remotely from any internet connected device Optional 9V battery connector for ease of use

Page 4: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 3

Top Level Design The following are the components of the system: ­ EA DOGM163A LCD controller and driver ­ Honeywell HumidIcon Digital Temperature and Humidity Sensor ­ MPXHZ6130A Pressure Sensor ­ MAX1270 Analog­to­Digital Converter with SPI ­ 4x4 Keypad (Some keys are not used for the final design) ­ XBee Wireless Module ­ Control signals for AC, Furnace, Humidifier and Dehumidifier

Figure 1: Top level system block diagram

The system uses SPI to communicate with the sensors and the LCD display. RS232 communication protocol is used to send and receive data via the wireless module. The AVR240 design is used for the keypad interface to minimize hardware requirements. The system uses two separate finite state machines for local operation mode and remote operation mode. Both the state machines are described in detail below. The schematic of the ATmega128 is attached in the Appendix.

Page 5: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 4

Modular Software

Figure 2: Modular Program Interaction

The functionality of the EMCS built upon several modules of code that divide and group the tasks carried out by the system into manageable building blocks. The figure above depicts the primary functions the EMCS undertakes:

Background Tasks ­ involve measuring the current temperature, humidity, and pressure, and displaying them to the LCD. The measured values are also compared against the set point values set by the user to determine if system needs to turn on or off the AC, furnace, humidifier, and/or dehumidifier.

Finite State Machines ­ EMCS switches between two FSM depending on which mode the EMCS is currently operation in. Each mode is designed to expose the user to different I/O capabilities of the EMCS. Thus improving the versatility of system

Interrupt Driven ­ the interrupt service routines allow for the handling of I/O from the user through their use of the keypad, or a terminal when the EMCS is wireless mode.

The remote_op_emcs.c located in the appendix us driver program for the EMCS. The program interacts with the modules max1720.c and baro_pressure.c to communicate with the MAX1270 to retrieve the barometric pressure. The program interacts with humidicon_task2 and temp_humid_humidicon to communicate with the Humidicon to retrieve both temperature and relative humidity. The program is able to display characters on the LCD due to the interaction to lcd_etc. and log_dog_iar_driver.asm The USART2.c contains the ISR (interrupt service routine) which stores received characters in the receive buffer, and transmits characters in the transmit buffer out.

Page 6: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 5

Local Operation Mode FSM This Finite State Machine implements the operations of the EMCS in Local operation

mode. The keypad is used for user input and the LCD display is used for output. This system allows the user to change the setpoints for the temperature (ST) and the humidity (SH). The setpoints can be modified one of two ways; by pressing the up or down keys on the keypad, or by directly inputting the tens, units and decimal digits on the keypad, in that order. Following is a description of the states and functions of the local finite state machine.

Local FSM States:

Select_temp ­ This is the default state of this finite state machine. In this state, the cursor (#) is displayed next to the temperature setpoint on the display. This indicates that, the setpoint for the temperature can be modified by pressing the 2nd key on the keypad.

Select_hum ­ Displays the cursor (#) next to the humidity setpoint. This allows the user to modify the setpoint for humidity by pressing the 2nd key on the keypad.

Set_temp ­ This state allows to modify the setpoint for temperature. There are two ways of doing this. By using the up or down keys on the keypad, or by directly inputting the digits for the setpoint. This state advances based on the first input from the user. Using the up or down key modifies the measurand in 0.1 increments

Set_hum ­ This state allows to modify the setpoint for temperature. There are two ways of doing this. By using the up or down keys on the keypad, or by directly inputting the digits for the setpoint. This state advances based on the first input from the user. Using the up or down key modifies the measurand in 0.1 increments

Tens_T ­ Upon entering the first digit in set_temp state, tens_T waits for the next digit to be put in the units place.

Units_T ­ This state waits for decimal digit to be input on the keypad. Dec_T ­ This state waits for the Enter key to be pressed and then updates the

temperature setpoint of the EMCS and updates the display accordingly. Tens_H ­ Upon entering the first digit in set_hum state, tens_H waits for the next digit to

be put in the units place. Units_H ­ This state waits for decimal digit to be input on the keypad. Dec_H ­ This state waits for the Enter key to be pressed and then updates the humidity

setpoint of the EMCS and updates the display accordingly. Local FSM Functions:

move_cursor_hum ­ Set the variable boolean hashtag equal to 0. The main function then used this variable to display the cursor next to the humidity setpoint.

move_cursor_temp ­ Set the variable boolean hashtag equal to 1. The main function then used this variable to display the cursor next to the temperature setpoint.

increment_ST ­ Incremented the value of the temperature setpoint by 0.1 degrees. decrement_ST ­ Decremented the value of the temperature setpoint by 0.1 degrees. update_ST ­ Set the flag, entered, equal to 1, enabling the main program to update the

temperature setpoint displayed on the LCD display.

Page 7: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 6

increment_SH ­ Incremented the value of the humidity setpoint by 0.1%. decrement_SH ­ Decremented the value of the humidity setpoint by 0.1%. update_SH ­ Set the flag, entered, equal to 1, enabling the main program to update the

humidity setpoint displayed on the LCD display. process_digit ­ Depending on the current state of the state machine, this function used

the keycode value obtained from the keypad to change the respective digit of the temperature or humidity setpoints. It then updated the value of the global variables for the two setpoints.

do_nothing ­ This function does nothing in the state machine and simply prints “Do Nothing”. This function is used for testing and debugging the state machine.

Page 8: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 7

Figure 3: Local Operation Mode FSM state diagram

Page 9: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 8

Remote Operation Mode FSM This Finite State Machine implements the operations of the EMCS in Local operation

mode. The commands are transmitted and data is received through an XBee module using RS232 protocol. The following is the command set for the EMCS in remote operation mode: To set temperature: ST=dd.d To set humidity: SH=dd.d To read temperature: T Response is: T=dd.d To read humidity: H Response is: H=dd.d To read pressure: P Response is: P=dd.dd where d is a digit 0­9. Commands sent by the device cloud are wrapped by a Return Carriage char ‘/r’. Following is the description of the remote FSM: Remote FSM States:

display ­ Initial state of the system that waits for an incoming command to be executed. The input command is saved in a buffer to be able to be accessed later in the system.

send_temp ­ When the carriage return char ‘/r’ is received, this state returns the temperature and goes back to the initial state display.

send_pressure ­ When the carriage return char ‘/r’ is received, this state returns the pressure and goes back to the initial state display.

send_humidity ­ When the carriage return char ‘/r’ is received, this state returns the humidity and goes back to the initial state display.

process_second ­ If the first character received was an ‘S’, the following command must be modifying one of the setpoints. This state waits for the second character to determine if temperature setpoint or the humidity setpoint is to be modified.

wait_H ­ This state waits for an ‘=’ character. tens_H ­ This state indicates that the next character received is the tens digit of the

humidity setpoint. The present state variable is used by the process_digit function to determine what position the digit is in.

ones_H ­ This state indicates that the next character received is the units digit of the humidity setpoint.

dot_H ­ Waits for a decimal point to be entered after the units digit. stay_H ­ Waits for a valid digit to be entered for the decimal digit of humidity setpoint. decimal_H ­ Waits for a carriage return character to update the humidity setpoint and

return to the initial state of the system. wait_T ­ This state waits for an ‘=’ character.

Page 10: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 9

tens_T ­ This state indicates that the next character received is the tens digit of the temperature setpoint.

ones_T ­ This state indicates that the next character received is the units digit of the temperature setpoint.

dot_T ­ Waits for a decimal point to be entered after the units digit. stay_T ­ Waits for a valid digit to be entered for the decimal digit of temperature setpoint. decimal_T ­ Waits for a carriage return character to update the temperature setpoint and

return to the initial state of the system. Remote FSM Functions:

save_command ­ Saves the incoming character in a buffer to be accessed later. return_temp ­ Sends the temperature measurement out to the remote station in the

format: T=dd.d. return_pressure ­ Sends the pressure measurement out to the remote station in the

format: P=dd.dd. return_hum ­ Sends the humidity measurement out to the remote station in the format:

H=dd.d. process_digitR ­ Depending on the present state of the machine, this function used the

digit to update the respective digits of one of the setpoint values. send_SH ­ The new humidity setpoint is updated and displayed on the LCD screen on

the device. send_ST ­ The new temperature setpoint is updated and displayed on the LCD screen

on the device.

Page 11: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 10

Figure 4: Remote Operation Mode FSM state diagram

Page 12: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 11

Keypad A 4x4 keypad is used to get input from the user in local operation mode. The keypad is used to modify the setpoints for the temperature and humidity measurands. The AVR240 design is used to achieve keypad scanning using minimal hardware.

Figure 5: Keypad Scanning Design Courtesy: AVR240 application notes

In this design, the rows are connected to the lower nibble of Port C and the columns are connected to the higher nibble of Port C. Initially the pins of the higher nibble are set up as outputs writing a logic ‘0’. Pins of the lower nibble are set up as inputs with internal pull up resistors enabled. INT0 is enabled to trigger on a falling edge. When a key is pressed, the row and column of that key are connected together. This pulls down the logic on that pin to a logic ‘0’ calling the interrupt service routine. The service routine then scans through the lower nibble of Port C to determine the row of the pressed key. Then, the direction of the pins of Port C are swapped. The higher nibble of Port C is scanned to determine the column of the key pressed. The combination of this row and column number is assigned a specific key value. This key value is then used to look up a table for the keycode of the key that was pressed.

Page 13: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 12

Figure 6: Keypad Scanning ISR Flowchart

Courtesy: AVR240 application notes

Page 14: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 13

EAR DOG Module LCD The EAR DOG Module DOGM163W­A used in this system is a SPI LCD display

controller and driver with a 3 line 16 character dot matrix LCD panel. The controller has two 8­bit registers, the instruction register (IR) and the data register (DR). The controller has parallel interface but it is also SPI compatible. In this system SPI is used to write to the display. The Register Select input (RS) selects the IR when RS = 0 and the DR when RS = 1. The IR stores instruction codes and address information for the DDRAM and Character Generator RAM (CGRAM). The DR holds the data to be written to the DDRAM or CGRAM. The address counter register (AC) holds the address of the locations in DDRAM or CGRAM.

Figure 7: LCD DOG Module connections

Courtesy: Professor Kenneth Short’s lecture slides The MOSI and SCK signals of the DOG module are shared by other SPI peripherals in the system. The RS signal is connected to the PB4 of the ATmega128. The LCD chip select signal (/SS) is connected to PB0. These connections are made using a JTAG connector shown below.

Figure 8: LCD JTAG Connector

Page 15: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 14

Honeywell HumidIcon Temperature and Humidity Sensor This design uses a Honeywell HIH9000 series SOIC­8 SMD with serial output. This

sensor is a combined temperature and humidity sensor with 14­bit resolution. In a measurement cycle, the sensor is normally in power down mode. To wake the sensor and make a measurement, a Measurement Request (MR) command is used. A MR command is an 8­bit read and then incoming data is ignored. A Data Fetch (DF) command is then used to read the temperature and/or humidity.

Figure 9: HumidIcon Measurement Cycle

Courtesy: Professor Kenneth Short’s Lecture Slides The sensor is a Read only device and uses the shared MISO input from the

microcontroller. Pin PortA 0 is used as a select signal for the sensor. A data fetch packet returned from the humidicon has the following format: [ S(1:0),C(13:8), C(7:0), T(13:6), T(5:0),xx ] where, S(1:0) = Status bit of the packet (00 ­ normal operation, valid data; 01 ­ stale data, no new data) C(13:8) = Upper six bits of the 14­bit humidity C(7:0) = Lower eight bits of the 14­bit humidity T(13:6) = Upper eight bits of the 14­bit temperature T(5:0) = Lower 6 bits of the 14­bit temperature xx = don’t care.

Figure 10: Humidicon Data packet

Courtesy: Professor Kenneth Short’s Lecture Slides Hence, a complete measurement of both temperature and humidity takes a total of four SPI transfer cycles. This raw data is then scaled and converted to the required units to be displayed.

Page 16: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 15

Figure 11: HumidIcon Schematic

Conversion and Scaling of Raw Data

1. The four data packets are stored in 4 separate unsigned integers. Using the above notation, C(13:8), C(7:0), T(13:6), T(5:0) are to be stored in separate variables C1, C2, T1, T2, respectively.

2. Mask the C1 with 0x3F to eliminate the two unnecessary MSB of C1 that do not contain the value of the raw humidity.

3. Mask T2 with 0xFC to eliminate the two unnecessary LSB of T2 that do not contain the value of the raw temperature.

4. Shift C1 to right 8 positions to place the high nibble of the raw humidity into the MSBs. 5. Shift T1 to the right 8 positions to place the high bible of the raw temperature into the

MSBS. 6. Performing a bitwise OR of C1 and C2 will yield the complete raw value of Humidity. 7. Performing a bitwise OR of T1 and T2 will yield the complete raw value of temperature,

after the OR result is shifted to the left two position.

(1)caled Temperature 000S = 2 −214Raw Temperture 100 165* * − 4

(2)caled Humidity S = 2 −214Raw Hiumidity 100 100* *

See files humidion _task2.c and temp_humid_humdicon.c in the appendix to see process executed in C.

Page 17: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 16

Pressure Sensor The transducer used in this system is a Freescale MPXHZ6130A Pressure sensor. This

sensor has a 1.5% accuracy over 0 degrees to 85 degrees Celsius. It comes in a surface mount package and is suitable for microcontroller based systems. The basic characteristics of the sensor are shown in the table below from the datasheet:

Figure 12: MPXHZ6130A Pressure Sensor Characteristics Courtesy: MPXHZ6130A Datasheet

The analog output of this sensor is connected an Analog­to­Digital converter.

Figure 13: MPXHZ6130A Schematic

Page 18: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 17

MAX1270 Analog-to-Digital Converter The MAX1270 is a Data­Acquisition­System (DAS) IC that has a multiplexer, to switch

between input channels, signal conditioning circuit for gain and offset adjustment, and an Analog­to­Digital converter with Voltage reference. It allows up to eight analog input channels. It has a 12­bit resolution with 0.5 LSB linearity Our system uses a SPI enabled version to save port pins on the microcontroller. This is used to convert the analog pressure sensor output to a digital output to be monitored and used by the microcontroller. Channel 0 analog input is used in our system.

To initiate a conversion, a Control Byte needs to be transmitted. The control byte selects the input channel for a particular conversion, selects the full scale input voltage range, unipolar or bipolar modes, and the clock and power down mode. The control byte has the following format: CB = Start, SEL2, SEL1, SEL0, RNG, BIP, PD1, PD0 Bit 7 ­ Start: First logic 1 after the /CS goes low defines the beginning of a control byte. Bit 6:4 ­ Select bits: The three bits select the desired analog input channel. Bit 3 ­ Range: Selects the full scale voltage range for the conversion. (Table __) Bit 2 ­ Bip: Unipolar or Bipolar operation mode (Table __) Bit 1:0 ­ Power Down mode: 00 for normal operation (always on) with internal clock.

Table 1: Range and Polarity selection for MAX1270

Courtesy: MAX1270 Datasheet

The timing waveform below from the MAX1270 datasheet shows the detailed timing requirements. After the Chip Select input (/CS) signal goes low, the control byte for a conversion is transmitted. After the transfer of the control byte, the chip is to be unselected (/CS=1). This sets the Strobe signal (SSTRB) to a logic 0 indicating the start of a conversion. The end of conversion is indicated by the SSTRB signal going high. Once the SSTRB signal goes high, our design transfers two dummy bytes over the MOSI line to read the 12­bit ADC output over the MISO line. For faster continuous conversion cycles, a second control byte can be transferred after the first dummy byte to initiate another conversion. However, our system does a total of three byte transfers, one control byte and two dummy bytes. At the end of the second dummy byte, the chip is deselected. INT1 of the microcontroller is used to trigger an interrupt service routine when end of conversion signal occurs on the SSTRB.

Page 19: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 18

Figure 14: MAX1270 ADC Timing waveform

Courtesy: MAX1270 Datasheet

Figure 15: MAX1270 ADC Schematic

Page 20: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 19

XBee Wireless Module The XBee 802.15.4 wireless transmitter/receiver converts RS232 protocol signals into a

wireless RS232 protocol data stream. In remote operation mode of the EMCS, the XBee is used to receive commands from a remote station and send data back. This enables the setting of temperature and humidity setpoints from any internet capable device. The ATmega128 uses USART0 to communicate with the XBee module. The base station sends out a command through the USART, which then goes to the XBee for wireless transmission. A remote station is also able to send commands back to the base station through a device cloud that is integrated with the XBee. The Heroku cloud application platform provides for customized device cloud capabilities. The XBee module comes with its own device cloud. Logging into the Heroku device cloud for XBee gives us loads of capabilities via widgets to communicate with the XBee. Our system uses a simple text interface that is able to send and receive data from the XBee module over the internet.

The Xbee needs a 3.3V power supply. Since this system is primarily 5V, a voltage regulator is used to convert 5V down to 3.3V. Because the XBee is operating at 3.3V, it cannot be directly connected to the ATmega128. The voltage and current characteristics of both the devices need to be compatible. The XBee RxD input from the microcontroller is connected to a voltage divider to limit the voltage.

Figure 16: XBee ­ ATmega128 Compatibility Requirements

Courtesy: Professor Kenneth Short’s Lecture Slides

Page 21: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 20

Figure 17: XBee and Voltage Regulator Schematic

Page 22: EMCS Design Documentation - ESE381

SAAT Corporation Your Home Environment Monitoring System 21

Troubleshooting

Issue Possible Reason How to fix it

LCD does not turn on System is not powered ­ Check if the power cord is connected properly. Disconnect and connect it. ­ Battery out of power, replace the battery

LEDs do not turn on Measurands and setpoints are equal

­ If the measurands and setpoints are equal, the LEDs do not turn on. This is not a problem

Wrong measurand readings Calibration ­ Power off and power on the system again to reset it

Device disconnected on Heroku device cloud

Device not connected to wifi ­ Ensure your wifi is open and available to connect. If not, contact your network administrator.

Cannot log on to device cloud Wrong username/password ­ Ensure the correct username and password ­ Contact Heroku Tech. Support for further details: 952­912­3444

Other unknown issues Contact us at 631­555­5555 to report the issue for further assistance

Contact Information

Email [email protected] Phone 1­800­888­SAAT(7228) Mail SAAT Corporation 1, Infinity Way Port Jefferson, NY 11790