Skip navigation.
Home

Verilog ifdef

Verilog supports a limited number of compiler directive statements. One particular useful statement is the Verilog `ifdef. The syntax for the `ifdef is "`ifdef NAME". The ifdef should be paired with the `define directive which has the syntax "`define NAME VALUE". The `ifdef can be used in conjunction with the `else and must be closed with the `endif. Both of these directives are very similar to the C equivalent. The following example shows how a particular module may be conditionally instantiated.

`define USE_MODULE_A 
 
module verilog_if_def_example
(
   input      clk,
   input      din,
   output reg dout
);
 
// instantiate either Module A or B 
// depending on the `ifdef
`ifdef USE_MODULE_A
module_a module_inst
(
  .clk (clk),
  .din (din),
  .dout(dout)
);
`else
module_b module_inst
(
  .clk (clk),
  .din (din),
  .dout(dout)
);
`endif
 
endmodule
 
// simple positive edge flip flop
module module_a
(
   input      clk,
   input      din,
   output reg dout
);
 
always @(posedge clk) 
  dout <= din;
 
endmodule
 
// simple negative edge flip flop
module module_b
(
   input      clk,
   input      din,
   output reg dout
);
 
always @(negedge clk) 
  dout <= din;
 
endmodule

AttachmentSize
verilog_if_def_example.v685 bytes

Interesting information about activation

I think this board is the proper place to ask you about the activation proccess. My link is not working properly, do you know why it is happening? http://www.hdlsnippets.com/?d4a89e0310162cdce61441c3737,