1
00:00:01,220 --> 00:00:08,570
How can we describe an officer in this lecture, explain the template code and coding style to describe

2
00:00:08,570 --> 00:00:10,340
an FSM in each of us?

3
00:00:11,490 --> 00:00:15,730
Most of the practical sequential circuits can be described with FSR.

4
00:00:17,520 --> 00:00:23,370
We are already familiar with the essential elements in an officer to describe an officer in us, we

5
00:00:23,370 --> 00:00:24,900
need a C C++ function.

6
00:00:26,080 --> 00:00:32,710
An enumeration data type can define all the states using the FSM on their description, then we need

7
00:00:32,710 --> 00:00:37,990
to define a set of static variables as registers to define states in deficit.

8
00:00:39,760 --> 00:00:44,830
Responding to each state, we define a variable to represent the next state's value.

9
00:00:47,200 --> 00:00:52,840
The idea is that we are not going to change the register value several times throughout the code, therefore,

10
00:00:52,990 --> 00:00:59,380
as a coding ASI, we define the next state variables and change them throughout the function and at

11
00:00:59,380 --> 00:01:02,160
the end we assign them to the state registers.

12
00:01:02,980 --> 00:01:07,330
Then we define a variable corresponding to each output argument in the function.

13
00:01:07,840 --> 00:01:14,050
Again, we modify these variables as the output value and assign them to the output arguments at the

14
00:01:14,050 --> 00:01:17,220
end of the function at the heart of the function.

15
00:01:17,230 --> 00:01:22,510
Buddy, we have a switch case statement that defines all the FSM transitions.

16
00:01:22,810 --> 00:01:26,900
At the end of the function, we modify the state registers and assigned outputs.

17
00:01:27,520 --> 00:01:33,340
Let's explain how to use this template to describe our combination lock example explained earlier in

18
00:01:33,340 --> 00:01:33,820
the section.

19
00:01:37,210 --> 00:01:43,240
As explained in the previous lectures, our combination lock should find the sequence of two, three,

20
00:01:43,240 --> 00:01:46,710
four and six through five states to open the lock.

21
00:01:47,110 --> 00:01:49,960
Let's write the code for this combination lock.

22
00:01:51,480 --> 00:01:58,440
First, it is a good practice to define an enumeration type to represent all the states, then we should

23
00:01:58,440 --> 00:02:04,560
define the design of function, which receives one form with input and generates a binary output.

24
00:02:05,740 --> 00:02:08,380
We can have the function arguments interfaces now.

25
00:02:10,150 --> 00:02:16,780
Registers represent the Sukkoth states in this example, we need one state to register that can be defined

26
00:02:16,780 --> 00:02:20,310
using the C static variable according to our template.

27
00:02:20,710 --> 00:02:25,040
Now we should define a variable that holds the next value of the circus.

28
00:02:25,040 --> 00:02:25,690
States register.

29
00:02:27,300 --> 00:02:32,880
Know that this technique prevents changing the registered value several times throughout the code.

30
00:02:34,320 --> 00:02:38,670
Now, let's define a variable that holds the output value throughout the code.

31
00:02:39,120 --> 00:02:45,210
Again, this variable prevents assigning different values to the function argument several times throughout

32
00:02:45,210 --> 00:02:45,690
the code.

33
00:02:48,050 --> 00:02:52,040
Now we need to each case a statement to represent the state transitions.

34
00:02:53,290 --> 00:02:59,200
The suitcase has five cases and a default, if you are in a state that's zero and the input is two,

35
00:02:59,380 --> 00:03:05,200
then the next state would be as to otherwise the next state is zero.

36
00:03:06,540 --> 00:03:12,080
If you are in the states, too, and the input is three, then the next state would be as two three,

37
00:03:12,540 --> 00:03:15,290
otherwise the next state is as zero.

38
00:03:16,430 --> 00:03:22,910
If you are in a state as two, three and then put is four, then the next state would be as two, three,

39
00:03:22,910 --> 00:03:26,650
four, otherwise the next state is a zero.

40
00:03:27,380 --> 00:03:32,870
If you are in a state as two, three, four and the input is six, then the next state would be two,

41
00:03:32,870 --> 00:03:33,920
three, four, six.

42
00:03:34,100 --> 00:03:36,170
Otherwise the next state is a zero.

43
00:03:36,930 --> 00:03:43,160
If you are in state as two, three, four, six, then the door is open and the second stays in that

44
00:03:43,160 --> 00:03:45,730
state until somebody locked the door again.

45
00:03:46,220 --> 00:03:51,200
Note that for the sake of simplicity, the lock mechanism is not shown in the scope.

46
00:03:53,190 --> 00:03:58,410
Finally, we should change the design of state and assigned output value to the corresponding function

47
00:03:58,410 --> 00:03:58,980
arguments.

48
00:04:00,540 --> 00:04:05,340
In the next lecture, I will explain how to synthesize the scope inviter Satchel's.

49
00:04:07,540 --> 00:04:14,080
These are our takeaway messages, we use a static variables in C to define the states in our telescope.

50
00:04:14,560 --> 00:04:19,350
It is a good practice not to change the static registers several times throughout the code.

51
00:04:19,570 --> 00:04:25,380
So defining nextstep that variables to keep the intermediate state value is a promising technique.

52
00:04:27,310 --> 00:04:32,670
An input signal to our combination lock circuit that resets the state machine and locks the door.
