• No results found

Explicit Functional Description

Explicit functional descriptions of combinational circuits (Sect.1.2.1) are tables that define the output signal values associated to all possible combinations of input signal values. In the case of sequential circuits all possible internal states must also be considered: to different internal states correspond different relations between input and output signals.

4.3.1 State Transition Graph

A state transition graph consists of a set of vertices that correspond to the internal states and of a set of directed edges that define the internal state transitions and the output signal values in function of the input signal values.

Example 4.4 The graph of Fig.4.6b defines a sequential circuit (Fig.4.6a) that has three internal statesA, B, and C encoded with two binary variables q0andq1that are stored in the memory block; it has a binary input signalx and a binary output signal y. It works as follows:

• If the internal state isA and if x ¼ 0 then the next state is C and y ¼ 0.

• If the internal state isA and if x ¼ 1 then the next state is A and y ¼ 1.

• If the internal state isB then (whatever x) the next state is A and y ¼ 0.

• If the internal state isC and if x ¼ 0 then the next state is C and y ¼ 0.

• If the internal state isC and if x ¼ 1 then the next state is B and y ¼ 1.

To complete the combinational circuit (Fig.4.6a) specification it remains to choose the encoding of statesA, B, and C, for example:

A: q0q1¼ 00, B : q0q1¼ 01, C : q0q1¼ 10: ð4:3Þ The following case instruction defines the combinational circuit function:

Negative pulse Period=T

Frequency=1/T Positive edge

Positive pulse

cycle Negative edge

clock

Fig. 4.5 Clock signal

4.3 Explicit Functional Description 83

case q0q1is

The clock signal (Sect.4.2) is not represented in Fig.4.6a but it is implicitly present and it is responsible for the periodic updating of the internal state.

The way that the external output signal values are defined in Fig.4.6bcorresponds to the so-called Mealy model: the value ofy depends on the current internal state and on the current value of the input signalx. In the following example another method is used.

Example 4.5 The graph of Fig.4.7b. defines a sequential circuit (Fig.4.7a) that has three internal statesA, B, and C encoded with two binary variables q0andq1that are stored in the memory block; it has two binary input signalsx0andx1that encode a ternary digitx2 {0, 1, 2} and a binary output signaly. It works as follows:

• If the internal state isA and if x ¼ 0 then the next state is C and y ¼ 1.

Fig. 4.7 Example of state transition graph (Moore model)

x = 1; y = 1

Fig. 4.6 Example of state transition graph (Mealy model)

• If the internal state isA and if x ¼ 2 then the next state is B and y ¼ 1.

• If the internal state isB then (whatever x) the next state is A and y ¼ 0.

• If the internal state isC and if x ¼ 0 then the next state is C and y ¼ 1.

• If the internal state isC and if x ¼ 1 or 2 then the next state is B and y ¼ 1.

To complete the combinational circuit (Fig.4.7a) specification it remains to choose the encoding of statesA, B, and C, for example the same as before (4.3). The following case instruction defines the combinational circuit function:

case q0q1is

when 00¼> if x1x0¼ 00 then q0Δq1Δ ¼ 10;

elsif x1x0¼ 01 then q0Δq1Δ ¼ 00;

elsif x1x0¼ 10 then q0Δq1Δ ¼ 01;

else q0Δq1Δ ¼ don’t care; end if;

y¼ 1;

when 01¼> if x1x0¼ 11 then q0Δq1Δ ¼ don’t care;

else q0Δq1Δ ¼ 00; end if;

y¼ 0;

when 10¼> if x1x0¼ 00 then q0Δq1Δ ¼ 10;

elsif (x1x0¼ 01) or (x1x0¼ 10) then q0Δq1Δ ¼ 01;

else q0Δq1Δ ¼ don’t care; end if;

y¼ 1;

when others¼> q0Δq1Δ ¼ don’t care; y ¼ don’t care;

end case;

In this case, the value ofy only depends on the current internal state. It is the so-called Moore model: the value ofy only depends on the current internal state; it does not depend on the current value of the input signalsx0andx1.

To summarize, two graphical description methods have been described. In both cases it is a graph whose vertices correspond to the internal states of the sequential circuit and whose directed edges are labelled with the input signal values that cause the transition from a state to another. They differ in the way that the external output signals are defined.

• In the first case (Example4.4) the external output values are a function of the internal state and of the external input values. The directed edges are labelled with both the input signal values that cause the transition and with the corresponding output signal values. It is the Mealy model.

• In the second case (Example4.5) the external output values are a function of the internal state. The directed edges are labelled with the input signal values that cause the transition and the vertices with the corresponding output signal values. It is the Moore model.

Observe that a Moore model is a particular case of Mealy model in which all edges whose origin is the same internal state are labelled with the same output signal values. As an example the graph of Fig. 4.8 describes the same sequential circuit as the graph of Fig. 4.7b. Conversely it can be demonstrated that a sequential circuit defined by a Mealy model can also be defined by a Moore model but, generally, with more internal states.

4.3 Explicit Functional Description 85

4.3.2 Example of Explicit Description Generation

Given a functional specification of a sequential circuit, for example in a natural language, how can a state transition graph be defined? There is obviously no systematic and universal method to translate an informal specification to a state transition graph. It is mainly a matter of common sense and imagination. As an example, consider the circuit that controls a robot vacuum cleaner (the photo of a commercial robot is shown in Fig.4.9).

To make the example more tractable a simplified version of the robot is defined:

• The robot includes a sensor that generates a binary signalOB¼ 1 when it detects an obstacle in front of it.

• The robot can execute three orders under the control of two binary inputsLR (left rotate) and RR (right rotate): move forward (LR¼ RR ¼ 0), turn 90to the left (LR¼ 1, RR ¼ 0), and turn 90 to the right (LR¼ 0, RR ¼ 1).

The specification of the robot control circuit is the following:

• If there is no obstacle: move forward.

• When an obstacle is detected: turn to the right until there is no more obstacle.

• The next time an obstacle is detected: turn to the left until there is no more obstacle.

• The next time an obstacle is detected: turn to the right until there is no more obstacle, and so on.

This behavior cannot be implemented by a combinational circuit. In order to take a decision it is not enough to know whether there is an obstacle or not; it is necessary to know the latest ordered movements:

Fig. 4.9 Photo of a robot vacuum cleaner (courtesy of iRobot Corporation)

x = 1; y = 1

x = 2;

y = 1 x = 0; y = 1

x = 0, 1 or 2; y = 0

x = 1 or 2; y = 1

x = 0; y = 1 A

B C

Fig. 4.8 Mealy model of Fig.4.7b

• If the previous command was turn to the right and if there is no obstacle then move forward.

• If the previous command was turn to the right and there is still an obstacle then keep turning to the right.

• If the previous command was turn to the left and if there is no obstacle then move forward.

• If the previous command was turn to the left and there is still an obstacle then keep turning to the left.

• If the previous command was move forward and if there is no obstacle then keep moving forward.

• If the previous command was move forward and there is an obstacle and the latest rotation was to the left then turn to the right.

• If the previous command was move forward and there is an obstacle and the latest rotation was to the right then turn to the left.

This analysis suggests the definition of four internal states:

• SAL: The robot is moving forward and the latest rotation was to the left.

• SAR: The robot is moving forward and the latest rotation was to the right.

• SRR: The robot is turning to the right.

• SRL: The robot is turning to the left.

With those internal states the behavior of the robot control circuit is defined by the state transition graph of Fig.4.10b(Moore model).

To define the combinational circuit of Fig.4.10athe internal states of Fig.4.10bmust be encoded.

For example:

SAR : q0q1¼ 00, SRR: q0q1¼ 01, SAL: q0q1 ¼ 10, SRL: q0q1¼ 11: ð4:4Þ The following case instruction defines the combinational circuit function:

case q0q1is

Fig. 4.10 Robot control circuit

4.3 Explicit Functional Description 87

when 10¼> if OB ¼ 0 then q0Δq1Δ ¼ 10;

else q0Δq1Δ ¼ 01; end if;

RR¼ 0; RL ¼ 0;

when 11¼> if OB ¼ 0 then q0Δq1Δ ¼ 10;

else q0Δq1Δ ¼ 11; end if;

RR¼ 0; RL ¼ 1;

end case;

4.3.3 Next State Table and Output Table

Instead of defining the behavior of a sequential circuit with a state transition graph, another option is to use tables. Once the set of internal states is known, the specification of the circuit of Fig. 4.3 amounts to the specification of the combinational circuit, for example by means of two tables:

• A table (next state table) that defines the next internal state in function of the current state and of the external input values

• A table (output table) that defines the external output values in function of the current internal state (Moore model) or in function of the current internal state and of the external input values (Mealy model)

As an example, the state transition diagram of Fig.4.10bcan be described by Tables4.1and4.2.