5.7 ADDITIONAL ILLUSTRATIVE EXAMPLES: INTERFACING SENSORS AND MOTORS

5.7 ADDITIONAL ILLUSTRATIVE EXAMPLES:

INTERFACING SENSORS AND MOTORS

In previous examples, we illustrated the interfacing of I/O devices that were pri­marily binary devices (on/off). We now extend the concepts to interface analog devices such as temperature sensors and motors. In interfacing analog devices, the basic procedure remains similar to that of interfacing binary devices; the MPU identifies the device through a binary port address and enables it with an appro­priate control signal. However, we need to find a way to detect and to convert the analog signal into the binary format and vice versa. The analog signal is generally handled in two ways: one is to detect the signal when it reaches a predetermined level, and the other is to convert it into binary format proportional to its magni­tude. The predetermined level of the analog signal can be detected by using a comparator circuit, and the binary equivalent can be obtained by using an AID (Analog-to-Digital) data converter. In this section, we will focus on interfacing cir­cuits that can detect the predetermined level of analog signals and defer the dis­cussion of interfacing data converters to Chapter 13.

Figure 5.11 shows the interfacing of a temperature sensor. This circuit is designed to detect (through an input port) whether the temperature has risen to 100°C, and at that temperature it turns on the dc motor of a water pump. The de motor is interfaced with the MPU through an output port.

5.7.1 Hardware: Temperature Sensor LM135

And Comparator LM311

Figure 5.1l shows the LM 135 used as a temperature sensor. Its output is con­nected as one of the inputs to the comparator LM311. The LM135 is an integrated circuit, designed to sense changes in temperature; its output voltage changes 10 m V/ °C. It is rated to operate over a temperature range from – 55°C to + 150°C, and the current range 400 µA to 5 mA . At 25°C, the output of the sensor is typi­cally 2.98 V, and it increases I0mV/°C; therefore, at 100°C, it can reach 3.73 V (2.98 V + 750 mV).

z80 Interfacing and programming-21_03

The LM311 is a voltage comparator that can be operated from a + 5 V power Supply. The comparator compares two voltages at its input terminals, and if the difference between the two voltages is less than or equal to – 10 m V, its output remains at the saturation voltage of about 0.75 V; otherwise, the output is near the power supply voltage.

The output of the sensor is connected to the positive terminal of the com­parator, and its negative terminal is set to 3.73 V. At temperatures lower than 100°C the output voltage of the sensor is less than 3.73 V; thus, the comparator output remains at 0.75 V (logic 0). When the temperature reaches 100°C, the out­put of the sensor is 3.73 V, and the comparator output goes to + 4.5 V (logic I). The output of the comparator is connected to the tri-state buffer 74LS244, which serves as an input port to the MPU.

5.7.2 Interfacing Circuit for the Sensor

Figure 5.11 shows that the 74LS138 (3-to-8) decoder is used for address decoding. This decoding circuit is identical to the circuit shown in Figure 5.8; thus, the outputs of the decoder are asserted for port addresses ranging froin80H to87H ("don’t care" lines are assumed to be at logic 0). The control signals I̅O̅R̅D̅ (I/O’ Read) and I̅O̅W̅R̅ (I/O Write) are generated by using the 74LS139 (2-to-4) decoder; which is enabled by the I̅O̅R̅Q̅ signal. When the MPU intends to read, it asserts the I̅O̅R̅Q̅ and R̅D̅ signals. The input of the 2-to-4 decoder becomes 0 1, and the output O. goes active low to assert the IORD (I/O Read) control signal. The I̅O̅R̅D̅ is logically ANDed with the decoded address 80H to generate the I̅O̅S̅E̅L̅80H(I/O Select) signal, which enables the input buffer 74LS244 to read the output of the comparator. The output voltage of the comparator is connected to the data line Do through the buffer, and the MPU can monitor the temperature by monitoring the data line D0 .

5.7.3 Interfacing Circuit for the DC Motor

The de motor is interfaced with the MPU through the latch 74LS373; the output bit O0 of the latch can drive the de motor by turning on the transistor (Darlington pair). The logic level of bit O0 of the latch is controlled by the data line D0. The port address of the latch (87 H) is determined by the 3-to-8 decoder; the output line O7 of the decoder is ANDed with the control signal I̅O̅W̅R̅ to generate the IOSEL87H, which enables the latch 74LS373. When the temperature reaches 100°C, the MPU sends logic I to the latch (port 87H) to turn on the motor, and when the temperature is less than 100°C, the motor is turned off by the logic 0.

z80 Interfacing and programming-22_03

5.7.5 Program and Circuit Description

The first instruction IN A, (80H) enables the buffer 74LS244, reads the entire data bus D7, D0, and places the byte in the accumulator. However, we are interested in the logic level of only bit Do; it has the output of the comparator. Therefore, the next instruction ANDs the contents of the accumulator with the byte 01 H in order to eliminate bits D1-D6 and save the logic level of bit D0. When the temperature exceeds 100°C, the output of the comparator is about + 5 V, and the MPU reads logic 1 on the data line D0. When the temperature is lower than 100°C, the com­parator output is about 0.7 V, and the MPU reads logic 0 on the data line D; The next instruction OUT turns on the transistor if D0 = 1 or turns off the transistor if D0 = 0. When the transistor is on, it supplies the necessary current for the motor to run, and when the transistor is off. The motor is turned off. The last instruction JP takes the program back to the beginning and continuously monitors the changes in the output of the comparator.

5.7.6 Additional Sensors and Output Devices

Figure 5. 11 illustrates one example of interfacing a sensor and driving a dc motor. We can extend the same concepts to other sensing and output devices. In Figure 5. 11, we used only one data line Do to monitor the output of the comparator. We can connect additional sensors such as light detectors, level detectors, and smoke detectors to the remaining data lines and instructions can monitor all the sensors in a sequence. Similarly, we can connect output devices such as speakers, alarms, and lights by using solid state relays to the remaining output lines of the latch.

Leave a comment

Your email address will not be published. Required fields are marked *