-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSegAdder.v
66 lines (57 loc) · 1.04 KB
/
SegAdder.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
module SegAdder(
clk,
rst_n,
opt_add,
opt_dec,
sig_add,
sig_dec,
data_out
);
parameter DATA_FORMAT = 4'D10;
parameter ORG_VALUE = 4'D0;
input clk;
input rst_n;
input opt_add;
input opt_dec;
output sig_add;
output sig_dec;
output[7:0] data_out;
reg sig_add;
reg sig_dec;
reg [3:0] cur_cal;
wire[1:0] opt_line;
SegDrv m_seg(
.clk (clk),
.rst_n (rst_n),
.data_in (cur_cal),
.data_out(data_out)
);
assign opt_line = {opt_add, opt_dec};
always@(posedge clk or negedge rst_n) begin
if(!rst_n) begin
cur_cal <= ORG_VALUE;
sig_add <= 1'B0;
sig_dec <= 1'B0;
end else begin
sig_add <= 1'B0;
sig_dec <= 1'B0;
casex(opt_line)
2'B1x:
if(cur_cal == (DATA_FORMAT - 1'B1)) begin
cur_cal <= 1'B0;
sig_add <= 1'B1;
end else begin
cur_cal <= cur_cal + 1'B1;
end
2'B01:
if(cur_cal == 1'B0) begin
cur_cal <= DATA_FORMAT - 1'B1;
sig_dec <= 1'B1;
end else begin
cur_cal <= cur_cal - 1'B1;
end
default:;
endcase
end
end
endmodule