tim 发表于 2010-6-27 23:51:31

用Vhdl写的分频器的代码问题!

用Vhdl写的分频器的代码问题!
l

ibrary ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity fdiv is
port(clk , and3 :in   std_logic;--位同步时钟与逻辑门3的控制信号
   freclk: out std_logic);
end fdiv;
architecture fp of fdiv is
signal cnt:integer range 0 to 31;
begin
process(clk,and3)
begin
if and3='0' then freclk='0';
elsif(clk'eventand clk='1')then
   if(cnt=cnt'high)then
    cnt<=0;
    freclk<='1';
   else
cnt<=cnt+1;
freclk<='0';
   end if;
end if;
end if;
end process;
end fp;

错误提示:Error: VHDL syntax error at fdiv.vhd(6) near text ?
Error: VHDL syntax error at fdiv.vhd(6) near text "?; expecting ";"
Error: VHDL syntax error at fdiv.vhd(6) near text ?
Error: VHDL error at fdiv.vhd(8): entity fdiv is used but not declared
Error: VHDL error at fdiv.vhd(9): object integer is used but not declared
Error: VHDL syntax error at fdiv.vhd(13) near text "="; expecting "'" or "(" or "."
Error: VHDL error at fdiv.vhd(16): object cnt is used but not declared
Error: VHDL error at fdiv.vhd(17): object freclk is used but not declared
Error: VHDL error at fdiv.vhd(19): object cnt is used but not declared
Error: VHDL error at fdiv.vhd(20): object freclk is used but not declared
Error: VHDL error at fdiv.vhd(15): object cnt is used but not declared
Error: VHDL error at fdiv.vhd(14): object clk is used but not declared
Error: VHDL error at fdiv.vhd(13): object and3 is used but not declared
Error: VHDL syntax error at fdiv.vhd(23) near text "if"; expecting "process"
Error: VHDL error at fdiv.vhd(11): object clk is used but not declared
Error: VHDL error at fdiv.vhd(11): object and3 is used but not declared
Error: Quartus II Analysis & Synthesis was unsuccessful. 16 errors, 0 warnings
    Error: Processing ended: Wed May 23 10:02:13 2007
    Error: Elapsed time: 00:00:02

ups 发表于 2010-6-28 00:22:42

将<br>
if and3='0' then freclk='0';<br>
&nbsp; &nbsp;&nbsp;&nbsp;elsif(clk'event&nbsp;&nbsp;and clk='1')then<br>
&nbsp; &nbsp;&nbsp; &nbsp; if(cnt=cnt'high)then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; freclk&lt;='1';<br>
改为<br>
if and3='0' then freclk='0';<br>
&nbsp; &nbsp;&nbsp;&nbsp;elsif(clk'event&nbsp;&nbsp;and clk='1')then<br>
&nbsp; &nbsp;&nbsp; &nbsp; if(cnt=31)then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; freclk&lt;='1';

CHANG 发表于 2010-6-28 05:02:31

建议好好学习下VHDL<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_arith.all;<br>
<br>
entity fdiv is<br>
&nbsp; &nbsp; &nbsp; &nbsp; port(<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clk,and3&nbsp; &nbsp; &nbsp; &nbsp; : in&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;std_logic;--位同步时钟与逻辑门3的控制信号<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freclk&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : out&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; std_logic<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>
end fdiv;<br>
<br>
architecture fp of fdiv is<br>
<br>
signal cnt&nbsp;&nbsp;:integer range 0 to 31;<br>
<br>
begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; process(clk,and3)<br>
&nbsp; &nbsp; begin <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(and3 = '0') then<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freclk &lt;= '0';<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elsif(clk'event&nbsp;&nbsp;and clk = '1') then<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(cnt = cnt'high) then<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnt &lt;= 0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freclk &lt;= '1';<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnt &lt;= cnt + 1;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freclk &lt;= '0';<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end if;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end if;<br>
&nbsp; &nbsp; &nbsp; &nbsp; end process;<br>
end fp;

CHAN 发表于 2010-6-28 06:19:46

看看,参考

ngtim 发表于 2010-6-28 07:23:13

多了一个END IF;<br>
freclk付值了两次

UFP 发表于 2010-6-28 08:45:01

还有一点忘记说了:cnt要在process下面定义,我认为是这样你先尝试下。

CHAN 发表于 2010-6-28 10:13:56

也可能是文件名与实体名不同造成的

longt 发表于 2010-6-28 10:34:21

看来论坛上热心的人也还挺多的嘛!!!!!!!!!!!!!!

encounter 发表于 2010-6-28 12:31:11

'?'表示有非法字符,所自己动手调试,很多提示错误就很容易看懂了;<br>
if语句的几种用法一定要看仔细了。

longt 发表于 2010-6-28 13:21:48

应该是文件名与实体名不同造成的。
页: [1] 2
查看完整版本: 用Vhdl写的分频器的代码问题!