codewarrior453
codewarrior453

Reputation: 83

Eight Bit Divider: Quotient and Remainder

I am trying to debug my code shown below. I am fairly new to SystemVerilog and hopefully I can learn from this. Let me know of any suggestions.

The errors I am receiving are:

Error-[ICPD] Invalid procedural driver combination
"divide.v", 2
Variable "Q" is driven by an invalid combination of procedural drivers. 
Variables written on left-hand of "always_comb" cannot be written to by any 
other processes, including other "always_comb" processes.
"divide.v", 2: logic [7:0] Q;
"divide.v", 8: always_comb  begin
if (x <= R) begin
...
"divide.v", 5: Q = 8'b0;

Error-[ICPD] Invalid procedural driver combination 
"divide.v", 2
Variable "R" is driven by an invalid combination of procedural drivers. 
Variables written on left-hand of "always_comb" cannot be written to by any 
other processes, including other "always_comb" processes.
"divide.v", 2: logic [7:0] R;
"divide.v", 8: always_comb  begin
if (x <= R) begin
...
"divide.v",6: R = y;

My SystemVerilog Code is:

module divider(input  logic [7:0] x,y,
               output logic [7:0] Q,R);
  initial
    begin
      Q = 8'd0;
      R = y;
    end
  always_comb
    begin
      if (x<=R)
        begin R <= R - x; Q <= Q + 8'd1; end
    end
endmodule

module test1; 

  logic [7:0] x,y,Q,R;

  divider Divider1 (x,y,Q,R);

  initial 
    begin
      x = 8'd2;
      y = 8'd8;
    end
endmodule

Upvotes: 0

Views: 4518

Answers (2)

Ari
Ari

Reputation: 7556

Generally, in Verilog/SystemVerilog you cannot assign to a variable from two parallel blocks (with some exceptions). You are assigning to R and Q from two places: the initial block and the always_comb block.

Although the initial block only runs once, it runs in parallel with the always_comb block at the beginning of the simulation, which is a violation of this rule.

Why don't you get rid of the initial block and do everything in always_comb?

   always_comb
    begin
      Q = 8'd0;     // set initial value of Q
      R = y;        // set initial value of R
      ....          //THE REST OF THE ALGORITHM
    end

Also, you are missing using a loop!

Upvotes: 3

Unn
Unn

Reputation: 5108

An important distinction between writing System Verilog (or any HDL) and writing in any software language (C/C++, Java, etc) is that System Verilog is designed to facilitate describing hardware structures while allowing for software-like testbenches, while software languages are designed to allow users to give instructions to an interpreter, VM or actual hardware. That being said, you need to think first about the hardware you are trying to describe and then write the associated HDL code. There are numerous posts describing the differences between HDLs and software languages (ex: Can Verilog/Systemverilog/VHDL be considered actor oriented programming languages?).

Looking at your code and flow chart you were given, it appears you are trying to use System Verilog as a programming language rather than a HDL. For example, initial blocks are generally only used in test benches and not in modules themselves. Also, as your algorithm is sequential, it is likely you will need a clock signal and registers, but the way your code lacks both.

Ideally, you should have a good idea of how to design digital hardware systems before trying to code any HDL, as this is the mentality you should have using HDLs. The goal is generally to translate a hardware design into HDL, so understanding digital design will help clarify alot.

Upvotes: 1

Related Questions