如何在STD_LOGIC_VECTor上以VHDL方式执行右移或左移......
它不起作用,为什么??`
AN <= "0001";
CounterProcess: process(CLK,Switch)
begin
if rising_edge(CLK) then
if prescaler < limit then
prescaler <= prescaler + 1;
else
prescaler <= (others => '0');
counter <= counter + 1;
AN sll 1;
end if;
end if;
end process;
An <= anode;
Segment <= counter;
end Behavioral;
我收到错误消息:sll在此上下文中不能有这样的操作数。 但是在哪种情况下可以使用它,以及如何执行我的左移?
这些是我的包括:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
不是执行我的leftshift操作所需的那个??
完整代码
entity Main is
PORT(
CLK: in std_logic;
LED: out std_logic_vector (7 downto 0);
Switch: in std_logic_vector(7 downto 0);
Segment: out std_logic_vector (7 downto 0);
AN: out std_logic_vector (3 downto 0)
);
end Main;
architecture Behavioral of Main is
signal counter: std_logic_vector (7 downto 0);
signal prescaler: std_logic_vector(25 downto 0);
signal limit: std_logic_vector (25 downto 0);
signal anode: std_logic_vector (3 downto 0);
begin
AN <= "0001";
ScalerChoice: Process(switch)
begin
CASE Switch IS
when "00000001" => limit <= "10111110101111000010000000"; -- 1 Hz;
when "00000010" => limit <= "00111111100101000000101011"; -- 3 HZ
When "00000100" => limit <= "00010011000100101101000000"; -- 10 Hz
when "00001000" => limit <= "00000111101000010010000000"; -- 25 Hz
When "00010000" => limit <= "00000011110100001001000000"; -- 50 Hz;
when "00100000" => limit <= "00000001111010000100100000"; -- 100 hz
when others => limit <= "00000000000000000000000001"; -- 50 MHz
end case;
end process;
CounterProcess: process(CLK,Switch)
begin
if rising_edge(CLK) then
if prescaler < limit then
prescaler <= prescaler + 1;
else
prescaler <= (others => '0');
counter <= counter + 1;
AN sll AN 1;
end if;
end if;
end process;
Segment <= counter;
end Behavioral;
答案 0 :(得分:1)
除了trumpetlicks所说的,请使用这些包。确保启用VHDL-2008开关。也请先与您的FPGA供应商联系,因为这些需要VHDL-2008更新:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;
上述包都是IEEE标准。包STD_LOGIC_ARITH
和std_logic_unsigned
不是IEEE标准。另请注意,numeric_std
和STD_LOGIC_ARITH
相互冲突,使得signed
和unsigned
类型变得困难(超出基本用法)。请注意std_logic_unsigned
与numeric_std_unsigned
冲突。因此,如果您的综合工具支持numeric_std_unsigned
,我建议您使用它。此外,如果不是,您应该提交针对它的错误报告。
答案 1 :(得分:0)
编辑1:
您的代码使用重置逻辑进行编辑,请注意将RESET
信号添加到端口列表,删除异步行设置该值,将RESET
添加到{的灵敏度列表中{1}}处理,添加CounterProcess
行,将if(RESET = '1')
更改为if
,以及更改换行:
我实际上不知道你的elsif
行在做什么,并且认为这也是错误的。
An <= Anode
你需要写下你目前拥有的那一行:
entity Main is PORT(
RESET: in std_logic;
CLK: in std_logic;
LED: out std_logic_vector(7 downto 0);
Switch: in std_logic_vector(7 downto 0);
Segment: out std_logic_vector(7 downto 0);
AN: out std_logic_vector(3 downto 0)
);
end Main;
architecture Behavioral of Main is
signal counter: std_logic_vector(7 downto 0);
signal prescaler: std_logic_vector(25 downto 0);
signal limit: std_logic_vector(25 downto 0);
signal anode: std_logic_vector(3 downto 0);
begin
ScalerChoice: Process(switch)
begin
CASE Switch IS
when "00000001" => limit <= "10111110101111000010000000"; -- 1 Hz;
when "00000010" => limit <= "00111111100101000000101011"; -- 3 HZ
When "00000100" => limit <= "00010011000100101101000000"; -- 10 Hz
when "00001000" => limit <= "00000111101000010010000000"; -- 25 Hz
When "00010000" => limit <= "00000011110100001001000000"; -- 50 Hz;
when "00100000" => limit <= "00000001111010000100100000"; -- 100 hz
when others => limit <= "00000000000000000000000001"; -- 50 MHz
end case;
end process;
CounterProcess: process(RESET, CLK, Switch)
begin
if(RESET = '1') then
AN <= "0001";
elsif rising_edge(CLK) then
if prescaler < limit then
prescaler <= prescaler + 1;
else
prescaler <= (others => '0');
counter <= counter + 1;
AN <= std_logic_vector(unsigned(AN) sll 1);
end if;
end if;
end process;
An <= anode;
Segment <= counter;
end Behavioral;
as
AN sll 1;
请记住,AN <= AN sll 1;
基本上就像一个需要“设置”的变量。就像你上面的一行
AN