所以我一直在使用VHDL創建一個寄存器,如果LOAD爲1,它將在輸入X中加載,並以串行方式輸出數據,基本上是並行串行輸出寄存器。輸入X是一個4位(3 Downto 0)輸入,當寄存器成功輸出輸入中的所有btis時,我想讓程序執行的操作始終輸出0。VHDL移位寄存器使用信號和變量編程不同的結果
將「count」定義爲信號時有效,但是,如果將count定義爲變量,則無論負載是否爲1,輸出都爲常量0。我的代碼如下所示:
entity qn14 is
Port (clk : in STD_LOGIC;
reset : in STD_LOGIC;
LOAD : in STD_LOGIC;
X : in STD_LOGIC_VECTOR (3 downto 0);
output : out STD_LOGIC);
end qn14;
architecture qn14_beh of qn14 is
type states is (IDLE , SHIFT);
signal state : states;
signal count: STD_LOGIC_VECTOR(1 downto 0);
begin
process(clk , reset)
variable temp: STD_LOGIC;
variable data: STD_LOGIC_VECTOR(3 downto 0);
begin
if reset = '1' then
state <= IDLE;
count <= "00";
output <= '0';
elsif clk'event and clk = '1' then
case state is
when IDLE =>
if LOAD = '1' then
data := X;
output <= '0';
state <= SHIFT;
elsif LOAD = '0' then
output <= '0';
end if;
when SHIFT =>
if LOAD ='1' then
output <= '0';
elsif LOAD = '0' then
output <= data(conv_integer(count));
count <= count + 1;
if (count >= 3) then
state <= IDLE ;
end if;
end if;
end case;
end if;
end process;
end qn14_beh;
希望能夠就此澄清。
謝謝。
***它將「count」定義爲信號時有效,但是,如果將count定義爲變量,則無論負載是否爲「1」,輸出都爲常量0。 ,但你的問題是什麼?您不會將'count'作爲變量顯示版本,並且您的代碼不是[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。賦值給變量是立即的,新值可以立即在表達式中求值。計劃分配的信號值,預測的輸出波形和未來模擬週期中可用的值。 – user1155120 2014-11-06 18:59:09