1
\$\begingroup\$

For example if i am going to model T flip flop using D flip flop. I am not writing the whole code of T flip flop as here it is not related to my query.

module T_ff(q,clk,clear); 
//............... 
//Instantiate the D flip flop 
D_ff dff(q,~q,clk,clear); 
endmodule 
// edge triggered D flip flop 
module D_ff(q,qbar,d,clk,clear); 
//.............. 
endmodule 

The number of input/output ports are different in Instantiate of D flip flop (define inside the T flip flop) and in module of D flip flop. Is it fine? Can it result in error?

asked May 10, 2014 at 4:29
\$\endgroup\$
0

1 Answer 1

6
\$\begingroup\$

When using Port Order connections, the ports are connected in the order declared by the module, and any unused ports are left unconnected (Z).

Instantiating by Port Name connections helps avoid this kind of problem.

Your code is interpreted as this:

D_ff dff_instance ( 
 .q ( q ), // first port
 .qbar ( ~q ), // second port
 .d ( clk ), // third port
 .clk ( clear ), // fourth port
 .clear ( 1'bZ ) // fitfh port has no connection
 );

Clearly what you intended was this:

D_ff dff_instance ( 
 .q ( q ),
 .qbar ( ), // unconnected output
 .d ( ~q ), // toggle by driving dff_instance.d input from ~q
 .clk ( clk ),
 .clear ( clear )
 );

If you are using an older verilog compiler that does not support Port Name connections, skip the unused port by two commas:

D_ff dff_instance ( q, , ~q , clk, clear); // qbar output port is unconnected

The Port Name connection style does require more typing, but makes the code easier for a person to read and understand, and more robust against connection errors.

answered May 10, 2014 at 6:42
\$\endgroup\$
2
  • \$\begingroup\$ Just at a curiosity, what older verilog compiler does not support port name connections? It would have to be before the first IEEE verilog standard or it will be non-compliant with IEEE 1364-1995 § 12.3.4 Connecting module ports by name. \$\endgroup\$ Commented May 12, 2014 at 17:10
  • \$\begingroup\$ You're right, any modern verilog compiler should accept connecting ports by name. Sometimes student example code uses port order connections, which isn't as clear in my opinion. As soon as I learned how to enable Xilinx ISE 12 to use Verilog-2001, I started coding this way and haven't looked back. \$\endgroup\$ Commented May 13, 2014 at 3:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.