Domanda

Sto cercando di scrivere un BCD Adder in Verilog, ma sto avendo problemi con uno dei moduli. Specificamente, il sommatore che prende due cifre BCD e li aggiunge. Così, l'idea è che se la somma delle due cifre è inferiore o uguale a nove, allora è corretto. Tuttavia, se è maggiore, allora un offset di 6 deve essere aggiunto. Ecco il mio codice Verilog finora:

module DIGITADD(
    input [3:0] IN_A,
    input [3:0] IN_B,
    input CIN,
    output reg COUT,
    output reg [3:0] SUM
);

wire s2, c2;

always @ ( * ) 
begin
 assign {c2, s2} = IN_A + IN_B + CIN;

 if(s2 <= 9 && c2 == 0) begin
  assign {COUT, SUM} = {c2, s2};
 end
 else if({c2, s2} > 9) begin
  assign {COUT, SUM} = {c2, s2 + 6};
 end
end
endmodule

In ogni modo, quando provo a sintetizzare in Xilinx, ottengo i seguenti errori:

ERRORE: HDLCompilers: 247 - "DIGITADD.v" linea 33 Riferimento al filo 'c2' scalare non è un registro legale o variabile lvalue

ERRORE: HDLCompilers: 247 - "DIGITADD.v" linea 33 Riferimento al filo di scalare 's2' non è un registro legale o variabile lvalue

ERRORE: HDLCompilers: 42 - line "DIGITADD.v" 33 Illegal lato sinistro assegnare procedurale

Ho provato a cambiare alcune cose come cambiare filo al reg, ma non riesco ancora a farlo funzionare. Ogni aiuto è apprezzato.

È stato utile?

Soluzione

Okay, I figured it out, the correct code is below. Basically, see the comment I made on my question for some tips to remember. Its funny how much simpler this is compared to the mess I had earlier.

module DIGITADD(
    input [3:0] IN_A,
    input [3:0] IN_B,
    input CIN,
    output COUT,
    output [3:0] SUM
    );

reg [4:0] s2;

assign SUM = s2[3:0];
assign COUT = s2[4];

always @ ( * )
begin
    s2 = IN_A + IN_B + CIN;
    if (s2 > 9)
    begin
        s2 = s2 + 6;
    end
end
endmodule 

Altri suggerimenti

In plain text, do not have a continuous assignment like "assign" statement in a procedural block i.e. always or initial.

Remember the rule and life is good :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top