Repository navigation
Expand file tree
/
Copy pathHelperModules.v
More file actions
106 lines (90 loc) · 2.96 KB
/
Copy pathHelperModules.v
File metadata and controls
106 lines (90 loc) · 2.96 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module speedControl(
input clk,
output pulse
);
parameter [26:0] data = 'd50000000;
reg [26:0] Q;
always@(posedge clk)
begin
if (Q == 27'b0)
begin
Q <= data;
end
else
begin
Q <= Q -1;
end
end
assign pulse = (Q == 0) ? 1 : 0;
endmodule
module seg7 (input [3:0] c, output [6:0] led );
assign led[0] = (~c[3] & ~c[2] & ~c[1] & c[0]) | (~c[3] & c[2] & ~c[1] & ~c[0]) | (c[3] & ~c[2] & c[1] & c[0]) | (c[3] & c[2] & ~c[1] & c[0]);
assign led[1] = (~c[3] & c[2] & ~c[1] & c[0]) | (~c[3] & c[2] & c[1] & ~c[0]) | (c[3] & ~c[2] & c[1] & c[0]) | (c[3] & c[2] & ~c[1] & ~c[0]) | (c[3] & c[2] & c[1] & ~c[0]) | (c[3] & c[2] & c[1] & c[0]);
assign led[2] = (~c[3] & ~c[2] & c[1] & ~c[0]) | (c[3] & c[2] & ~c[1] & ~c[0]) | (c[3] & c[2] & c[1] & ~c[0]) | (c[3] & c[2] & c[1] & c[0]);
assign led[3] = (~c[3] & ~c[2] & ~c[1] & c[0]) | (~c[3] & c[2] & ~c[1] & ~c[0]) | (~c[3] & c[2] & c[1] & c[0]) | (c[3] & ~c[2] & c[1] & ~c[0]) | (c[3] & c[2] & c[1] & c[0]);
assign led[4] = (~c[3] & ~c[2] & ~c[1] & c[0]) | (~c[3] & ~c[2] & c[1] & c[0]) | (~c[3] & c[2] & ~c[1] & ~c[0]) | (~c[3] & c[2] & ~c[1] & c[0]) | (~c[3] & c[2] & c[1] & c[0]) | (c[3] & ~c[2] & ~c[1] & c[0]);
assign led[5] = (~c[3] & ~c[2] & ~c[1] & c[0]) | (~c[3] & ~c[2] & c[1] & ~c[0]) | (~c[3] & ~c[2] & c[1] & c[0]) | (~c[3] & c[2] & c[1] & c[0]) | (c[3] & c[2] & ~c[1] & c[0]);
assign led[6] = (~c[3] & ~c[2] & ~c[1] & ~c[0]) | (~c[3] & ~c[2] & ~c[1] & c[0]) | (~c[3] & c[2] & c[1] & c[0]) | (c[3] & c[2] & ~c[1] & ~c[0]);
endmodule
module debugClock(clk, debug, newclk, KEY);
input clk;
input debug;
input [3:0] KEY;
output reg newclk;
always@(*) begin
if(~debug)
newclk = clk;
else
newclk = KEY[3];
end
endmodule
module lfsr (out, clk, rst);
output reg [3:0] out;
input clk, rst;
wire feedback;
assign feedback = ~(out[3] ^ out[2]);
always @(posedge clk, posedge rst)
begin
if (rst)
out = 4'b0;
else
out = {out[2:0],feedback};
end
endmodule
module binToBCD(
sourceValue,
Hundreds,
Tens,
Units
);
//input
input [7:0] sourceValue;
//outputs
output reg [3:0]Hundreds, Tens, Units;
integer count;
always @(sourceValue)//change to clock?
begin
//initialise/reset by default
Hundreds = 4'b0;
Tens = 4'b0;
Units = 4'b0;
//looping through all bits to apply bin to BCD conversion algorithm
for (count=7; count>=0; count=count-1)
begin
//add 3 to all columns bigger or equal to 5
if (Hundreds >= 5)
Hundreds = Hundreds + 3;
if (Tens >= 5)
Tens = Tens + 3;
if (Units >= 5)
Units = Units + 3;
//shift to the left by one
Hundreds = Hundreds << 1;
Hundreds[0] = Tens[3];
Tens = Tens << 1;
Tens[0] = Units[3];
Units = Units << 1;
Units[0] = sourceValue[count];
end
end
endmodule