-
Notifications
You must be signed in to change notification settings - Fork 0
/
division_half.v
51 lines (51 loc) · 944 Bytes
/
division_half.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
module division_half
#(
parameter MUL_2 = 9
)
(
input clk,rst,
output cnt_pos_w,cnt_neg_w,
output [4:0] cnt_w,
output clk_o
);
reg [4:0] cnt;
reg cnt_neg;
reg cnt_pos;
assign cnt_pos_w = cnt_pos;
assign cnt_neg_w = cnt_neg;
assign cnt_w = cnt;
//counter
always @( posedge clk , negedge rst) begin
if(!rst)
begin
cnt <= 3'b0;
end
else if (cnt == MUL_2-1)
begin
cnt <= 3'b0;
end
else begin
cnt <= cnt +1;
end
end
//
always @( posedge clk , negedge rst) begin
if(!rst)
begin
cnt_pos <= 3'b1;
end
else if (cnt == 1 || cnt == 8|| cnt == 3|| cnt == 6 ) begin
cnt_pos <= ~cnt_pos;
end
end
always @( negedge clk , negedge rst) begin
if(!rst)
begin
cnt_neg <= 3'b1;
end
else if (cnt == 2 || cnt == 4||cnt == 6 || cnt == 8) begin
cnt_neg <= ~cnt_neg;
end
end
assign clk_o = cnt_neg & cnt_pos;
endmodule