我是新來的VHDL,我試圖做一個計數器,它接收來自輸入的值,並計數到給定值,然後輸出1;VHDL如何分配一個輸入向量值到一個整數信號
例如,輸入是一個4位向量 「1011」
我試圖設置一個整數信號=輸入= 1011在十進制= 11,那麼,如果B = A = 11輸出1,否則輸出0和b = b + 1
我知道我可以通過一系列的if語句來實現,但我想知道是否有更好的方法,如直接將輸入向量賦值爲整數信號?感謝任何能夠幫助的人!
我是新來的VHDL,我試圖做一個計數器,它接收來自輸入的值,並計數到給定值,然後輸出1;VHDL如何分配一個輸入向量值到一個整數信號
例如,輸入是一個4位向量 「1011」
我試圖設置一個整數信號=輸入= 1011在十進制= 11,那麼,如果B = A = 11輸出1,否則輸出0和b = b + 1
我知道我可以通過一系列的if語句來實現,但我想知道是否有更好的方法,如直接將輸入向量賦值爲整數信號?感謝任何能夠幫助的人!
這是未經測試的,但它是一般的體系結構,聽起來像是你之後。在VHDL中使用if
語句是不錯的做法;他們有必要定義順序(而不是組合)的邏輯;你只需要明智的使用。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Counter is port (
enable: in std_logic; -- Used to increment the counter. (Active high.)
value: in std_logic_vector(0 to 3);
clk: in std_logic; -- Used to clock the counter.
reset: in std_logic; -- Reset the counter. (Active high.)
output: out std_logic -- Generates a logic high once the count has been reached.
);
end Counter;
architecture Behavioral of Counter is
signal count: unsigned(0 to 3);
begin
process(clk,reset)
begin
-- If reset goes high, reset the count.
if reset='1' then
count <= "0000"; -- Reset the counter.
output <= '0'; -- Set the output low.
elsif(clk'event and clk='1') then -- If not reset, and the rising edge of the input clock...
if enable='1' then -- If the counter is enabled...
if count=unsigned(value) then -- If the count reached the input value...
output <= '1'; -- Set the output high.
else
count <= count + 1; -- Increment the counter.
end if;
end if;
end if;
end process;
end Behavioral;
我認爲這需要一些澄清。所以你將一個'value'傳遞給一個模塊,它的'count'被初始化爲0,然後使用參考時鐘輸入遞增到'value',然後輸出一個邏輯1?何時重置? –
您可能需要某種形式的if語句,因爲這將允許您使用寄存器定義順序行爲。 –
非常感謝您的快速回復,是的,這就是我想要做的,我知道我可以通過if語句來實現,就像輸入=「0000」,然後a = 0一樣,但我在想的是任何更簡單的方法來這樣做? – tedhan