⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13.2.htm

📁 介绍asci设计的一本书
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML EXPERIMENTAL 970324//EN">

<HTML>

<HEAD>

<META NAME="GENERATOR" CONTENT="Adobe FrameMaker 5.5/HTML Export Filter">



<TITLE> 13.2&nbsp;The Comparator/MUX Example</TITLE></HEAD><!--#include file="top.html"--><!--#include file="header.html"-->



<DIV>

<P>[&nbsp;<A HREF="CH13.htm">Chapter&nbsp;start</A>&nbsp;]&nbsp;[&nbsp;<A HREF="CH13.1.htm">Previous&nbsp;page</A>&nbsp;]&nbsp;[&nbsp;<A HREF="CH13.3.htm">Next&nbsp;page</A>&nbsp;]</P><!--#include file="AmazonAsic.html"--><HR></DIV>

<H1 CLASS="Heading1">

<A NAME="pgfId=28765">

 </A>

13.2&nbsp;<A NAME="16644">

 </A>

The Comparator/MUX Example</H1>

<P CLASS="BodyAfterHead">

<A NAME="pgfId=28769">

 </A>

As an <A NAME="marker=116891">

 </A>

example we borrow the model from Section&nbsp;12.2, &#8220;A Comparator/MUX,&#8221;</P>

<P CLASS="ComputerFirstLabelV">

<A NAME="pgfId=48446">

 </A>

// comp_mux.v</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48447">

 </A>

<B CLASS="Keyword">

module</B>

 comp_mux(a, b, outp); <B CLASS="Keyword">

input</B>

 [2:0] a, b; <B CLASS="Keyword">

output</B>

 [2:0] outp;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48448">

 </A>

<B CLASS="Keyword">

function</B>

 [2:0] compare; <B CLASS="Keyword">

input</B>

 [2:0] ina, inb;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48449">

 </A>

<B CLASS="Keyword">

begin</B>

 <B CLASS="Keyword">

if</B>

 (ina &lt;= inb) compare = ina; <B CLASS="Keyword">

else</B>

 compare = inb; <B CLASS="Keyword">

end</B>

</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48450">

 </A>

<B CLASS="Keyword">

endfunction</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48451">

 </A>

<B CLASS="Keyword">

assign</B>

 outp = compare(a, b);</P>

<P CLASS="ComputerLastLabelV">

<A NAME="pgfId=48452">

 </A>

<B CLASS="Keyword">

endmodule</B>

 </P>

<P CLASS="Body">

<A NAME="pgfId=48454">

 </A>

We can use the following testbench to generate a sequence of input values (we call these <SPAN CLASS="Definition">

input vectors</SPAN>

<A NAME="marker=85764">

 </A>

) that test or <SPAN CLASS="Definition">

exercise</SPAN>

<A NAME="marker=80462">

 </A>

 the behavioral model, <SPAN CLASS="BodyComputer">

comp_mux.v</SPAN>

:</P>

<P CLASS="ComputerFirstLabelV">

<A NAME="pgfId=48603">

 </A>

// testbench.v</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48455">

 </A>

<B CLASS="Keyword">

module</B>

 comp_mux_testbench;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48456">

 </A>

<B CLASS="Keyword">

integer</B>

 i, j;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48457">

 </A>

<B CLASS="Keyword">

reg</B>

 [2:0] x, y, smaller; <B CLASS="Keyword">

wire</B>

 [2:0] z;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48458">

 </A>

<B CLASS="Keyword">

always</B>

 @(x) $display(&quot;t    x y actual calculated&quot;);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48459">

 </A>

<B CLASS="Keyword">

initial</B>

 $monitor(&quot;%4g&quot;,$time,,x,,y,,z,,,,,,,smaller);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48460">

 </A>

<B CLASS="Keyword">

initial</B>

 $dumpvars; <B CLASS="Keyword">

initial</B>

 #1000 $finish; </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48461">

 </A>

<B CLASS="Keyword">

initial</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48462">

 </A>

<B CLASS="Keyword">

begin</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48463">

 </A>

	<B CLASS="Keyword">

for</B>

 (i = 0; i &lt;= 7; i = i + 1) </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48464">

 </A>

	<B CLASS="Keyword">

begin</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48465">

 </A>

		<B CLASS="Keyword">

for</B>

 (j = 0; j &lt;= 7; j = j + 1) </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48466">

 </A>

		<B CLASS="Keyword">

begin</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48467">

 </A>

		x = i; y = j; smaller = (x &lt;= y) ? x : y; </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48468">

 </A>

<A NAME="41922">

 </A>

		#1 if (z  != smaller) $display(&quot;error&quot;);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=56022">

 </A>

		<B CLASS="Keyword">

end</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=56023">

 </A>

	<B CLASS="Keyword">

end</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=56024">

 </A>

<B CLASS="Keyword">

end</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48472">

 </A>

comp_mux v_1 (x, y, z);</P>

<P CLASS="ComputerLastLabelV">

<A NAME="pgfId=48473">

 </A>

<B CLASS="Keyword">

endmodule</B>

 </P>

<P CLASS="BodyAfterHead">

<A NAME="pgfId=48579">

 </A>

The results from the behavioral simulation are as follows:</P>

<P CLASS="ComputerFirst">

<A NAME="pgfId=48582">

 </A>

t    x y actual calculated</P>

<P CLASS="Computer">

<A NAME="pgfId=48584">

 </A>

   0 0 0 0      0</P>

<P CLASS="Computer">

<A NAME="pgfId=48585">

 </A>

   1 0 1 0      0</P>

<P CLASS="Computer">

<A NAME="pgfId=48588">

 </A>

... 60 lines omitted...</P>

<P CLASS="Computer">

<A NAME="pgfId=48593">

 </A>

&nbsp;&nbsp;62 7 6 6      6</P>

<P CLASS="ComputerLast">

<A NAME="pgfId=48594">

 </A>

  63 7 7 7      7</P>

<P CLASS="Body">

<A NAME="pgfId=48703">

 </A>

We included a delay of one Verilog time unit in line <A HREF="CH13.2.htm#41922" CLASS="XRef">

15</A>

 of the testbench model (allowing time to progress), but we did not specify the units&#8212;they could be nanoseconds or days. Thus, behavioral simulation can only tell us if our design does not work; it cannot tell us that real hardware will work.</P>

<DIV>

<H2 CLASS="Heading2">

<A NAME="pgfId=58164">

 </A>

13.2.1&nbsp;<A NAME="23329">

 </A>

Structural Simulation</H2>

<P CLASS="BodyAfterHead">

<A NAME="pgfId=85517">

 </A>

We use logic synthesis to produce a structural model from a behavioral model. The following comparator/MUX model is adapted from the example in <A HREF="/Humuhumu/from Antibes/Prof.htm#22485" CLASS="XRef">

Section&nbsp;12.11</A>

, &#8220;<A HREF="/Humuhumu/from Antibes/Prof.htm#22485" CLASS="XRef">

Performance-Driven Synthesis</A>

&#8221; (optimized for a 0.6  <SPAN CLASS="Symbol">

m</SPAN>

m standard-cell library):</P>

<P CLASS="ComputerFirstLabelV">

<A NAME="pgfId=85524">

 </A>

`timescale 1ns / 10ps // comp_mux_o2.v</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48718">

 </A>

<B CLASS="Keyword">

module</B>

 comp_mux_o (a, b, outp);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48719">

 </A>

<B CLASS="Keyword">

input</B>

  [2:0] a; <B CLASS="Keyword">

input</B>

  [2:0] b;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48720">

 </A>

<B CLASS="Keyword">

output</B>

 [2:0] outp;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48721">

 </A>

<B CLASS="Keyword">

supply1</B>

 VDD; <B CLASS="Keyword">

supply0</B>

 VSS;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48723">

 </A>

mx21d1 b1_i1 (.i0(a[0]), .i1(b[0]), .s(b1_i6_zn), .z(outp[0]));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48724">

 </A>

oa03d1 b1_i2 (.a1(b1_i9_zn), .a2(a[2]), .b1(a[0]), .b2(a[1]),</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48738">

 </A>

	.c(b1_i4_zn), .zn(b1_i2_zn));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48725">

 </A>

nd02d0 b1_i3 (.a1(a[1]), .a2(a[0]), .zn(b1_i3_zn));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48726">

 </A>

nd02d0 b1_i4 (.a1(b[1]), .a2(b1_i3_zn), .zn(b1_i4_zn));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48727">

 </A>

mx21d1 b1_i5 (.i0(a[1]), .i1(b[1]), .s(b1_i6_zn), .z(outp[1]));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48728">

 </A>

oa04d1 b1_i6 (.a1(b[2]), .a2(b1_i7_zn), .b(b1_i2_zn),</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48742">

 </A>

	.zn(b1_i6_zn));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48729">

 </A>

in01d0 b1_i7 (.i(a[2]), .zn(b1_i7_zn));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48730">

 </A>

an02d1 b1_i8 (.a1(b[2]), .a2(a[2]), .z(outp[2]));</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48731">

 </A>

in01d0 b1_i9 (.i(b[2]), .zn(b1_i9_zn));</P>

<P CLASS="ComputerLastLabelV">

<A NAME="pgfId=48733">

 </A>

<B CLASS="Keyword">

endmodule</B>

 </P>

<P CLASS="Body">

<A NAME="pgfId=48713">

 </A>

Logic simulation requires Verilog models for the following six logic cells: <SPAN CLASS="BodyComputer">

mx21d1 </SPAN>

(2:1 MUX), <SPAN CLASS="BodyComputer">

oa03d1</SPAN>

 (OAI221), <SPAN CLASS="BodyComputer">

nd02d0</SPAN>

 (two-input NAND), <SPAN CLASS="BodyComputer">

oa04d1</SPAN>

 (OAI21), <SPAN CLASS="BodyComputer">

in01d0</SPAN>

 (inverter), and <SPAN CLASS="BodyComputer">

an02d1</SPAN>

 (two-input AND). These models are part of an ASIC library (often encoded so that they cannot be seen) and thus, from this point on, the designer is dependent on a particular ASIC library company. As an example of this dependence, notice that some of the names in the preceding code have changed from uppercase (in Figure 12.8 on p.&nbsp;624) to lowercase. Verilog is case sensitive and we are using a cell library that uses lowercase. Most unfortunately, there are no standards for names, cell functions, or the use of case in ASIC libraries. </P>

<P CLASS="Body">

<A NAME="pgfId=97498">

 </A>

The following code (a simplified model from a 0.8  <SPAN CLASS="Symbol">

m</SPAN>

m standard-cell library) models a 2:1 MUX and uses fixed delays:</P>

<P CLASS="ComputerFirstLabelV">

<A NAME="pgfId=48780">

 </A>

`timescale 1 ns / 10 ps</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48781">

 </A>

<B CLASS="Keyword">

module</B>

 mx21d1 (z, i0, i1, s); <B CLASS="Keyword">

input</B>

 i0, i1, s; <B CLASS="Keyword">

output</B>

 z;</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48792">

 </A>

<B CLASS="Keyword">

	not</B>

 G3(N3, s);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=49067">

 </A>

<B CLASS="Keyword">

	and</B>

 G4(N4, i0, N3), G5(N5, s, i1), G6(N6, i0, i1);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=49068">

 </A>

	<B CLASS="Keyword">

or</B>

 G7(z, N4, N5, N6);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48795">

 </A>

<B CLASS="Keyword">

specify</B>

 </P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48796">

 </A>

<A NAME="23032">

 </A>

	(i0*&gt;z) = (0.279:0.504:0.900, 0.276:0.498:0.890);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48797">

 </A>

	(i1*&gt;z) = (0.248:0.448:0.800, 0.264:0.476:0.850);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48798">

 </A>

	(s*&gt;z)&nbsp;&nbsp;= (0.285:0.515:0.920, 0.298:0.538:0.960);</P>

<P CLASS="ComputerLabelV">

<A NAME="pgfId=48799">

 </A>

<B CLASS="Keyword">

endspecify</B>

 </P>

<P CLASS="ComputerLastLabelV">

<A NAME="pgfId=48800">

 </A>

<B CLASS="Keyword">

endmodule</B>

 </P>

<P CLASS="BodyAfterHead">

<A NAME="pgfId=77726">

 </A>

This code uses Verilog primitive models (<SPAN CLASS="BodyComputer">

not</SPAN>

, <SPAN CLASS="BodyComputer">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -