ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 3134

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

15.3

A Microcontroller Implementation of a Fuzzy Controller

191

MLOOP EQU

*

INCLUDE

TIMER.ASM

INCLUDE

INPUT.ASM

INCLUDE

DERIV.ASM

INCLUDE

FUZZY.ASM

INCLUDE

DISPLAY.ASM

JMP

MLOOP

INCLUDE

OUTPUT.ASM

INCLUDE

MFTAB.ASM

END

INPUT.ASM contains the code to read the status of the digital input lines (the START and STOP buttons, and the rotary encoder used to select the variable to display) and the values of the analog inputs AN0, AN1, AN2, assigned to the variables TS – set-point temperature, TM – measured temperature, and TD – the time interval used to compute the error dot. The variable ERR is updated here with the values of the difference TS – TM by the subroutine CERR, listed below:

CERR CLRA

LDAB

TM

STD

TEMP

;TEMP is a 16-bit storage

LDAB

TS

SUBD

TEMP

;D=TS-TM 16-bit signed INT

STD

ERR

;update ERR

RTS

The rest of the preprocessing task is performed in the module DERIV.ASM, which calculates the derivative of the error, by comparing the current value of ERR with the previous value, stored in the variable PREVERR. The time interval between two successive samples is obtained using a software timer, and it is made adjustable by multiplying the timer quantum with the value of the variable TD, which stores the analog value of the potential on the cursor of the potentiometer R13. The effect is that the variable DERIV = ERR − PREVERR is updated at time intervals of 100 ms*TD.

The six membership functions associated with the subdomains N, Z, and P of e(t) and d(t) are defined as tables in module MFTAB.ASM. This also contains the nine-byte consequent table SGTAB.

The actual fuzzy inference is performed in FUZZY.ASM, by the subroutine CAT (Create Antecedent Table), which updates the contents of the 9-byte RAM table ATAB, according to the rule matrix described above. Finally, the subroutine CRISP computes the crisp output of the controller, and updates the variable VOUT, as the weighted average of the values in SGTAB, with the weights extracted from the antecedent table ATAB.

The value of VOUT is used in OUTPUT.ASM to determine the moments when the triac that drives the heater must be open, as described in the previous chapter.


192 15 Fuzzy Logic Temperature Controller

Exercises

SX 15.1

What is the influence of the parameter TD on the overall behavior of the fuzzy controller described above?

Solution

TD determines the time between the moments when the variables ERR and PREVERR are updated. The values of the error dot d(t) = e(t2) − e(t1) = e(t1 + TD × k) e(t1) are directly related to the parameter TD and to the response time of the controlled system. When TD is too small, t2 is very close to t1, d(t) tends to zero, and the process is misinterpreted as being at equilibrium. Therefore, the control system exerts low-to-moderate action on the process, even if the error is positive and high.

On the contrary, when TD is too large, the controller tends to react drastically even at small variations of the temperature, and the system tends to become unstable. In practice, TD should be set to high values only for slow response processes.

SX 15.2

What is the effect of changing the shape of the membership functions associated with the subdomains N, Z, P of e(t) to the shape presented in Fig. 15.6?

Z

N

1

P

0.8

0.2

e(t)

-8

-3

0

3

8

Fig. 15.6. Membership functions for exercise SX15.2

Solution

The slope of a function f(x) contains information about the speed of variation of the function. For high values of the slope, even small variations of the argument x produce important variations in f(x). In this particular example, the controller senses the variations of e(t) as being more significant when the slope of the membership functions is higher, and therefore Vout will change more drastically when Tm is far from Ts , than in the vicinity of the equilibrium point.

Note the similarity between the slope of the membership functions associated with e(t) and the proportional gain K p of a PID controller. Using membership functions with the shape presented in Fig. 15.2 is equivalent to dynamically adjusting the parameter K p of a PID controller. The risk of overshoot is reduced in this case, compared to the case of triangular membership functions.


16

Remote Relay Controller over Telephone Lines

16.1 In this Chapter

This chapter contains the description of a device that interfaces a microcontroller to a telephone line, and is capable of receiving and decoding a series of DTMF signals, and to execute commands received this way.

16.2 Description of the Hardware Solution

Since telephone lines are available almost anywhere, it is interesting to design a device that, when connected to a phone line, is able to answer a call, and to recognize and execute a series of commands generated directly from the keypad of the telephone set that initiated the call.

This device operates according to the following set of rules:

The human operator initiates a call, using a regular telephone set.

The relay controller senses and counts the ring tones generated by the central office.

After a specified number of rings, the relay controller answers the call and transmits a specific audible tone over the telephone line to acknowledge its presence.

Using the telephone keypad, the operator generates a series of DTMF (Dual Tone Multi Frequency) tones, having a determined structure, which are received and decoded by the controller. The DTMF tones are audio signals, consisting of a combination of two sine waves, having precise frequencies in the range 697–1633 Hz. Each key of the telephone set keypad is associated with a distinct combination of frequencies, so that the receiving device can easily identify the key pressed.

The relay controller sends back to the operator distinct audible tones after the reception of correct, or erroneous DTMF series.

After 30 seconds of inactivity, i.e. if no DTMF tone is received for 30 seconds, the controller closes the line, and terminates the session.


194 16 Remote Relay Controller over Telephone Lines

Ring

Auto

detector

answer

Telephone line

DTMF

I / O

decoder

lines

HC11 development board

Fig. 16.1. Block diagram of the remote relay controller

The block diagram of such a device, called remote relay controller, is presented in Fig. 16.1.

The circuit is designed to use the HC11 development board, described in Chap. 9, extended with a telephone line interface, and the actual relay interface.

The telephone line interface comprises the following functional blocks:

The ring detector. This is the circuit that recognizes the ring tone, and informs the microcontroller about an incoming call.

The auto-answer circuit. This allows the microcontroller to open the line and answer the call, after a specified number of rings.

The DTMF decoder. This decodes DTMF tones received over the telephone line and reports the codes to the microcontroller, along with a STROBE signal. The DTMF tones are generated by the telephone set that initiates the call.

The schematics of the ring detector and auto-answer circuits are presented in Fig. 16.2.

The device emulates the behavior of a standard telephone set. While in the onhook status, the capacitor C1 separates the interface from the telephone line, but allows the ring signal, which is an ac signal with amplitude 48–50 V, and frequency of approximately 30 Hz, to go through, towards the rectifier formed by D1, D2 and C2.

TR1

GND

VPP

S2

K1

PRI

DTMF In

U3

VCC

D3

S1

1

PA7

R4

R7

3

C3

2

Q1

10K

DT

1N4004

40107

J1

2N2222

100n

VCC

R5

4

R6

3

S2

S1

1K

10K

2

P2

R2

R3

1

P1

GND

K1

K1

GND

GND

U1330K

5K6

O2

O1

C1

D1

C2

R1

1

U5A

6

1

PA0

2.2uF

1N4004

10K

5

2

D2

2

4

40106N

1N4004

10uF/100V

GND

Fig. 16.2. Ring detector and auto-answer circuits


16.2 Description of the Hardware Solution

195

The resulting dc voltage activates the LED of the optocoupler U1, which results in the saturation of the output transistor. The output of the optocoupler is conditioned and inverted by the Schmitt trigger gate U5A, and then applied to the PA0 (TIC3) input of the microcontroller. The rising edge of the signal on PA0 generates a TIC3 interrupt, thus informing the microcontroller about the detected ring.

After counting a programmed number of rings, the MCU activates the relay K1, by writing 1 to PA7, and opens the telephone line. In the off-hook status, the telephone line is connected to the primary circuit of the transformer TR1, in series with the resistor R4 (560 ohms), which gives a total load impedance of around 600 ohms, as required by all modern central offices.

Besides galvanic isolation, the transformer TR1 has two additional functions: it transfers the audio signal DTMF_IN from the telephone line to the input of the DTMF decoder, and, on the other hand, transmits the audible dialog tones DT, generated by the interface, to the telephone line, by means of the transistor Q1.

The actual DTMF decoder is shown in Fig. 16.3.

The input for the decoder circuit CM8870 (U2) is the analog signal DTMF_IN, which is the analog signal present on the telephone line, separated by the transformer TR1, without further processing. When this signal contains a valid combination of tones, corresponding to the DTMF standard, the circuit presents on the output lines Q1–Q4 the 4-bit binary code of the digit associated with the DTMF tone, along with a strobe signal STD, active HIGH. STD stays HIGH as long as the DTMF tone is stable at the input of the circuit (min 100 ms).

The combinations of frequencies associated with each digit are presented in Table 16.1, and the corresponding binary codes are shown in Table 16.2.

The strobe signal is connected to the line PA1/IC2 of the MCU, and generates a TIC2 interrupt on the rising edge. The data bits Q1–Q4 (Q4 is the most significant bit) are connected to the port D (PD2–PD5) of the microcontroller.

Note that the binary codes associated with each digit are not the hexadecimal codes for these digits. Table 16.2 lists the binary codes corresponding to the frequency pairs in Table 16.1.

Figure 16.4 shows the schematic of the circuit that generates the audible dialog tones DT, transmitted by the controller over the telephone line in response to

C4

U2

R9

R8

1

IN+

STD

15

PA1

DTMF In

2

11

PD2

IN-

Q1

3

12

PD3

100n

100k

100k

GS

Q2

13

PD4

Y1

7

OSC1

Q3

14

PD5

8

Q4

3.58MHz

17

OSC2

INH

5

ST/GT

6

C5

16

PD

EST

18

GND

100n

10

OE

VDD

9

VCC

4

VSS

R10

300k

VREF

GND

VCC

Fig. 16.3. Schematic of the DTMF decoder circuit