AzofeifaJ / Proyecto-3-Dise-o-L-gico

En este repositorio se lleva a cabo el proceso de diseño del tercer proyecto del curso diseño lógico
MIT License
0 stars 0 forks source link

Segunda fase - Codificación del Algoritmo Booth #5

Open JoseDavidL opened 1 year ago

JoseDavidL commented 1 year ago

Descripción

Se muestra los códigos realizados de cada sección del desarrollo del circuito

JoseDavidL commented 1 year ago

Código Subsistema lectura de datos

module subsistemaLectura (reloj, reinicio, operandoEntradaA, operandoEntradaB, iniciarMultiplicacion, operandoSalidaA, operandoSalidaB, ledOperandoA, ledOperandoB, banderaValida);
    input reloj;
    input reinicio;
    input[3:0] operandoEntradaA;
    input[3:0] operandoEntradaB;
    input iniciarMultiplicacion;
    output[3:0] operandoSalidaA;
    output[3:0] operandoSalidaB;
    output ledOperandoA;
    output ledOperandoB;
    output banderaValida;

    always @(posedge reloj) begin
        if (reinicio == 1'b0) begin
            if (iniciarMultiplicacion == 1'b1) begin
                operandoSalidaA = operandoEntradaA;
                operandoSalidaB = operandoEntradaB;
                ledOperandoA = 1'b0;
                ledOperandoB = 1'b0;
                banderaValida = 1'b1;
            end
            else begin
                operandoSalidaA = 4'b0000;
                operandoSalidaB = 4'b0000;
                ledOperandoA = 1'b1;
                ledOperandoB = 1'b1;
                banderaValida = 1'b0;
            end
        end
        else begin
            operandoSalidaA = 4'b0000;
            operandoSalidaB = 4'b0000;
            ledOperandoA = 1'b1;
            ledOperandoB = 1'b1;
            banderaValida = 1'b0;
        end
    end
endmodule 
JoseDavidL commented 1 year ago

Código de Subsistema de cálculo de multiplicación

typedef struct {
    logic load_A;
    logic load_B;
    logic load_add;
    logic shift_HQ_LQ_Q_1;
    logic add_sub;
} mult_control_t;

module subsistemaMultiplicacion (reloj, reinicio, operandoA, operandoB, banderaValida, controladorMult, resultado, banderaLista);
    input reloj;
    input reinicio;
    input[3:0] operandoA;
    input[3:0] operandoB;
    input banderaValida;
    input mult_control_t controladorMult;
    output[7:0] resultado;
    output banderaLista;

    logic[7:0] M;
    logic[7:0] adder_sub_out;
    logic[16:0] shift;
    logic[7:0] HQ;
    logic[7:0] LQ;
    logic Q_1;
    reg[2:0] qlsb;
    reg[3:0] A;
    reg[3:0] B;
    reg[7:0] Y;

    always_ff @(posedge reloj) begin
        if (reinicio == 1'b1) begin
            M <= 8'b00000000;
        end
        else begin
            if (controladorMult.load_A) begin
                M <= A;
            end
            else begin
                M <= M;
            end
        end
    end

    always_comb begin
        if (controladorMult.add_sub) begin
            adder_sub_out = M + HQ;
        end
        else begin
            adder_sub_out = M - HQ;
        end
    end

    always_comb begin
        Y = {HQ,LQ};
        HQ = shift[16:9];
        LQ = shift[8:1];
        Q_1 = shift[0];
        qlsb = {LQ[0], Q_1};
    end

    always_ff @(posedge reloj) begin
        if (reinicio == 1'b1) begin
            shift <= 'b0;
        end
        else if (controladorMult.shift_HQ_LQ_Q_1) begin
            shift <= $signed(shift)>>>1;
        end
        else begin
            if (controladorMult.load_B) begin
                shift[8:1] <= B;
            end
            if (controladorMult.load_add) begin
                shift[16:9] <= adder_sub_out;
            end
        end
    end

    always @(posedge reloj) begin
        if (reinicio == 1'b0) begin
            if (banderaValida == 1'b1) begin
                resultado = operandoA*operandoB;
                banderaLista = 1'b1;
            end
            else begin
                resultado = 8'b00000000;
                banderaLista = 1'b0;
            end
        end
        else begin
            resultado = 8'b00000000;
            banderaLista = 1'b0;
        end
    end

endmodule 
JoseDavidL commented 1 year ago

Hacer consultas sobre el tamaño de la cantidad del números representados en el panel de 7 segmentos

JoseDavidL commented 1 year ago

Código de subsistema conversión binario a representación BCD

module subsistemaConversion (reloj, reinicio, resultadoEntrada, banderaLista, bcd, banderaConvertida);
    input reloj;
    input reinicio;
    input[7:0] resultadoEntrada;
    input banderaLista;
    output[12:0] bcd;
    output banderaConvertida;

    reg[11:0] bcd;
    reg[3:0] i;   

    always @(posedge reloj) begin
        if (reinicio == 1'b0) begin
            if (banderaLista == 1'b1) begin
                bcd = 0;
                for (i = 0; i < 8; i = i+1) begin
                    bcd = {bcd[10:0], resultadoEntrada[7-i]};
                    if(i < 7 && bcd[3:0] > 4) begin
                        bcd[3:0] = bcd[3:0] + 3;
                    end
                    if(i < 7 && bcd[7:4] > 4) begin
                      bcd[7:4] = bcd[7:4] + 3;
                    end
                    if(i < 7 && bcd[11:8] > 4) begin
                      bcd[11:8] = bcd[11:8] + 3;
                    end
                end
                banderaConvertida = 1'b1;
            end
            else begin
                bcd = 12'b000000000000;
                banderaConvertida = 1'b0;
            end
        end
        else begin
            bcd = 12'b000000000000;
            banderaConvertida = 1'b0;
        end
    end

endmodule 
JoseDavidL commented 1 year ago

Código de subsistema de despliegue en display de 7 segmentos

module subsistemaDisplay (reloj, reinicio, resultadoBCD, banderaConvertida, sieteSegmentosA, sieteSegmentosB, sieteSegmentosC);
    input reloj;
    input reinicio;
    input[11:0] resultadoBCD;
    input banderaConvertida;
    output[6:0] sieteSegmentosA;
    output[6:0] sieteSegmentosB;
    output[6:0] sieteSegmentosC;

    always @(posedge reloj) begin
        if (reinicio == 1'b0) begin
            if (banderaConvertida == 1'b1) begin
                case (resultadoBCD[3:0]) 
                    4'b0000: sieteSegmentosA = 7'b1111111; //0
                    4'b0001: sieteSegmentosA = 7'b1001111; //1
                    4'b0010: sieteSegmentosA = 7'b0010010; //2
                    4'b0011: sieteSegmentosA = 7'b0000110; //3
                    4'b0100: sieteSegmentosA = 7'b1001100; //4
                    4'b0101: sieteSegmentosA = 7'b0100100; //5
                    4'b0110: sieteSegmentosA = 7'b0100000; //6
                    4'b0111: sieteSegmentosA = 7'b0001111; //7
                    4'b1000: sieteSegmentosA = 7'b0000000; //8
                    4'b1001: sieteSegmentosA = 7'b0001100; //9
                endcase
                case (resultadoBCD[7:4]) 
                    4'b0000: sieteSegmentosB = 7'b1111111; //0
                    4'b0001: sieteSegmentosB = 7'b1001111; //1
                    4'b0010: sieteSegmentosB = 7'b0010010; //2
                    4'b0011: sieteSegmentosB = 7'b0000110; //3
                    4'b0100: sieteSegmentosB = 7'b1001100; //4
                    4'b0101: sieteSegmentosB = 7'b0100100; //5
                    4'b0110: sieteSegmentosB = 7'b0100000; //6
                    4'b0111: sieteSegmentosB = 7'b0001111; //7
                    4'b1000: sieteSegmentosB = 7'b0000000; //8
                    4'b1001: sieteSegmentosB = 7'b0001100; //9
                endcase
                case (resultadoBCD[11:8])
                    4'b0000: sieteSegmentosC = 7'b1111111; //0
                    4'b0001: sieteSegmentosC = 7'b1001111; //1
                    4'b0010: sieteSegmentosC = 7'b0010010; //2
                    4'b0011: sieteSegmentosC = 7'b0000110; //3
                    4'b0100: sieteSegmentosC = 7'b1001100; //4
                    4'b0101: sieteSegmentosC = 7'b0100100; //5
                    4'b0110: sieteSegmentosC = 7'b0100000; //6
                    4'b0111: sieteSegmentosC = 7'b0001111; //7
                    4'b1000: sieteSegmentosC = 7'b0000000; //8
                    4'b1001: sieteSegmentosC = 7'b0001100; //9
                endcase
            end
            else begin
                sieteSegmentosA = 7'b1111111;
                sieteSegmentosB = 7'b1111111;
                sieteSegmentosC = 7'b1111111;
            end
        end
        else begin
            sieteSegmentosA = 7'b1111111;
            sieteSegmentosB = 7'b1111111;
            sieteSegmentosC = 7'b1111111;
        end
    end
endmodule