我对vhdl很新。我正在编写一个代码,通过使用开关在de2-115 t-pad上显示不同类型的rgb模式。以下是我写的以下代码。我已经多次检查过,但是Quartus总是报告错误。如果你能帮助我,我会很感激。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity rgb is
port (
sw : in std_logic_vector(2 downto 0);
iclk : in std_logic:= '0';
iRST_n : in std_logic;
x_cnt : in std_logic_vector (10 downto 0);
y_cnt : in std_logic_vector (10 downto 0);
data1,data2,data3 : out std_logic_vector(7 downto 0)
);
end rgb;
architecture behave of rgb is
begin
process(RGB, iclk,iRST_n,x_cnt,y_cnt)
begin
if iRST_n = '0' then -- line of error
data1 <= "00000000";
data2 <= "00000000"; -- BLACK
data3 <= "00000000";
elsif (rising_edge(iclk)) then
if (rgb = "001") then --RGB
if (y_cnt<=209) then
data1 <= "11111111"; -- RED
data2 <= "00000000";
data3 <= "00000000";
elsif (y_cnt>209 and y_cnt<=418) then
data1 <= "00000000";
data2 <= "11111111"; -- GREEN
data3 <= "00000000";
elsif (y_cnt> 418) then
data1 <= "00000000";
data2 <= "00000000";
data3 <= "11111111"; --BLUE
end if;
end if;
elsif(rgb ="010") then --RBGBB
if (x_cnt<=184) then
data1 <= "11111111";
data2 <= "00000000";
data3 <= "00000000";
elsif (x_cnt>=234 and x_cnt<=393) then
data1 <= "00000000";
data2 <= "11111111";
data3 <= "00000000";
elsif (x_cnt>= 443) then
data1 <= "00000000";
data2 <= "00000000";
data3 <= "11111111";
end if;
end process;
end behave;
答案 0 :(得分:1)
首先根据控制结构缩进代码。这将显示最终elsif(rgb ="010") then
不在rising_edge(iclk)
之下,因此更新可能会发生在“时钟边缘之外”,如错误消息所示。
此外,没有rgb
信号或端口,因此使用此类rgb = "001"
也会导致错误。
此外,if
和end if
不平衡。
可能更多的问题,但只是一个开始...
答案 1 :(得分:1)
如果你应该使用rgb
,那么你可以在两个地方弄乱并且有几个地方使用了标识符sw
。
当Morten写下并修复名字并结束ifs时,有点缩进:
library ieee;
use ieee.std_logic_1164.all;
-- use ieee.std_logic_unsigned.all;
use ieee.numeric_std_unsigned.all;
entity rgb is
port (
sw: in std_logic_vector (2 downto 0);
iclk: in std_logic := '0';
iRST_n: in std_logic;
x_cnt: in std_logic_vector (10 downto 0);
y_cnt: in std_logic_vector (10 downto 0);
data1,data2,data3: out std_logic_vector (7 downto 0)
);
end entity rgb;
architecture behave of rgb is
begin
L1:
process (sw, iclk, iRST_n, x_cnt, y_cnt)
begin
if iRST_n = '0' then -- line of error
data1 <= "00000000";
data2 <= "00000000"; -- BLACK
data3 <= "00000000";
elsif rising_edge(iclk) then
if sw = "001" then --RGB
if y_cnt <= 209 then
data1 <= "11111111"; -- RED
data2 <= "00000000";
data3 <= "00000000";
elsif y_cnt > 209 and y_cnt <= 418 then
data1 <= "00000000";
data2 <= "11111111"; -- GREEN
data3 <= "00000000";
elsif y_cnt > 418 then
data1 <= "00000000";
data2 <= "00000000";
data3 <= "11111111"; --BLUE
end if;
elsif sw = "010" then --RBGBB
if x_cnt <= 184 then
data1 <= "11111111";
data2 <= "00000000";
data3 <= "00000000";
elsif x_cnt >= 234 and x_cnt <= 393 then
data1 <= "00000000";
data2 <= "11111111";
data3 <= "00000000";
elsif (x_cnt>= 443) then
data1 <= "00000000";
data2 <= "00000000";
data3 <= "11111111";
end if;
end if;
end if;
end process;
end architecture behave;
使用包numeric_std_unsigned是我个人的选择。没有检查使用包std_logic_unsigned可能工作得很好。包numeric_std_unsigned是-2008 VHDL标准的一部分,旨在取代来自特定供应商的std_logic_unsigned,而不是标准的一部分(但仍然被广泛使用,-2008的速度很慢)。
通过这些更改,您的代码将进行分析和阐述。