forked from 412910609/galvoMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enc_filter.v
74 lines (66 loc) · 1.46 KB
/
enc_filter.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
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
module enc_filter
(
input sys_clk,
input filter_nrst,
input filter_en,
input enc_a_in,
input enc_b_in,
input enc_z_in,
output reg enc_a_out_r = 1'b0,
output reg enc_b_out_r = 1'b0,
output reg enc_z_out_r = 1'b0
);
reg[2:0] enc_a_r = 3'd0;
reg[2:0] enc_b_r = 3'd0;
reg[2:0] enc_z_r = 3'd0;
task initData;
begin
enc_a_r <= 3'b0;
enc_b_r <= 3'b0;
enc_z_r <= 3'b0;
end
endtask
always@(posedge sys_clk or negedge filter_nrst)
begin
if (!filter_nrst)
begin
initData;
end
else
begin
if (!filter_en)
begin
enc_a_out_r <= enc_a_in;
enc_b_out_r <= enc_b_in;
enc_z_out_r <= enc_z_in;
end
else
begin
enc_a_r <= {enc_a_r[1:0],enc_a_in};
enc_b_r <= {enc_b_r[1:0],enc_b_in};
enc_z_r <= {enc_z_r[1:0],enc_z_in};
case (enc_a_r)
3'b000: enc_a_out_r <= 1'd0;
3'b001: enc_a_out_r <= 1'd0;
3'b010: enc_a_out_r <= 1'd0;
3'b100: enc_a_out_r <= 1'd0;
default: enc_a_out_r <= 1'd1;
endcase
case (enc_b_r)
3'b000: enc_b_out_r <= 1'd0;
3'b001: enc_b_out_r <= 1'd0;
3'b010: enc_b_out_r <= 1'd0;
3'b100: enc_b_out_r <= 1'd0;
default: enc_b_out_r <= 1'd1;
endcase
case (enc_z_r)
3'b000: enc_z_out_r <= 1'd0;
3'b001: enc_z_out_r <= 1'd0;
3'b010: enc_z_out_r <= 1'd0;
3'b100: enc_z_out_r <= 1'd0;
default: enc_z_out_r <= 1'd1;
endcase
end
end
end
endmodule