ch10.01.htm

来自「介绍asci设计的一本书」· HTM 代码 · 共 88 行

HTM
88
字号
<HTML>

<HEAD>

  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Mac">

  

  <TITLE> 10.1&nbsp;	A Counter</TITLE>

</HEAD><!--#include file="top.html"--><!--#include file="header.html"--><br><!--#include file="AmazonAsic.html"-->





<P><A NAME="pgfId=83948"></A><A HREF="CH10.htm">Chapter&nbsp;&nbsp;start</A>&nbsp;&nbsp;&nbsp;<A

HREF="CH10.htm">Previous&nbsp;&nbsp;page</A>&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="CH10.02.htm">Next&nbsp;&nbsp;page</A></P>



<H2>10.1&nbsp; A Counter</H2>



<P><P CLASS="BodyAfterHead"><A NAME="pgfId=339767"></A>The following VHDL

model describes an electrical &quot;black box&quot; that contains a 50 MHz

clock generator and a counter. The counter increments on the negative edge

of the clock, counting from zero to seven, and then begins at zero again.

The model contains separate processes that execute at the same time as each

other. Modeling concurrent execution is the major difference between HDLs

and computer programming languages such as C.</P>



<PRE><B>entity</B> Counter_1 <B>is end</B>; -- declare a &quot;black box&quot; called Counter_1

<B>library</B> STD; <B>use</B> STD.TEXTIO.<B>all</B>; -- we need this library to print

<B>architecture</B> Behave_1 <B>of</B> Counter_1 <B>is </B>-- describe the &quot;black box&quot; 

-- declare a signal for the clock, type BIT, initial value '0'

<B>	signal</B> Clock : BIT := '0';

-- declare a signal for the count, type INTEGER, initial value 0

<B>	signal</B> Count : INTEGER := 0;

<B>begin </B>

<B>	process</B> <B>begin </B>-- process to generate the clock

<B>		wait</B> <B>for</B> 10 ns; -- a delay of 10 ns is half the clock cycle

		Clock &lt;= <B>not</B> Clock;

<B>		if</B> (now &gt; 340 ns) <B>then</B> <B>wait</B>; <B>end</B> <B>if</B>; -- stop after 340 ns

	<B>end</B> <B>process</B>;

-- process to do the counting, runs concurrently with other processes

	<B>process</B> <B>begin</B>

-- wait here until the clock goes from 1 to 0

		<B>wait</B> <B>until</B> (Clock = '0');

-- now handle the counting

		<B>if</B> (Count = 7) <B>then</B> Count &lt;= 0;

		<B>else</B> Count &lt;= Count + 1;

		<B>end</B> <B>if</B>;

	<B>end</B> <B>process</B>;

	<B>process</B> (Count) <B>variable</B> L: LINE; <B>begin</B> -- process to print

		write(L, now); write(L, STRING'(&quot; Count=&quot;));

		write(L, Count); writeline(output, L);

	<B>end</B> <B>process</B>;

<B>end</B>;</PRE>



<P><P CLASS="Body"><A NAME="pgfId=112278"></A>Throughout this book VHDL

keywords (reserved words that are part of the language) are shown in bold

type in code examples (but not in the text). The code examples use the bold

keywords to improve readability. VHDL code is often lengthy and the code

in this book is always complete wherever possible. In order to save space

many of the code examples do not use the conventional spacing and formatting

that is normally considered good practice. So &quot;Do as I say and not

as I do.&quot;</P>



<P><P CLASS="Body"><A NAME="pgfId=358942"></A>The steps to simulate the

model and the printed results for <CODE>Counter_1</CODE> using the Model

Technology V-System/Plus common-kernel simulator are as follows:</P>



<PRE>&gt; vlib work

&gt; vcom Counter_1.vhd

Model Technology VCOM V-System VHDL/Verilog 4.5b

-- Loading package standard

-- Compiling entity counter_1

-- Loading package textio

-- Compiling architecture behave_1 of counter_1

&gt; vsim -c counter_1

# Loading /../std.standard

# Loading /../std.textio(body)

# Loading work.counter_1(behave_1)

VSIM 1&gt; run 500

# 0 ns Count=0

# 20 ns Count=1

(...15 lines omitted...)

# 340 ns Count=1

VSIM 2&gt; quit

&gt;</PRE>



<P><HR ALIGN=LEFT></P>



<P><A HREF="CH10.htm">Chapter&nbsp;&nbsp;start</A>&nbsp;&nbsp;&nbsp;<A HREF="CH10.htm">Previous&nbsp;&nbsp;page</A>&nbsp;&nbsp;&nbsp;<A HREF="CH10.02.htm">Next&nbsp;&nbsp;page</A>

</BODY>



<!--#include file="Copyright.html"--><!--#include file="footer.html"-->

⌨️ 快捷键说明

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