0% found this document useful (0 votes)
2 views10 pages

Embedded Control Design Methodology

The document presents a project titled 'think locally, solve globally,' which proposes a methodology for designing embedded controls using automatic tools for synchronization and supervisor synthesis. It outlines a three-step approach to tackle embedded control challenges, illustrated through a temperature controller for a frost-free refrigerator. The methodology leverages supervisory control theory and includes details on hardware structure, implementation, and application examples.

Uploaded by

Mohamed Ahmad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Embedded Control Design Methodology

The document presents a project titled 'think locally, solve globally,' which proposes a methodology for designing embedded controls using automatic tools for synchronization and supervisor synthesis. It outlines a three-step approach to tackle embedded control challenges, illustrated through a temperature controller for a frost-free refrigerator. The methodology leverages supervisory control theory and includes details on hardware structure, implementation, and application examples.

Uploaded by

Mohamed Ahmad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Circuit Cellar / AVR Design Contest 2006

Abstract

Project Title:

think locally, solve globally:


an interesting approach to design embedded controls

… an elegant tool to improve the thinking process during software modeling…

…and a simple technique for automatic code generation of AVR’s microcontrolled controls.

Entry Number:
AT3403

Author Name:
AEE1DB207615C9113CCE9CC9FF4CD9A79B76048A01ACD9*

* this is my name! It is encrypted using the 256-bit AES (advanced encryption standard) method,
more known as Rijndael, developed by the Belgian cryptographers Joan Daemen and Vincent
Rijmen. If this job eventually becomes a winner project, I will be glad to inform you the key to
decrypt this code… Became curious? Then please, read this document carefully and… be kind!
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

introduction

Usually, complex problems are composed of a group of small and simple problems. The
strategies for problem solution normally involve to understand the system behavior, divide the goals
and address them one by one.

Following this concept, mostly of the embedded control challenges can be treated essentially
in three steps.

a) Listing the essential elements of the situation, defining their individual models, and
synchronizing these small models obtaining the system global model.

b) Defining the system requirements, creating one or more specifications to satisfy each
requirement and synchronizing all specifications obtaining the global system specification.

c) Calculating one controller, more properly called a supervisor, which is in charge of


adequate the system behavior to satisfy the defined requirements.

The Figure 1 illustrates these 3 steps and its relationship.

GLOBAL PLANT

SUB-PLANT SUB- PLANT SUB-PLANT

#1 #2 #3

SUB-PLANT SUB- PLANT

#4 #5
SUPERVISOR

SPEC SPEC SPEC


SPEC
#1 #3 #4
#2

GLOBAL SPECIFICATION

Figure 1 – individuals and global plant & specification and the obtained supervisor

The present work proposes a methodology to perform these 3 steps using automatic tools for
individual models synchronization, supervisor synthesis and implementation. The method principle
is based on the supervisory control theory of Discrete-Event Systems introduced by Ramadge and
Wonham[5]. The implementation concept consists of a framework and a procedure for the software
coding of supervisors on small (or, let’s say, AVR tiny) microcontrollers.

2 / 10
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

methodology overview

The technique here proposed considers an embedded system as a structure described by


discrete events, where there is a global plant controlled by a supervisor in order to satisfy a list of
requirements. The Figure 2 illustrates this concept.

SUPERVISOR

actions
events

SUB- SUB- SUB-


PLANT PLANT PLANT
# 1 # 2 # 3

SUB- SUB-
PLANT PLANT
# 4 #5

GLOBAL PLANT
EMBEDDED SYSTEM

Figure 2 – an embedded system from the point of view of the proposed methodology

The supervisor synthesis is performed using the GRAIL[4] or Smart TCT[6] software, two free
tools developed by the academic community. The supervisor can be represented as an automaton,
which in this work is implemented as a set of vectors located in program memory. Data search
routines are applied to process the control paths. It was developed an automatic process using
EXCEL macros, to convert the supervisor into three vectors represented in ANSI C format.

A work flow of the method is presented in Figure 3. Notice that a great part of the tasks are
automatically performed.

OPEN LOOP SYSTEM DESCRIPTION timeline

events definition

individual elements modelling as automata

complete system modelling as a resulting automaton

REQUIREMENTS DEFINITION

requirements listing

partial specifications modelling as automata

global specification calculation as a resulting automaton

SUPERVISORY CONTROL SYNTHESIS

supervisor calculation

IMPLEMENTATION
events coding
supervisor coding

Legend:
manually performed
final solution
automatically performed by Grail or Smart TCT software
automatically performed by Excel macros

Figure 3 – methodology work flow

3 / 10
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

application description

A Temperature Controller for a Frost Free Duplex Refrigerator is designed to explain the
application of the technique, but solutions as many as you can imagine are feasible with this
proposal. A system diagram is presented in Figure 4, where the events (represented by arrows with
labels) considered for the modeling and control design are presented.

FREEZER COMPARTMENT

Evaporator Fan Freezer Lamp


f_on fzl_on
f_off fzl_off

Defrost Resistance Freezer Door Sensor


dr_on fzd_o
dr_off fzd_c

Fridge Door Sensor


fgd_o
fgd_c
User Interface

Fridge Lamp
fgl_on
fgl_off

Fridge Temperature Sensor


cut_in
cut_out

Compressor
c_on
REFRIGERATOR COMPARTMENT c_off

USER INTERFACE
Open Door

On/Off Set Point Low Mid High Super Cooling Buzzer Alarm Off Fridge Freezer
on spl spll_on spml_on sphl_on sc_on scl_on bz_on alm_off fgdl_on fzdl_on
off spm spll_off spml-off sphl_off sc_off scl_off bz_off fgdl_off fzdl_off
sph

Figure 4 – diagram of the Frost Free Duplex Refrigerator, with the events considered in the modeling

4 / 10
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

The main goals of the control design are:

- adjust the fridge temperature, turning on or off the compressor and the evaporator fan
according to the current and desired temperatures;

- periodically perform a defrost process, turning on the defrost resistance and the evaporator
fan during a certain amount of time;

- turn on or off the fridge and freezer lamp according to the fridge and freezer door
conditions;

- allow the adjustment of desired temperature, super cooling process, open door audible alarm
off and also system on or off.

hardware structure

The main element of the hardware structure is an Atmel AVR ATtinyX5 microcontroller,
where X can be 2, 4 or 8, depending on the application size. Shift registers and an optimized
multiplexing method are applied allowing the use of a low pin-count microcontroller. The 6 user
interface buttons, the 2 door sensors and 2 additional sensors are referred as switches in the
diagram. These 10 switches are read using only one ADC channel. The Figure 5 illustrates this
structure.

Legend :
Linear Transformer Power Supply - adc = analog -to-digital ATtiny input
AC Input 115 Vrms CN1 - do = digital ATtiny output
(2 outputs : 24Vdc, 5Vdc)
- sro = shift-register output
CNi = board connector i

Load # 1 NTC # 2
Compressor CN2 Input CN8 Additional NTC Probe
Control

1 adc
Load # 2
Defrost Resistance CN3 NTC # 1
Control CN9 NTC Probe
Attiny 1 adc Input
Micro

Load # 3
Evaporator Fan CN4 Control 1 adc
sro

Load # 4 Switches Group A CN10 Fridge Door Sensor


Fridge Lamp CN5 sro Leds Group A
Control (3 buttons and
(5 leds) 2 external sensors )
sro CN11 Additional Sensor # 1
sro
Load # 5 3 do
Freezer Lamp CN6 Control
sro
CN12 Freezer Door Sensor
sro Switches Group B
Load # 6 Leds Group B
(3 buttons and
Additional Load CN7 Control (5 leds)
2 external sensors )
sro CN13 Additional Sensor # 2
sro
sro 5 sro
Buzzer Shift Shift
Control Reg 3 do Reg
#1 #2
Printed Circuit Board

Figure 5 – developed hardware structure

A photograph of the prototype is shown in Figure 6 and the pcb layout is shown in Figure 7.

5 / 10
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

Figure 6 – prototype photograph

Figure 7 – pcb layout

The circuit schematic is presented in Figure 8.

6 / 10
5V

2
R43
13k 1%

R55 C N8
TR1 47R

1
4 5 2 1 2
2
1

2
1
C N1 D7 C 11

4
2 NEUTRAL 3 6 24V 5V 1nF/16V
2
1 2 7
DF06STRR16 IC3 0V
1 1A/600V

AC

1
PHASE MC 7805BT
1 2 2 1 1 3
- + Vin Vout

GND
1 2 1 8 R18 0V

AC
39R 5% 1/2W
F2 6VA(115V/10V)
160mA/250Vrms 5V

1
DC

1
C3 + + 2
JP51 21
C5 C8

2
470u F/35V C9 2
100nF/50V 10uF/50V 1
1
100n F/50V
R44

2
NM
2

R56 C N9
NM

1
2 1 2
F1 1
2

2
6.3A/250Vrms 1
0V
5V
C 12
1

NM 0V

1
24V

R46
4k7 0V
1
2

1
2
JP26

1
2
D1 JP45 1
2
12

43

C N2 LL4148 1
2
C 10
2 JP46 10nF/50V
2
1
1

1
2

1
K1 JP9 JP10 JP11
16A/12Vdc 0V 5V
JP48 21
3

SPS T-NO

2
5V

1
2

1
2

1
2
T2 1 1 2
R30
BC817-25
2

2
R4 4k7
4k7 R39
R12 LINE L2 4k7
4k7 2 1 1 T15
2

1
B C807-25
0V
1

3
24V
0V

5V
JP49 21
1
2

2
5V
K2 D2
R21
12

34

C N3 LL4148

2
2
4k7
2
1 R22
LINE L1
1

1 4k7
2

JP7 JP8 2 1 1 T10

1
10A/12Vdc BC807-25
3

SPS T-NO

3
1
2

1
2

T3 1 1 2
BC817-25
2

R5
4k7 JP12JP13 JP14JP15 JP34 JP16JP17 JP18JP19
R13 JP47
4k7
2

0V

1
2

1
2

1
2

1
2

1
2

1
2

1
2

1
2

1
2

1
2
1

C6 LEDS GRO UP A: LEDS GRO UP B:

2
24V
0V JP52 5V100nF/50V L1 = FDG SP1 L6 = FUTURE
2 2
1 1 L2 = FDG SP2 L7 = FUTURE

K A

K A

K A

K A

K A

K A

K A

K A

K A

K A
L3 = FDG SP3 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 L8 = FUTURE

1
0V L4 = SUPER FREEZING L9 = FUTURE
1

JP56 L5 = FDG DOO R L10 = FRZ DO OR


2

5V JP44 JP43 JP42 JP31 21 JP27 R41 R47 R48 R49 R57

1
K3 D3 1
2 1
2 1
2 1
2
1
PB5 VDD
8 JP66JP65JP64 2
1 JP32 2121 JP28 4k7 4k7 4k7 4k7 4k7
12

34

C N4 LL4148 1
2 1
2 JP33 21 JP29
2 2 7 JP30
2 PB3 PB2

2
1
1

1
2

1
2

1
2
1
2

JP6 3 6
PB4 PB1

SUPER FREEZING
10A/12Vdc 4 5
3

SPS T-NO GND PB0

FRIDGE SP

TS61N-RA

TS61N-RA

TS61N-RA
2

FRIDGE
C N10 C N12

FUTURE

FUTURE
0V

DOOR
IC1
1
2

2 2

SW1

SW3

SW5
T4 1 1 2 ATTi ny13 1
2
1
2
BC817-25
2

1 1
R6

2
4k7

2
R14

1
4k7 R31 R32 R33 R34
2

1
2
JP62 R23 220R 220R 220R 220R
1
2
220R SWITC HES GROUP A
0V JP63
1

1
24V

1
0V

PRO G
1
2

1
K4 D4 2
12

34

C N5 LL4148 3
2 4
2
1 5
1

1
2

0V
10A/12Vdc
3

SPS T-NO

T5 1
2 JP1
1 1 2
BC817-25
2

R7
4k7 R15
4k7 1
2 JP41
2

0V
1
2 JP40
1

24V
0V

3
R24
4k7
C OLUMN C1 2 11 T9
1

BC817-25 JP39
2

2
1
2

K5 D5 1
2 JP38
R25
12

34

C N6 LL4148 1
2 JP37
4k7

2
2 JP36
2 1
2
1
1

3
1 0V
JP68 21 JP25
2

1
2

1
10A/12Vdc R26
0V 4k7 T11
3

SPS T-NO 2 11
C OLUMN C2 BC817-25 JP20

2
T6 1 1 2 R27
BC817-25 4k7
2

2
R8

1
2
4k7 JP24 1
2 JP35
R16 0V

1
1
2
4k7
2

1
R28
C4 C7 0V 4k7 R42 R52 R53 R54 R59
0V JP50 21 T12 3k
2 11
5V100nF/50V 5V100n F/50V C OLUMN C3 3k 3k 3k 3k
1

B C817-25

2
JP55 21 5V JP70 21 JP71
24V 2 1 2 1 2
1
0V
JP69 21
2

R29

2
0V 0V
4k7

2
R40 JP23
1

11 4k7 7
2

Q8 Q4 0V

3
1
2

1
K6 D6 13 JP57 5 R35
Q6 Q2
0V
12

34

C N7 LL4148 4k7
1

14 1 JP58 1 6
C OLUMN C4 2 11 T13
2 Q5 STROBE STROBE Q3 BC817-25

2
2
1
2

1 JP59
1

1 4 2 2 4
2

Q1 DATA DATA Q1
R36
1
2

10A/12Vdc 5 3 3 14

ALARM OFF
4k7

2
Q2 CLOCK CLOCK Q5

TS61N-RA

TS61N-RA

TS61N-RA
3

2
SPS T-NO 5V

FREEZER
1
2

ON/OFF
JP22 C N11 C N13

FUTURE

FUTURE
6 15 15 13

DOOR
Q3 OE OE Q6 0V

3
1
2 2 2

SW2

SW4

SW6
1
T7 2 2
1 1 2 7 12 R37 1 1
BC817-25 Q4 JP67 Q7 1 1
2

0V 4k7
R9 12 11 2 11 T14
JP53 4k7 JP61 Q7 Q8 BC817-25

2
R17 C OLUMN C5

1
4k7 5V 5V
2

1
2

5V 10 16 16 10 R38
Qs VDD VDD Qs
4k7 SWITC HES GROUP B
1
2

1
2

2
0V
9 8 8 9
1

Qs VSS VSS Qs
2

0V
0V 0V 0V 1 1
2 JP21
R1 R2 R3 R10 IC2 IC4
1k2 12k 12k 1k2 MC 14094BDR2G MC 14094BDR2G 0V

BZ1 C2
PMK13EPYH4002-B0 C1 10n F/16V
1

10nF/16V
1 2 1 2 1
3

T1 1 1 T8
BC817-25 BC817-25
JP3 JP4
1
2

Figure 8 – circuit schematic


2

R11
JP2 47R
1
2

1
2

2 1
software design
supervisor automaton processing

A code snippet of the Process_Supervisor_S function is presented in Figure 9.


unsigned char Process_Supervisor_S(unsigned char qd, unsigned char e)
{
unsigned char i=0,j=0;

while (Qd[i] != qd) i++;


j=i;
while (E[j] != e) j++;

if (Qa[j] >= 128)


return Qa[j];
else
{
i=0;
while (Qd[i] != Qa[j]) i++;
t = Qd[i];

// set corresponding flag according to the task t = Qd[i]


if (t == 128) setbit(LOADS_BIT,0); // set flag "turn compressor on"
if (t == 129) setbit(LOADS_BIT,1); // set flag "turn compressor off"
return Qa[j];
}
}

Figure 9 – code snippet of the Process_Supervisor_S function

shift register update

A code snippet of the shift register update routine is presented in Figure 10.
void Send_To_SR(unsigned char SHIFT1, unsigned char SHIFT2)
{
unsigned char bit=16;
__disable_interrupt();
clearbit(PORTB,SRST); // Place STROBE = 0 to refresh data

do
{
__delay_cycles(48); // ~5us
if (bit <= 8)
{
// Place current data bit in SRDL
if ( checkbit(SHIFT2,bit-1) )
setbit(PORTB,SRDL);
else if ( !checkbit(SHIFT2,bit-1) )
clearbit(PORTB,SRDL);
}
else if (bit <= 16)
{
if ( checkbit(SHIFT1,bit-9) )
setbit(PORTB,SRDL);
else if (!checkbit(SHIFT1,bit-9))
clearbit(PORTB,SRDL);
}
__delay_cycles(48); // ~5us
// generate clock in SRCK
setbit(PORTB,SRCK);
__delay_cycles(48); // ~5us
clearbit(PORTB,SRCK);
} while (--bit);
__delay_cycles(48);

setbit(PORTB,SRST); // Place STROBE = 1 for normal operation


__enable_interrupt();
}

Figure 10 – code snippet of the shift register update routine


entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

switches reading

A code snippet of the switches reading routine is presented in Figure 11.


if (SCHEDULER_FLG.Sws_Reading_F) // "Switches Reading" routine
{
SCHEDULER_FLG.Sws_Reading_F=0;

SR1_BIT = 1; // Evaluate column 1


Send_To_SR(SR1_BIT,SR2_BIT);
__delay_cycles(1920); // ~200us
SWITCHES1_BYT = ADC_Read(1);

if ((SWITCHES1_BYT >= 115)&(SWITCHES1_BYT <= 192)) // Group A


setbit(SWITCHES2_BIT,7);
else
clearbit(SWITCHES2_BIT,7);
if ((SWITCHES1_BYT >= 85)&(SWITCHES1_BYT <= 115)) // Group B
setbit(SWITCHES2_BIT,6);
else
clearbit(SWITCHES2_BIT,6);

SR1_BIT = 16; // Evaluate column 2


Send_To_SR(SR1_BIT,SR2_BIT);
__delay_cycles(1920); // ~200us
SWITCHES1_BYT = ADC_Read(1);

if ((SWITCHES1_BYT >= 115)&(SWITCHES1_BYT <= 192)) // Group A


setbit(SWITCHES2_BIT,5);
else
clearbit(SWITCHES2_BIT,5);
if ((SWITCHES1_BYT >= 85)&(SWITCHES1_BYT <= 115)) // Group B
setbit(SWITCHES2_BIT,4);
else
clearbit(SWITCHES2_BIT,4);

SR1_BIT = 32; // Evaluate column 3


Send_To_SR(SR1_BIT,SR2_BIT);
__delay_cycles(1920); // ~200us
SWITCHES1_BYT = ADC_Read(1);

if ((SWITCHES1_BYT >= 115)&(SWITCHES1_BYT <= 192)) // Group A


setbit(SWITCHES2_BIT,3);
else
clearbit(SWITCHES2_BIT,3);
if ((SWITCHES1_BYT >= 85)&(SWITCHES1_BYT <= 115)) // Group B
setbit(SWITCHES2_BIT,2);
else
clearbit(SWITCHES2_BIT,2);

SR1_BIT = 64; // Evaluate column 4


Send_To_SR(SR1_BIT,SR2_BIT);
__delay_cycles(1920); // ~200us
SWITCHES1_BYT = ADC_Read(1);

if ((SWITCHES1_BYT >= 115)&(SWITCHES1_BYT <= 192)) // Group A


setbit(SWITCHES2_BIT,1);
else
clearbit(SWITCHES2_BIT,1);
if ((SWITCHES1_BYT >= 85)&(SWITCHES1_BYT <= 115)) // Group B
setbit(SWITCHES2_BIT,0);
else
clearbit(SWITCHES2_BIT,0);

// Column 5 is not implemented yet (future developments)

// Evaluate debounce
if (SWITCHES3_BIT != SWITCHES2_BIT) DEBOUNCE_CNT=0;

SWITCHES3_BIT = SWITCHES2_BIT;

if (!SWITCHES3_BIT) DEBOUNCE_CNT=0;

if (DEBOUNCE_CNT == 80)
{
SWITCHES4_BIT = SWITCHES3_BIT;
DEBOUNCE_CNT++;
}

if (SWITCHES4_BIT == 128) togglebit(SR2_BIT,5);

9 / 10
entry # AT3403 - think locally, solve globally: an interesting approach to design embedded controls

if (SWITCHES4_BIT == 64) togglebit(SR2_BIT,4);


if (SWITCHES4_BIT == 32) togglebit(SR2_BIT,0);
if (SWITCHES4_BIT == 16) togglebit(SR2_BIT,1);
if (SWITCHES4_BIT == 8) togglebit(SR2_BIT,2);
if (SWITCHES4_BIT == 4) togglebit(SR2_BIT,6);

SWITCHES4_BIT=0;

}
Figure 11 – code snippet of the switches reading routine
references

[1]. Atmel PDFs containing the AVR microcontroller specifications and diverse programming tips.
[2]. Cassandras, C. G. and Lafortune, S. (1999). Introduction to Discrete Event Systems, 2nd Ed,
Kluwer Academic Publishers, Massachussetts.
[3]. de Queiroz, M. H. and Cury, J. E. R. (2002). Synthesis and Implementation of Local Modular
Supervisory Control for a Manufacturing Cell, 6th International Workshop on Discrete Event
Systems (WODES), v. 1, p. 377-382, Saragoza.
[4]. Raymond, D. and Wood, D. (1995). Grail: A C++ library for automata and expressions, Journal
of Symbolic Computation, 11, pp. 341-350.
[5]. Wonham, W. M. (2005). Supervisory Control of Discrete-Event Systems, Technical Report,
Dept. of Electrical and Computer Engineering, University of Toronto. ECE 1636F/1637S 2005-
06, [Link]
[6]. Zhang, Z.H. and Wonham, W.M., STCT: (2001). An Efficient Algorithm for Supervisory
Control Design, Symposium on Supervisory Control of Discrete Event Systems (SCODES2001),
Paris, 12 pp.
[7]. Teixeira, C. A., Leal, A. B., de Sousa, A. H. (2006). Implementação de Supervisores em
Microcontroladores: Uma Abordagem Baseada na Teoria de Sistemas a Eventos Discretos,
Congresso Brasileiro de Automática (CBA’2006), Salvador, Brasil.

10 / 10

You might also like