Add project 1
This commit is contained in:
31
Project1/hamming.v
Normal file
31
Project1/hamming.v
Normal file
@@ -0,0 +1,31 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
module hamming(
|
||||
input [11:0] code,
|
||||
output [7:0] data,
|
||||
output [3:0] syndrome
|
||||
);
|
||||
reg [3:0] rec_check, calc_check;
|
||||
reg [11:0] corrected_code;
|
||||
|
||||
always @* begin
|
||||
rec_check = { code[7], code[3], code[1], code[0] };
|
||||
|
||||
calc_check[0] = code[2] ^ code[4] ^ code[6] ^ code[8] ^ code[10];
|
||||
calc_check[1] = code[2] ^ code[5] ^ code[6] ^ code[9] ^ code[10];
|
||||
calc_check[2] = code[4] ^ code[5] ^ code[6] ^ code[11];
|
||||
calc_check[3] = code[8] ^ code[9] ^ code[10] ^ code[11];
|
||||
end
|
||||
|
||||
always@* begin
|
||||
corrected_code = code;
|
||||
if (syndrome > 0)
|
||||
corrected_code[syndrome - 1] = ~corrected_code[syndrome - 1];
|
||||
|
||||
end
|
||||
|
||||
assign syndrome = calc_check ^ rec_check;
|
||||
assign data = { corrected_code[11], corrected_code[10], corrected_code[9], corrected_code[8],
|
||||
corrected_code[6], corrected_code[5], corrected_code[4], corrected_code[2] };
|
||||
|
||||
endmodule
|
||||
48
Project1/hammingtb.v
Normal file
48
Project1/hammingtb.v
Normal file
@@ -0,0 +1,48 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
module hammingtb(
|
||||
);
|
||||
|
||||
reg [11:0] code;
|
||||
wire [7:0] data;
|
||||
wire [3:0] syndrome;
|
||||
|
||||
hamming h1 (.code(code), .data(data), .syndrome(syndrome));
|
||||
|
||||
initial
|
||||
begin
|
||||
$monitor ($time, " ns code=%b, data=%b, syndrome=%b", code, data, syndrome);
|
||||
code = 12'b0011_0100_1111;
|
||||
#10 code = 12'b1011_0100_1111;
|
||||
#10 code = 12'b0111_0100_1111;
|
||||
#10 code = 12'b0001_0100_1111;
|
||||
#10 code = 12'b0010_0100_1111;
|
||||
#10 code = 12'b0011_1100_1111;
|
||||
#10 code = 12'b0011_0000_1111;
|
||||
#10 code = 12'b0011_0110_1111;
|
||||
#10 code = 12'b0011_0101_1111;
|
||||
#10 code = 12'b0011_0100_0111;
|
||||
#10 code = 12'b0011_0100_1011;
|
||||
#10 code = 12'b0011_0100_1101;
|
||||
#10 code = 12'b0011_0100_1110;
|
||||
|
||||
#10 code = 12'b1111_0111_0111;
|
||||
#10 code = 12'b1111_0111_0110;
|
||||
#10 code = 12'b1111_0111_0101;
|
||||
#10 code = 12'b1111_0111_0011;
|
||||
#10 code = 12'b1111_0111_1111;
|
||||
#10 code = 12'b1111_0110_0111;
|
||||
#10 code = 12'b1111_0101_0111;
|
||||
#10 code = 12'b1111_0011_0111;
|
||||
#10 code = 12'b1111_1111_0111;
|
||||
#10 code = 12'b1110_0111_0111;
|
||||
#10 code = 12'b1101_0111_0111;
|
||||
#10 code = 12'b1011_0111_0111;
|
||||
#10 code = 12'b0111_0111_0111;
|
||||
|
||||
#10 code = 12'b0000_0000_0000;
|
||||
#10 $finish;
|
||||
end
|
||||
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user