0
\$\begingroup\$

I am working to create a daisy chain Flip Flop circuit (following the asynchronous method of connection).

The Q output of a flip flop acts as the clock for the next Flip Flop.

module dff(d,clk,q,qbar,rst);
input d,clk, rst;
output reg q, qbar;
always@(posedge clk)
if(rst) begin q<=0; qbar<=1; end
else begin q<=d; qbar<=~d; end
endmodule

module dffchain(d,clk,q,qbar,rst);
parameter N=2;
input [N-1:0]d;
input clk, rst;
output [N-1:0] q, qbar;
wire [N:0] connect;
wire [N-1:0] qbarc;
genvar i;
assign connect[0] = clk;
    generate
        for(i=0;i<N;i=i+1)
            begin: DFFL
            dff DU(d[i],connect[i],connect[i+1],~connect[i+1],rst); 
            end
    endgenerate
assign q[N-1] = connect[N];  
endmodule

I am obtaining the following error: Line 21: Illegal expression in target

The Line 21 is dff DU(d[i],connect[i],connect[i+1],~connect[i+1],rst);

Why is the problem occurring, and what are best practises to avoid it in the future?

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

The problem is that the expression ~signal is not an lvalue — an entity that can be assigned a value on the left-hand side of an assignment. Anything connected to an output port of a module must be an lvalue, like a bare signal name. That's why you're getting that specific error.

But more to the point of your actual example, why would you want to connect to both q and qbar? They are just redundant copies of the same information.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks a lot for the information. Since I was using qbar in the FF module as an input port, so I was curious to use it in the daisy chain too. Thanks a lot, I learned something new. \$\endgroup\$ Jul 26, 2020 at 12:50
0
\$\begingroup\$

You should not use an expression, ~connect[i+1], to connect to the qbar output port of dff. Perhaps you can leave this output unconnected:

            dff DU (
                .d      (d[i]),
                .clk    (connect[i]),
                .q      (connect[i+1]),
                .qbar   (),
                .rst    (rst)
            ); 

One way to avoid connection problems like this is to use connection-by-name, as shown, instead of connection-by-order (as in your code).

\$\endgroup\$
1
  • \$\begingroup\$ I am thankful for your reply. Please, can you guide on what is the problem that is occurring if we use the expression ~connect[i+1], to connect to the qbar output port, it'll help me to understand the functioning better. \$\endgroup\$ Jul 26, 2020 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.