-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp156.v
37 lines (33 loc) · 969 Bytes
/
p156.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module top_module (
input clk,
input reset, // Synchronous reset
input data,
output shift_ena,
output counting,
input done_counting,
output done,
input ack );
enum {A, B, C, D, E, F, G} state = A;
reg [1:0] counter = 0;
always @(posedge clk) begin
if (reset)
state <= A;
else begin
case (state)
A: state <= data == 1'b1 ? B : A;
B: state <= data == 1'b1 ? C : A;
C: state <= data == 1'b0 ? D : C;
D: state <= data == 1'b1 ? E : A;
E: begin
state <= counter == 3 ? F : E;
counter <= counter + 1;
end
F: state <= done_counting ? G : F;
G: state <= ack ? A : G;
endcase
end
end
assign shift_ena = state == E;
assign counting = state == F;
assign done = state == G;
endmodule