-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2B.sv
47 lines (38 loc) · 1005 Bytes
/
P2B.sv
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
`include "sys_defs.svh"
module P2B(
input clock,
input reset,
input enable,
input in_val,
output reg [(`BIN_LEN - 1) : 0] out_val
);
reg [(`BIN_LEN - 1) : 0] n_out_val;
reg [(`BIN_LEN - 1) : 0] modulus_m;
wire storage_ld;
always@(posedge clock) begin
if(reset || storage_ld) begin
n_out_val = 0;
end else if(enable && in_val) begin
n_out_val = n_out_val + 1;
end
end
always@(clock) begin
if(reset) begin
modulus_m = 0;
end else if(enable) begin
if(storage_ld) begin
modulus_m = 0;
end else begin
modulus_m = modulus_m + 1;
end
end
end
assign storage_ld = (modulus_m == `LFSR_INIT_VAL - 1) ? 1 : 0;
always@(posedge clock) begin
if(reset) begin
out_val = 0;
end else if (enable && storage_ld) begin
out_val = n_out_val;
end
end
endmodule