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

Subversion Repositories mod3_calc

[/] [mod3_calc/] [trunk/] [rtl/] [mod3.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 yanzixuan
module  mod3 (
2
    input   [ 7: 0] dat_i,
3
    output  [ 1: 0] reminder
4
    );
5
 
6
    wire    [ 1: 0] dat_1, dat_2, dat_3, dat_4;
7
    wire    [ 1: 0] dat_5, dat_6;
8
 
9
    type_conv TC0(
10
        .plus_one(dat_i[0]),
11
        .minus_one(dat_i[1]),
12
        .dat_o(dat_1)
13
    );
14
 
15
    type_conv TC1(
16
        .plus_one(dat_i[2]),
17
        .minus_one(dat_i[3]),
18
        .dat_o(dat_2)
19
    );
20
 
21
    type_conv TC2(
22
        .plus_one(dat_i[4]),
23
        .minus_one(dat_i[5]),
24
        .dat_o(dat_3)
25
    );
26
 
27
    type_conv TC3(
28
        .plus_one(dat_i[6]),
29
        .minus_one(dat_i[7]),
30
        .dat_o(dat_4)
31
    );
32
 
33
    mod3_adder MA0(
34
        .din_a(dat_1), .din_b(dat_2),
35
        .dat_o(dat_5)
36
    );
37
 
38
    mod3_adder MA1(
39
        .din_a(dat_3), .din_b(dat_4),
40
        .dat_o(dat_6)
41
    );
42
 
43
    mod3_adder MA3(
44
        .din_a(dat_5), .din_b(dat_6),
45
        .dat_o(reminder)
46
    );
47
 
48
endmodule
49
//convert to signed data
50
module  type_conv (
51
    input   plus_one,
52
            minus_one,
53
    output  reg [ 1: 0] dat_o
54
    );
55
 
56
    always@(*)  begin
57
        case ({plus_one, minus_one})
58
            2'b00   :   dat_o   = 2'b00;
59
            2'b01   :   dat_o   = 2'b10;
60
            2'b10   :   dat_o   = 2'b01;
61
            2'b11   :   dat_o   = 2'b00;
62
            default :   dat_o   = 2'b00;
63
        endcase
64
    end
65
 
66
endmodule
67
 
68
//a qucik mod3 adder
69
module  mod3_adder (
70
    input   [ 1: 0] din_a, din_b,
71
    output  reg [ 1: 0] dat_o
72
    );
73
 
74
    always@(*)  begin
75
        case ({din_a, din_b})
76
            4'b00_00    :   dat_o   = 2'b00;
77
            4'b00_01    :   dat_o   = 2'b01;
78
            4'b00_10    :   dat_o   = 2'b10;
79
            4'b01_00    :   dat_o   = 2'b01;
80
            4'b01_01    :   dat_o   = 2'b10;
81
            4'b01_10    :   dat_o   = 2'b00;
82
            4'b10_00    :   dat_o   = 2'b10;
83
            4'b10_01    :   dat_o   = 2'b00;
84
            4'b10_10    :   dat_o   = 2'b01;
85
            default     :   dat_o   = 2'b00;
86
        endcase
87
    end
88
endmodule
89
 

powered by: WebSVN 2.1.0

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