-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathencode.v
More file actions
41 lines (35 loc) · 996 Bytes
/
Copy pathencode.v
File metadata and controls
41 lines (35 loc) · 996 Bytes
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
module calculate_val #(
parameter INPUT = 1
) (
input [4:0] value,
input [4:0] rotor,
output reg [4:0] out,
input [4:0] ring_position
);
reg signed [6:0] val = 7'b0000000;
always @*
begin
if (INPUT==1)
val = value - ring_position + rotor;
else
val = value + ring_position - rotor;
if (val < 0 ) val = val + 7'd26;
if (val > 7'd25) val = val - 7'd26;
out = val[4:0];
end
endmodule
module encode #(
parameter REVERSE = 0
) (
input [4:0] inputValue,
input [4:0] rotor,
output [4:0] outputValue,
input [2:0] rotor_type,
input [4:0] ring_position
);
wire [4:0] calculated_input;
wire [4:0] outval;
calculate_val #(.INPUT(1)) cinput(.value(inputValue),.rotor(rotor),.out(calculated_input),.ring_position(ring_position));
rotorEncode #(.REVERSE(REVERSE)) rotEncode(.code(calculated_input),.val(outval),.rotor_type(rotor_type));
calculate_val #(.INPUT(0)) coutput(.value(outval),.rotor(rotor),.out(outputValue),.ring_position(ring_position));
endmodule