-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequencer.sv
More file actions
76 lines (66 loc) · 1.16 KB
/
sequencer.sv
File metadata and controls
76 lines (66 loc) · 1.16 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module sequencer (input logic start, clock, Q0, n_rst,
output logic add, shift, ready, reset);
enum {idle,adding,shifting,stopped} present_state, next_state;
logic [3:0]count = 4;
always_ff @(posedge clock, negedge n_rst)
begin: SEQ
if (~n_rst)
begin
count <= 4;
present_state <= idle;
end
else
begin
if (present_state == adding)
count <= count - 1;
if (present_state == idle)
count <= 4;
present_state <= next_state;
end
end
always_comb
begin: COM
reset = '0;
add = '0;
shift= '0;
ready = '0;
next_state = present_state;
unique case (present_state)
idle: begin
ready = '0;
reset = '1;
if (start)
next_state = adding;
end
adding: begin
reset = '0;
shift = '0;
if (count == 0)
next_state = stopped;
else
next_state = adding;
if (Q0)
add = '1;
else
begin
add = '0;
shift = '1;
end
end
shifting: begin
add = '0;
shift = '1;
if (count == 0)
next_state = stopped;
else
next_state = adding;
end
stopped: begin
shift = '0;
ready = '1;
if (start)
next_state = idle;
end
endcase
end
endmodule