有幾件事情錯了,側翻凱文提到,還有一些錯別字的名字:
此:
package compt is
shared variable compteur1,compteur2 : natural range 0 to 15;
end package;
library ieee;
use ieee.std_logic_1164.all;
use work.compt.all;
entity foo is
end entity;
architecture fum of foo is
signal H: std_logic := '0';
begin
CLOCK:
process
begin
wait for 10 ns;
H <= not H;
if Now > 600 ns then
wait;
end if;
end process;
UNLABELLED:
process(H)
begin
if(rising_edge(H)) then
compteur1 := compteur1 + 1;
report "compteur1 = " & natural'image(compteur1);
if (compteur1 = 9) then
compteur2 := compteur2 + 1;
report "compteur2 = " & natural'image(compteur2);
end if;
end if;
end process;
end architecture;
,因爲你增加compteur1超越它必將使運行時錯誤:
compteur.vhdl:31:13:@10ns:(report note): compteur1 = 1
compteur.vhdl:31:13:@30ns:(report note): compteur1 = 2
compteur.vhdl:31:13:@50ns:(report note): compteur1 = 3
compteur.vhdl:31:13:@70ns:(report note): compteur1 = 4
compteur.vhdl:31:13:@90ns:(report note): compteur1 = 5
compteur.vhdl:31:13:@110ns:(report note): compteur1 = 6
compteur.vhdl:31:13:@130ns:(report note): compteur1 = 7
compteur.vhdl:31:13:@150ns:(report note): compteur1 = 8
compteur.vhdl:31:13:@170ns:(report note): compteur1 = 9
compteur.vhdl:34:17:@170ns:(report note): compteur2 = 1
compteur.vhdl:31:13:@190ns:(report note): compteur1 = 10
compteur.vhdl:31:13:@210ns:(report note): compteur1 = 11
compteur.vhdl:31:13:@230ns:(report note): compteur1 = 12
compteur.vhdl:31:13:@250ns:(report note): compteur1 = 13
compteur.vhdl:31:13:@270ns:(report note): compteur1 = 14
compteur.vhdl:31:13:@290ns:(report note): compteur1 = 15
./foo:error: bound check failure at compteur.vhdl:30
./foo:error: simulation failed
ghdl: compilation error
因爲VHDL沒有模塊化整數類型和您使用的共享變量,您可以測試,你增加:
UNLABELLED:
process(H)
begin
if(rising_edge(H)) then
if compteur1 = 15 then
compteur1 := 0;
else
compteur1 := compteur1 + 1;
end if;
report "compteur1 = " & natural'image(compteur1);
if (compteur1 = 9) then
compteur2 := compteur2 + 1;
report "compteur2 = " & natural'image(compteur2);
end if;
end if;
end process;
這會給你compteur2倍數的增量:
compteur.vhdl:35:13:@10ns:(report note): compteur1 = 1
compteur.vhdl:35:13:@30ns:(report note): compteur1 = 2
compteur.vhdl:35:13:@50ns:(report note): compteur1 = 3
compteur.vhdl:35:13:@70ns:(report note): compteur1 = 4
compteur.vhdl:35:13:@90ns:(report note): compteur1 = 5
compteur.vhdl:35:13:@110ns:(report note): compteur1 = 6
compteur.vhdl:35:13:@130ns:(report note): compteur1 = 7
compteur.vhdl:35:13:@150ns:(report note): compteur1 = 8
compteur.vhdl:35:13:@170ns:(report note): compteur1 = 9
compteur.vhdl:38:17:@170ns:(report note): compteur2 = 1
compteur.vhdl:35:13:@190ns:(report note): compteur1 = 10
compteur.vhdl:35:13:@210ns:(report note): compteur1 = 11
compteur.vhdl:35:13:@230ns:(report note): compteur1 = 12
compteur.vhdl:35:13:@250ns:(report note): compteur1 = 13
compteur.vhdl:35:13:@270ns:(report note): compteur1 = 14
compteur.vhdl:35:13:@290ns:(report note): compteur1 = 15
compteur.vhdl:35:13:@310ns:(report note): compteur1 = 0
compteur.vhdl:35:13:@330ns:(report note): compteur1 = 1
compteur.vhdl:35:13:@350ns:(report note): compteur1 = 2
compteur.vhdl:35:13:@370ns:(report note): compteur1 = 3
compteur.vhdl:35:13:@390ns:(report note): compteur1 = 4
compteur.vhdl:35:13:@410ns:(report note): compteur1 = 5
compteur.vhdl:35:13:@430ns:(report note): compteur1 = 6
compteur.vhdl:35:13:@450ns:(report note): compteur1 = 7
compteur.vhdl:35:13:@470ns:(report note): compteur1 = 8
compteur.vhdl:35:13:@490ns:(report note): compteur1 = 9
compteur.vhdl:38:17:@490ns:(report note): compteur2 = 2
compteur.vhdl:35:13:@510ns:(report note): compteur1 = 10
compteur.vhdl:35:13:@530ns:(report note): compteur1 = 11
compteur.vhdl:35:13:@550ns:(report note): compteur1 = 12
compteur.vhdl:35:13:@570ns:(report note): compteur1 = 13
compteur.vhdl:35:13:@590ns:(report note): compteur1 = 14
compteur.vhdl:35:13:@610ns:(report note): compteur1 = 15
這正常退出(見時鐘進程if語句)。
看着時間標記,你還會看到compteur1在同一邊緣上使用變量導致的compteur2增量變爲9。
當使用遞增之前,你可能會考慮估計變量:
UNLABELLED:
process(H)
begin
if(rising_edge(H)) then
if (compteur1 = 9) then
compteur2 := compteur2 + 1;
report "compteur2 = " & natural'image(compteur2);
end if;
if compteur1 = 15 then
compteur1 := 0;
else
compteur1 := compteur1 + 1;
end if;
report "compteur1 = " & natural'image(compteur1);
end if;
end process;
這將是如果你使用的信號的順序一致:
compteur.vhdl:39:13:@490ns:(report note): compteur1 = 9
compteur.vhdl:32:17:@510ns:(report note): compteur2 = 2
compteur.vhdl:39:13:@510ns:(report note): compteur1 = 10
compteur.vhdl:39:13:@530ns:(report note): compteur1 = 11
下一個時鐘邊沿遞增compteur2。
正如QuantumRipple指出
如果你簡單地回答一個問題,而不是提供完整的解決方案,你可能會錯過一些東西。在這種情況下,側翻在comptuer2的影響,這是可以治癒的,他表示做同樣的事情吧:
process(H)
begin
if rising_edge(H) then
if compteur1 = 9 then
if compteur2 = 15 then
compteur2 := 0;
else
compteur2 := compteur2 + 1;
end if;
report "compteur2 = " & natural'image(compteur2);
end if;
if compteur1 = 15 then
compteur1 := 0;
else
compteur1 := compteur1 + 1;
end if;
report "compteur1 = " & natural'image(compteur1);
end if;
end process;
有我們能夠立刻在問題的原代碼介意至少一個其他特點。信號分配中不涉及計數器變量,其中表示不會由綜合產生硬件。
看起來很可疑,就好像第一行有一個錯字(*除了*一般的電腦的奇怪拼寫)。確保重新輸入的代碼中沒有其他錯誤,呃? – 2015-01-26 23:44:16
@NathanTuggy - 我相信compteur是法國人的反擊。問題是隻有拼寫錯誤。凱文本來可以抓住他們。 – user1155120 2015-01-27 00:01:59
@DavidKoontz當然,但爲什麼有人用中文用戶名使用法語變量名? – 2015-01-27 00:04:31