Sie sind auf Seite 1von 15

This report presents a design of a temperature measurement and display system that incorporated the Motorola 68HC11 microcontroller,

simply referred to here as the HC11. This design was a valuable experience because similar temperature measurement and display systems often are used in buildings and vehicles [Spasov, 1996]. The design presented in this report made use of the HC11's analog-to-digital (A/D) converter and the serial subsystems. As shown in Figure 1, the design included a temperature sensor connected to one of the HC11's A/D input pins on Port E, and light emitting diodes (LEDs) connected to Port B. These LEDs acted as temperature indicators. Additionally, the design included a connection between the HC11 and a remote personal computer (PC). This connection served to send messages regarding temperature to the PC. An assembly software program developed for this design performed various functions for using the added hardware. The design had two main objectives. The first objective was to use the HC11 to measure temperature. Included in this objective was the task of connecting the temperature sensor and the LEDs to the HC11. Also included in this objective was the task of designing software to do the following: initialize the A/D converter and serial subsystems; control the measurement and storage of temperature in a RAM variable called TEMP; and control the display of temperature on the LED outputs. The second objective of the design was to use the HC11 to indicate if the temperature went outside of prescribed limits: below 20 degrees Fahrenheit or above 90 degrees Fahrenheit. Included in this objective was the task of connecting the HC11 to a remote PC terminal through an RS-232 connection. Another task within this objective was developing software to initialize the serial subsystem. The final task of this objective was to create subroutines for the software program of the first objective to have the HC11 send a message to the PC if the measured temperature went outside the stated limits. This report first presents the procedures for and assessment of the design to have the HC11 measure temperature. Then the report discusses the procedures for and assessment of adding a serial output to the HC11 design to communicate whether the temperature is outside of prescribed limits.

Figure 1. Temperature measurement and display system developed for the Motorolla 68HC11 microcontroller, which is attached to a universal evaluation board (EVBU).

> > Connecting a Temperature Measurement Circuit to the HC11 > Connecting a temperature measurement circuit to the HC11 microcontroller involved both hardware and software. Hardware was added to control the measurement and display of the temperature. Software served to control this added hardware. In performing the testing and design for this part of the project, my laboratory partner and I divided the work in the following way. My partner assumed the lead role in connecting the hardware, and I assumed the lead role in writing the programs. Although one of us had a lead role in performing either the hardware or the software, we worked collaboratively in checking both the hardware and software and in troubleshooting any problems. > Procedures for Design. The hardware for the temperature measurement circuit included both a temperature sensor attached to Port E and LEDs attached to Port B. The circuit, which is shown in Figure A-1 of Appendix A, was designed according to the specifications obtained from the Computer Engineering Laboratories web site for ECPE 4535 [Lineberry, 2001]. Within the circuit was an LM3911 temperature controller integrated circuit (IC), the output of which we connected to a non-inverting op-amp. The output of this op-amp attached to the HC11 A/D input pin E2 through a 1000-ohm resistor. The circuitry was scaled so that 0 volts out corresponded to 0 degrees and 5 volts out corresponded to 110 degrees. To each of the output pins of Port B, we connected LEDs using a 74HC244 buffer IC and 330-ohm current limiting resistors, all of which are shown in Figure A-1. The LEDs were located in the breadboard area of

the trainer kits. To control this added hardware, we programmed the HC11 following the pseudo code and program listing given in Appendices B and C, respectively. The program shown in Appendix C consisted of three subroutines that were called from the main program (Main). The three subroutines were named Startup, GetTemp, and SetDisp. The Startup subroutine was used to enable the A/D converter subsystem. First the A/D charge pump was powered up by setting bit 7 of the Option register. Then, bit 6 was cleared so that the charge pump used the system E-clock [Spasov, 1996]. After a 100 microsecond delay to allow the charge pump to stabilize, the control word $22 was written to the ADCTL register to start continuous, singlescan conversions on pin E2 of Port E. The subroutine GetTemp was used to input and scale the analog voltage from the temperature sensor circuit. The register ADR3 held the result of the A/D conversions, which was treated as an 8-bit binary fraction between 0 and 1. This value was loaded into accumulator A and then multiplied by a scale factor of 110 using the MUL instruction. The result of this multiplication was a 16-bit number between 0 and 110, with an 8-bit integer portion stored in accumulator A and an 8bit fractional portion stored in accumulator B. The integer portion of the temperature was then stored in the RAM variable TEMP. The subroutine SetDisp controlled the lighting of the LEDs connected to Port B. The amount of lighting was based on the present value of TEMP. First, TEMP was loaded into accumulator A and compared with the value 20, the designated cut-off for low temperature. Accumulator B was cleared to zero and represented the initial value to be written to Port B. If the value in accumulator A was greater than or equal to 20, then the value in accumulator B was shifted one position left and incremented, and 10 was subtracted from accumulator A. The process then repeated itself as long as the value in accumulator A was greater than or equal to 20. An abbreviated form of this process appears in Figure 2 (the complete process appears in Appendix C). After the number of LEDs to turn on were determined, as shown in Figure 2, the number of bits indicated by the count value in accumulator B were set high on Port B beginning with bit 0 [Motorola, 1991].

Figure 2. Flowchart illustrating the determination of the number of Port B bits to enable for the LED display.

> > Assessment of Design. To test the operation of the GetTemp and SetDisp subroutines, we measured the actual temperature with a temperature probe and compared that with the measured value represented by the LED display indicators at several different temperature settings. Table 1 shows the results of the measurement comparison, where the actual temperatures measured are shown on the left, and the temperatures represented by the number of LEDs lit are shown on the right. From Table 1, we verified that the developed hardware and software for this part of the lab were functioning properly. Overall, this section of the laboratory went smoothly. Table 1. Comparison of temperature measurements.
Actual Temperature 15F 28F 33F 56F 110F Number of LEDs Lit 0 1 2 4 8

> > Adding Serial Output to the HC11

> This section presents the addition of four subroutines to the existing software developed in the previous section. The added subroutines, listed in Appendix D, were called InitSCI, SendChar, SendMsg, and CheckLimits. The InitSCI subroutine initialized the serial subsystem of the HC11 so that it could communicate with the host PC at 9600 baud [Spasov, 1996]. This initialization was done by writing control words to the BAUD, SCCR1, and SCCR2 control registers in the HC11 as shown in Appendix C. In performing the testing and design for this part of the project, my laboratory partner and I divided the work in the following way. My partner assumed the lead role in connecting the hardware, and I assumed the lead role in writing the programs. Although one of us had a lead role in performing either the hardware or the software, we worked collaboratively in checking both the hardware and software and in troubleshooting any problems. > Procedures for Design. The first subroutine, SendChar, was added to send a single data byte from the HC11 to the remote PC terminal. The data byte to be sent was contained in accumulator A. After waiting for the TDRE bit in the SCSR register to be set, indicating that the HC11 is ready to transmit another byte, the value in accumulator A was written to the SCDR register to begin the transmission [Motorola, 1991]. The second subroutine, SendMsg, used the SendChar subroutine to write character strings to the remote PC terminal. Before calling SendMsg, the X index register was set to point to the beginning of the character string to be sent. The SendMsg subroutine then sent out the string by calling SendChar for each character until the NULL character was reached, which marked the end of a string. The third and final subroutine, CheckLimits, was added to the existing software program to check the temperature range. The subroutine CheckLimits called SendMsg to print the following message if TEMP was less than 20 degrees Fahrenheit: "Temperature is very low." If TEMP was greater that 90 degrees Fahrenheit, CheckLimits called SendMsg to print the following message: "Temperature is very high." If TEMP was between 20 and 90 degrees Farenheit, CheckLimits called SendMsg to print the following message: "Temperature is acceptable." A flag variable called FLG ensured that the messages were not repeatedly sent for each entry into the very hot, very cold, or acceptable temperature regions. FLG was set to zero if TEMP was between 20 and 90 degrees, one if TEMP was less than 20 degrees, and two if TEMP was greater than 90 degrees. > Assessment of Design. While developing the design presented in this section, several mistakes and difficulties were encountered. The initial setup of the serial subsystem of the 68HC11 involved some troubleshooting. We also had problems with sending the alarm messages more than one time because a flag variable was not set. The diagnosis and solutions to these problems are discussed in this section. Initially, the serial writes from the 68HC11 to the host PC did not work properly

because the SendChar routine did not check the TDRE bit before writing to the SCDR register. This caused characters to be dropped when sending a message. We also had a problem sending out messages using SendMsg because we did not terminate the message strings correctly with the NULL zero. By adding the NULL zero to the end of the strings, the sending of messages worked as expected. A final problem was the output rate of the alarm messages. At first, we did not set a flag to indicate to the program that a message had already been sent to the PC. This failure caused messages to be continually sent to the PC terminal when the temperature was outside of the normal operating region. This problem was fixed by making a variable called FLG that was set as soon as the alarm message was sent and then cleared when the temperature returned to the normal operating region. > > Conclusions > This report has discussed the development of a temperature measurement and display system. The objectives of this lab were to develop the necessary hardware and software to have the HC11 measure temperature and indicate whether that temperature fell outside of prescribed limits. Both objectives were met. By keeping track of the measured temperature, the HC11 was able to control an LED temperature display. Also, if the temperature became very cold or hot, the HC11 sent an alarm message to a host PC terminal. This lab has introduced us to the important topics of A/D conversion and serial communications. In the lab, an A/D converter allowed us access to analog inputs of temperature from a remote computer. Besides temperature measurement, A/D converters have many applications in automatic control systems and factory automation. For example, in an electric motor drive, the phase currents and flux are continually measured by using scaling circuitry and an A/D converter input to a microprocessor. > > >

Appendix A: Hardware Schematic


> > Figure A-1 presents the hardware schematic for the temperature circuit. The circuit was designed according to the specifications obtained from the Computer Engineering Laboratories web site for ECPE 4535 [Lineberry, 2001].

Figure A-1. Hardware schematic for the temperature measurement circuit designed for this lab. In an actual report, all the connections, pin numbers, and pin labels should be shown.

> > >

Appendix B: Pseudocode for the Software Developed


> > XXXXXXXXXXXXXXXXXX* XXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXX

XXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXX


*In an actual report, the pseudocode would appear here. Also note that some professors allow you to substitute an appendix with program flow charts for this appendix.

> > >

Appendix C: Program Listing


> >
Assembler release TER_2.0 version 2.09 (c) Motorola (free ware) 0001 ;************************************************** 0002 temperature 0003 is 0004 is 0005 bar 0006 below 0007 link. 0008 ; Temp_Monitor: This program implements a ; measurement and display system. The A/D system ; used to read an analog temperature. The value ; scaled to Farenheit, and displayed on an LED ; display. If the temperature is above 90 or ; 20, a message is transmitted over the serial ; Programmer: JMB

0009 ;************************************************* 0010 0011 ; Define some I/O registers

0012 1004 0013 102b 0014 102c 0015 102d 0016 102e 0017 102f 0018 1030 0019 1031 0020 1032 0021 1033 0022 1034 0023 1039 0024 0025 0026 005a temperature limit 0027 0014 temperature limit 0028 0002 indicating 0029 UPPER_LIMIT 0030 0001 indicating 0031 LOWER_LIMIT 0032 0000 indicating 0033 within limits 0034 000d carraige return

PORTB BAUD SCCR1 SCCR2 SCSR SCDR ADCTL ADR1 ADR2 ADR3 ADR4 OPTION

EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU

$1004 $102B $102C $102D $102E $102F $1030 $1031 $1032 $1033 $1034 $1039

; Define some constants UPPER_LIMIT LOWER_LIMIT HOT EQU EQU EQU 90 20 2 ; COLD EQU 1 ; OK EQU 0 ; CR EQU $0D ; upper ; lower ; flag value temperature ; flag value temperature < ; flag value temperature is ; ASCII code for

0035 000a line feed 0036 0037 0038 0100 0039 0100 temperature 0040 0101 indicating system state 0041 0042 0043 b600

LF

EQU

$0A

; ASCII code for

; Variables ORG TEMP FLAG $100 rmb rmb 1 1 ; ; place in RAM area ; current ; flag (HOT, COLD, or OK)

ORG

$B600

; EEPROM area

0044 ;*************************************************** 0045 system, and 0046 reads 0047 then 0048 necessary. 0049 0050 0051 TEMP, FLAG ; Temp_Monitor: This routine initializes the ; then enters an endless loop. In this loop, it ; the current temperature, updates the LEDs, and ; sends a message to the serial link, if ; Input: none ; Output: none ; Registers/variables modified: ACCA, ACCB, CCR,

0052 ;**************************************************** 0053 0054 b600 8e 01 ff pointer 0055 b603 bd b6 11 SCI, 0056 variables Temp_Monitor: lds jsr #$1FF Startup ; initialize stack ; initialize A/D and ; initialize RAM

0057 0058 b606 bd b6 1d temperature 0059 b609 bd b6 29 0060 b60c bd b6 3c limits 0061 b60f 20 f5 0062 0063 0064

Main: jsr jsr jsr bra GetTemp SetDisp CheckLimits Main ; get current ; update LED display ; check upper and lower ; repeat

0065 ;**************************************************** 0066 It calls 0067 and the 0068 variable. 0069 0070 0071 FLAG ; Startup: This routine initializes the system. ; other routines to initialize the A/D system ; SCI system. It also initializes the FLAG ; Input: none ; Output: none ; Registers/variables modified: ACCA, IX, CCR,

0072 ;**************************************************** 0073 0074 b611 bd b6 7c system 0075 b614 bd b6 a2 interface 0076 0077 b617 86 00 0078 b619 b7 01 01 0079 0080 b61c 39 rts ldaa staa #OK FLAG ; initialize FLAG Startup: jsr jsr InitAD InitSCI ; power up the A/D ; initialize the serial

0081 0082 ;**************************************************** 0083 temperature. 0084 Farenheit, 0085 $00 0086 $100) 0087 by 0088 0089 0090 0091 TEMP ; GetTemp: This routine gets the current ; It reads the A/D value, converts it to ; and stores the result in TEMP. An A/D value of ; corresponds to 0 degrees, and $FF (actually ; is 110 degrees, so the A/D value is multiplied ; 110 to convert to temperature. ; Input: none ; Output: New temperature stored in TEMP ; Registers/variables modified: ACCA, ACCB, CCR,

0092 ;**************************************************** 0093 0094 b61d b6 10 31 0095 b620 c6 6e 0096 b622 3d 0097 b623 89 00 0098 0099 b625 b7 01 00 0100 0101 b628 39 0102 0103 ;**************************************************** rts staa TEMP ; store new temperature GetTemp: ldaa ldab mul adca #$00 ADR1 #110 ; read A/D value ; multiply by 110 ; to get temperature

; round to 8 bits

0104 display 0105 as a 0106 in 10 0107 of the 0108 temperature. 0109 0110 0111

; SetDisp: This routine updates the LEDs to ; the current temperature. The LEDs are arranged ; bar display with a range of 20 - 90 degrees, ; degree steps. This routine determines how many ; LEDs should be turned on based on the current ; Input: TEMP variable ; Output: none ; Registers/variables modified: ACCA, ACCB, CCR

0112 ;**************************************************** 0113 0114 b629 c6 00 0115 b62b b6 01 00 temperature 0116 0117 0118 b62e 81 14 0119 b630 25 06 0120 b632 58 0121 b633 5c 0122 b634 80 0a 0123 b636 20 f6 0124 0125 0126 b638 f7 10 04 0127 0128 b63b 39 rts Update_LEDs: stab PORTB ; update the LEDs SD_Loop: cmpa blo lslb incb suba bra #10 SD_Loop ; value = value - 10 ; repeat #20 Update_LEDs ; is value 20? SetDisp: ldab ldaa #$00 TEMP ; all LEDs off initially ; get current

; branch if not ; else, turn on next LED

0129 0130 ;**************************************************** 0131 current 0132 limits. If 0133 over the 0134 0135 0136 0137 CCR ; CheckLimits: This routine checks to see if the ; temperature is within the upper and lower ; not, then a warning message is transmitted ; serial link. ; Input: TEMP, FLAG ; Output: none ; Register/variables modified: ACCA, ACCB, IX,

0138 ;**************************************************** 0139 0140 b63c b6 01 00 temperature 0141 b63f 81 5a 0142 b641 23 12 0143 b643 c6 02 0144 0145 b645 f1 01 01 HOT?) 0146 b648 27 31 repeat 0147 0148 b64a f7 01 01 0149 b64d ce b6 e2 message 0150 b650 bd b6 c5 0151 b653 20 26 0152 stab ldx jsr bra FLAG #HOT_MSG SendMsg CL_Exit ; and exit cmpb beq FLAG CL_Exit CheckLimits: ldaa cmpa bls ldab TEMP #UPPER_LIMIT Check_Lower #HOT ; get current ; temp upper limit?

; branch if not ; have we already sent a ; ; warning for this? (i.e., is FLAG ==

; branch if so (don't ; warning message)

; update flag ; send "hot" warning

0153 0154 b655 81 14

Check_Lower: cmpa #LOWER_LIMIT ; temp $102F

Das könnte Ihnen auch gefallen