OpenCores
URL https://opencores.org/ocsvn/mod3_calc/mod3_calc/trunk

Subversion Repositories mod3_calc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

/mod3_calc/trunk/rtl/mod3.v
0,0 → 1,89
module mod3 (
input [ 7: 0] dat_i,
output [ 1: 0] reminder
);
wire [ 1: 0] dat_1, dat_2, dat_3, dat_4;
wire [ 1: 0] dat_5, dat_6;
type_conv TC0(
.plus_one(dat_i[0]),
.minus_one(dat_i[1]),
.dat_o(dat_1)
);
type_conv TC1(
.plus_one(dat_i[2]),
.minus_one(dat_i[3]),
.dat_o(dat_2)
);
 
type_conv TC2(
.plus_one(dat_i[4]),
.minus_one(dat_i[5]),
.dat_o(dat_3)
);
 
type_conv TC3(
.plus_one(dat_i[6]),
.minus_one(dat_i[7]),
.dat_o(dat_4)
);
mod3_adder MA0(
.din_a(dat_1), .din_b(dat_2),
.dat_o(dat_5)
);
 
mod3_adder MA1(
.din_a(dat_3), .din_b(dat_4),
.dat_o(dat_6)
);
 
mod3_adder MA3(
.din_a(dat_5), .din_b(dat_6),
.dat_o(reminder)
);
endmodule
//convert to signed data
module type_conv (
input plus_one,
minus_one,
output reg [ 1: 0] dat_o
);
always@(*) begin
case ({plus_one, minus_one})
2'b00 : dat_o = 2'b00;
2'b01 : dat_o = 2'b10;
2'b10 : dat_o = 2'b01;
2'b11 : dat_o = 2'b00;
default : dat_o = 2'b00;
endcase
end
endmodule
 
//a qucik mod3 adder
module mod3_adder (
input [ 1: 0] din_a, din_b,
output reg [ 1: 0] dat_o
);
always@(*) begin
case ({din_a, din_b})
4'b00_00 : dat_o = 2'b00;
4'b00_01 : dat_o = 2'b01;
4'b00_10 : dat_o = 2'b10;
4'b01_00 : dat_o = 2'b01;
4'b01_01 : dat_o = 2'b10;
4'b01_10 : dat_o = 2'b00;
4'b10_00 : dat_o = 2'b10;
4'b10_01 : dat_o = 2'b00;
4'b10_10 : dat_o = 2'b01;
default : dat_o = 2'b00;
endcase
end
endmodule
/mod3_calc/trunk/tb/mod3_tb.v
0,0 → 1,34
module mod3_tb ();
reg [ 7: 0] dat_i;
reg [ 1: 0] comp;
reg [ 1: 0] err_cnt;
wire [ 1: 0] reminder;
initial begin
$display("------------------The self_check begin ------------------");
dat_i = 0;
err_cnt = 0;
repeat(256) begin
comp = dat_i % 3;
#5;
if (reminder != comp) begin
$display("comp = %d, calc data = %d", comp, reminder);
err_cnt = err_cnt + 1;
end
dat_i = dat_i + 1;
end
if (err_cnt == 0)
$display("------------------The self_check passed------------------");
else
$display("------------------The self_check failed------------------");
$stop;
end
 
mod3 M0(
.dat_i(dat_i),
.reminder(reminder)
);
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.