【发布时间】:2018-05-26 20:11:58
【问题描述】:
不久前刚开始使用VHDL,出于好奇。
所以我试图在 spartan 3 board 上编写 BCD 计时器和
不知何故,我不知道为什么它一直显示“意外”错误。
所以如果我想拥有图片链接所示的功能, 如何修改代码?任何帮助将不胜感激。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity w3 is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
stp : in STD_LOGIC;
an : out STD_LOGIC_VECTOR (3 downto 0);
c : out STD_LOGIC_VECTOR (6 downto 0));
end w3;
architecture timer of w3 is
signal div1 : integer range 0 to 499999 :=0; -- 100Hz
signal ck100hz : std_logic; -- 100Hz output
signal div2 : integer range 0 to 249999 :=0; -- 200Hz
signal ck200hz : std_logic; -- 200Hz output
signal div3 : integer range 0 to 124999 :=0; -- 400Hz
signal ck400hz : std_logic; -- 400Hz output
signal index : integer range 0 to 9 :=0;
signal scan : std_logic_vector (3 downto 0);
signal S : std_logic;
signal disp : std_logic_vector (3 downto 0);
begin
process begin
wait until rising_edge(clk);
if div1 < 499999 then
ck100hz <= '0';
div1 <= div1+1;
else
ck100hz <= '1';
div1 <= 0;
end if;
if div2 < 249999 then
ck200hz <= '0';
div2 <= div2+1;
else
ck200hz <= '1';
div2 <= 0;
end if;
if div3 < 124999 then
ck400hz <= '0';
div3 <= div3+1;
else
ck400hz <= '1';
div3 <= 0;
end if;
end process;
process begin
wait until rising_edge(clk);
if rst = '1' then
index <= 0;
end if;
if stp = '1' then
index <= index;
end if;
if ck100hz = '1' then
if index < 3 then index <= index+1;
else index <= 0;
if index < 4 and index > 7 then index <= index+1;
else index <= 0;
if index < 8 and index > 11 then index <= index+1;
else index <= 0;
if index < 12 and index > 15 then index <= index+1;
else index <= 0;
end if;
end if;
end if;
end if;
end if;
end process;
process begin
wait until rising_edge(clk);
if ck400hz = '1' then
With scan select -- error unexpected With
an <= an(0) when "00",
an(1) when "01",
an(2) when "10",
an(3) when others;
end if;
end process;
process begin
wait until rising_edge(clk);
if ck200hz = '1' then
With S select -- error unexpected With
disp <= index integer range 0 to 3 when "00",
index integer range 4 to 7 when "01",
index integer range 8 to 11 when "10",
index integer range 12 to 15 when others;
end if;
end process;
with index select
C <= "1000000" when 0,
"1111001" when 1,
"0100100" when 2,
"0110000" when 3,
"0011001" when 4,
"0010010" when 5,
"0000010" when 6,
"1111000" when 7,
"0000000" when 8,
"0011000" when 9;
end timer;
【问题讨论】:
-
with在顺序代码(例如进程)中不受支持。不需要那么多end if,使用elsif分支,尽量减少语句的深度。您不应该编写低活动代码。scan和S没有驱动程序。 -
@Paebbels 我认为这是一个高活性代码?
scan和S没有驱动程序是什么意思?我对elsif不太熟悉,所以我使用了很多end if...好吧,如果with...select不能在process中使用,那么我可以使用什么来使该功能正常工作?感谢您的帮助。编辑:如果你不介意,请举个例子。 -
ISE 不支持 -2008 语法更改(顺序选择信号分配)。 ISE XST 也不支持并发选择信号分配。顺序选择的信号分配具有等效的 case 语句。这不是代码编写服务,也许您会问一个具体的问题?
an不对,一次只能有一个元素为真(分配整个事物)。disp未使用,您似乎没有 BCD 计数器,index仅分配了 0 或其当前值。div1、div2和div3仅评估增量。