0% found this document useful (0 votes)
33 views4 pages

21 FSM Examples

The document describes a finite state machine (FSM) that reduces a stream of binary inputs to a single output bit by detecting when at least two consecutive 1s have occurred in the input stream. The FSM uses one bit of state to track whether zero, one, or two or more 1s have been seen. It provides state transition diagrams and logic expressions for the next state logic and output logic. Verilog code is presented to implement the FSM with one or two state bits and with the next state logic and output logic combined or separated.

Uploaded by

vikramkolanu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
33 views4 pages

21 FSM Examples

The document describes a finite state machine (FSM) that reduces a stream of binary inputs to a single output bit by detecting when at least two consecutive 1s have occurred in the input stream. The FSM uses one bit of state to track whether zero, one, or two or more 1s have been seen. It provides state transition diagrams and logic expressions for the next state logic and output logic. Verilog code is presented to implement the FSM with one or two state bits and with the next state logic and output logic combined or separated.

Uploaded by

vikramkolanu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

)

!
" # $%#

!
!
!
&

* #

'

!
" # $% (
" # $%
*
)
+ *

)
)

#
#

*0

"

,
4

2,

*
%
%
%

1,

" #$ (
3

*
current
next
reset state
input state

#
#

A/0
reset

0
1

D/1

1
0
0
0
0
0
0
0
0

B/0

C/0

A
A
B
B
C
C
D
D

0
1
0
1
0
1
0
1

current
output

A
A
B
A
C
A
D
A
D

0
0
0
0
0
0
0
1
1

.
*

'! -

reset

D/1
1

1,
78

current
next
reset state
input state

B/0

1
0
1

C/0

"

0
A/0

5 ,

1
0
0
0
0
0
0
0
0

00
00
01
01
10
10
11
11

0
1
0
1
0
1
0
1

00
00
01
00
10
00
11
00
11

current
output
0
0
0
0
0
0
0
1
1

9'8

78

MSB+ = LIn + MIn

LSB+ = L'In + MIn

Out+ = ML

Notation
M := MSB
L := LSB
In := Input
2

2, #

* " # $%
;

MSB+ = LIn + MIn


AND2

PRN

MSB

CLRN

OR2

Out+ = ML

DFF
PRN

AND2

51

<

LSB

44

In

Out

53

AND2

In
MSB 52

AND2

Reset

45

!#

47

48
41

LSB

&
#

DFF

OR2

AND2

NOT

*2
*

In
MSB 43
In
LSB

CLRN

LSB+ = L'In + MIn

Clock

42

Reset

&
:

*
#

-, ! -

present
state
0

Reset

&
&
&

inputs
D N
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1

S0

&

%
# $< 3
# $#

S7

[open]

S2

S1

S5

S4

S3
N

[open]

[open]

S6

10

[open]

D
S8

[open]

15

next
state
0
5
10

5
10
15

10
15
15

15

present
output
0
0
0

0
0
0

0
0
0

#
<

( !

1
1-

#
>

&

<
3

>
< 83
2>
?# @

"

&

<
2>

#
*
3

present state inputs


Q0 Q1
D N
0 0
0 0
0 1
1 0
1 1
0 1
0 0
0 1
1 0
1 1
1 0
0 0
0 1
1 0
1 1
1 1

next state present


P1 P0
output
0 0
0
0 1
0
1 0
0

0 1
0
1 0
0
1 1
0

1 0
0
1 1
0
1 1
0

1 1
1

1,

K-map for P1

K-map for P0

Q1Q0
Q1
DN 00 01 11 10
00 0 0 1 1

01 0 1

1 1

11 X X

X X

10 1 1

1 1

2, #
K-map for Open

Q1Q0
Q1
DN 00 01 11 10
00 0 1 1 0
N
D

01 1 0

1 1

11 X X

X X

10 0 1

1 1

Q0

Q1Q0
Q1
DN 00 01 11 10
00 0 0 1 0
N
D

01 0 0

1 0

11 X X

X X

10 0 0

1 0

Q0

P1 = Q1 + D + Q0N

Q0

if FFs do not have a reset pin then


A BC 83 8C <

P0 = Q0'N + Q0N' + Q1N + Q1D

P1 = reset'(Q1 + D + Q0N)

OPEN = Q1Q0

P0 = reset'(Q0'N + Q0N' + Q1N + Q1D)

A BC D
< 8 C <D8 C < 8 C 3
A < BC C
1

*
A <

! -!%<3 *

!-!
#

* /
%<3 * 0

Reset

Reset

A < BC C B/
C 838C <0
/
C D
<8C <D
8C <8C 30
*

*
D

0
[0]
N

N'D'

5
[0]
N

N'D'

10
[0]
N+D

N'D'

N'D'/0

N/0
5

D/0

N'D'/0

N/0
10

D/1

N'D'/0

N+D/1

15
[1]

/1

15

3
(

* *

" #$

)#

#
#
!

;
&

*-!
!

,!
!

)
-

#
#

/
)) #
/!

B
08 *
G*
*

*0
F

.
?@

.
?@

/,
*,% 9
G

?@
?@

?@

*)

" #

*)

40

always @(in or state)

`define zero 0
`define one1 1
`define two1s 2

case (state)
`zero:
// last input was a zero
begin
if (in) next_state = `one1;
else
next_state = `zero;
end
`one1:
// we've seen one 1
begin
if (in) next_state = `two1s;
else
next_state = `zero;
end
`two1s:
// we've seen at least 2 ones
begin
if (in) next_state = `two1s;
else
next_state = `zero;
end
endcase

module reduce (clk, reset, in, out);


input clk, reset, in;
output out;
reg out;
reg [2:1] state;
// state variables
reg [2:1] next_state;
always @(posedge clk)
if (reset) state = `zero;
else
state = next_state;

.
?@

?@

?@

*
#

always @(state)
case (state)
`zero: out = 0;
`one1: out = 0;
`two1s: out = 1;
endcase
endmodule

!+

*)

module reduce (clk, reset, in, out);


input clk, reset, in;
output out;
reg out;
reg state;
// state variables
reg next_state;
always @(posedge clk)
if (reset) state = `zero;
else
state = next_state;
always @(in or state)
case (state)
`zero:
// last input was a zero
begin
out = 0;
if (in) next_state = `one;
else
next_state = `zero;
end
`one:
// we've seen one 1
if (in) begin
next_state = `one; out = 1;
end else begin
next_state = `zero; out = 0;
end
endcase
endmodule

module reduce (clk, reset, in, out);


input clk, reset, in;
output out;
reg out;
reg state; // state variables
always @(posedge clk)
if (reset) state = `zero;
else
case (state)
`zero:
// last input was a zero
begin
out = 0;
if (in) state = `one;
else
state = `zero;
end
`one:
// we've seen one 1
if (in) begin
state = `one; out = 1;
end else begin
state = `zero; out = 0;
end
endcase
endmodule

#
!

You might also like