Previous

Three-State Inference

Foundation Express infers a three-state driver when you assign the value of z to a variable. The z value represents the high-impedance state. Foundation Express infers one three-state driver per block. You can assign high-impedance values to single-bit or bused variables.

Reporting Three-State Inference

Foundation Express generates an inference report of the inferred devices.

The following example shows a three-state inference report.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |               OUT1_tri |          Three-state Buffer          |
   =========================================================================

The first column of the report indicates the name of the inferred three-state device. The second column of the report indicates the type of three-state device that Foundation Express inferred.

Controlling Three-State Inference

Foundation Express always infers a three-state driver when you assign the value of z to a variable. Foundation Express does not provide any means of controlling the inference.

Inferring Three-State Drivers

This section contains Verilog examples that infer the following types of three-state drivers.

Simple Three-State Driver

This section shows a template for a simple three-state driver. In addition, this section supplies examples of how allocating high-impedance assignments to different blocks affects three-state inference.

The following example shows the Verilog template for a simple three-state driver. Foundation Express generates the inference report shown in the inference report example for simple three-state driver. The figure “Three-State Driver” shows the inferred three-state driver.

   module three_state (ENABLE, IN1, OUT1);
      input IN1, ENABLE;
      output OUT1;
      reg OUT1;
   
   always @(ENABLE or IN1) begin
      if (ENABLE)
         OUT1 = IN1;
   else
         OUT1 = 1'bz;  //assigns high-impedance state
   end
   endmodule

The following example shows an inference report for a simple three-state driver.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |               OUT1_tri |          Three-state Buffer          |
   =========================================================================

Figure 6.15 Three-State Driver

The following example shows how to place all high-impedance assignments in a single block. In this case, the data is gated and Foundation Express infers a single three-state driver. An inference report for a single process follows the example. The figure “Inferring One Three-State Driver” shows the schematic generated by the code.

   module three_state (A, B, SELA, SELB, T);
      input  A, B, SELA, SELB;
      output T;
      reg T;
   
   always @(SELA or SELB or A or B) begin
      T = 1'bz;
      if (SELA)
         T = A;
      if (SELB)
         T = B;
   end
   endmodule

The following example shows a single process inference report.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |                T_tri |          Three-state Buffer          |
   =========================================================================

Figure 6.16 Inferring One Three-State Driver

The following example shows how to place each high-impedance assignment in separate blocks. In this case, Foundation Express infers multiple three-state drivers. The inference report for two three-state drivers follows the example. The figure “Inferring Two Three-State Drivers” shows the schematic generated by the code.

   module three_state (A, B, SELA, SELB, T);
      input  A, B, SELA, SELB;
      output T;
      reg T;
   
   always @(SELA or A)
      if (SELA)
         T = A;
      else
         T = 1'bz;
   
   always @(SELB or B)
      if (SELB)
         T = B;
      else 
   endmodule

The following example shows an inference report for two three-state drivers.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |                T_tri |          Three-state Buffer          |
   =========================================================================
   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |                T_tri2 |          Three-state Buffer          |
   =========================================================================

Figure 6.17 Inferring Two Three-State Drivers

Registered Three-State Drivers

When a variable is registered in the same block in which it is three-stated, Foundation Express also registers the enable pin of the three-state gate. The following example shows this type of code, and the inference report for a three-state driver with registered enable follows the example. The figure “Three-State Driver with Registered Enable” shows the schematic generated by the code.

   module ff_3state (DATA, CLK, THREE_STATE, OUT1);
      input DATA, CLK, THREE_STATE;
      output OUT1;
      reg OUT1;
   
   always @ (posedge CLK) begin
      if (THREE_STATE)
         OUT1 = 1'bz;
      else
         OUT1 = DATA;
   end
   endmodule

The following example shows an inference report for a three-state driver with registered enable.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |               OUT1_tri |          Three-state Buffer          |
   |         OUT1_tri_enable_reg |         Flip-flop (width 1)          |
   =========================================================================

Figure 6.18 Three-State Driver with Registered Enable

In the above example, the three-state gate has a register on its enable pin. The following example uses two blocks to instantiate a three-state gate with a flip-flop only on the input. The inference report for a three-state driver without registered enable follows the example. The figure “Three-State Driver without Registered Enable” shows the schematic generated by the code.

   module ff_3state (DATA, CLK, THREE_STATE, OUT1);
      input DATA, CLK, THREE_STATE;
      output OUT1;
      reg OUT1;
   
      reg TEMP;
   
   always @(posedge CLK)
      TEMP = DATA;
   
   always @(THREE_STATE or TEMP)
      if (THREE_STATE)
         OUT1 = TEMP;
      else
         OUT1 = 1'bz;
   endmodule

The following example shows an inference report for a three-state driver without registered enable.


   =========================================================================
   |       Three-state Device Name |                 Type                 |
   =========================================================================
   |               OUT1_tri |          Three-state Buffer          |
   =========================================================================

Figure 6.19 Three-State Driver without Registered Enable

Understanding the Limitations of Three-State Inference

You can use the Z value in the following ways.

You cannot use the Z value in an expression, except for comparison to Z. Be careful when using expressions that compare to the Z value. Foundation Express always evaluates these expressions to FALSE and the pre- and post-synthesis simulation results might differ. For this reason, Foundation Express issues a warning when it synthesizes such comparisons.

The following example shows the incorrect use of the Z value in an expression.

OUT_VAL = (1'bz && IN_VAL);

The following example shows the correct use of the Z value in an expression.

if (IN_VAL == 1'bz) then

Next