2013-03-11 71 views
3

我想單獨設置一個std_logic_vector的位,以便輕鬆設置單個位或一組位的註釋。以下是我有:VHDL std_logic_vector索引與「downto」

signal DataOut : std_logic_vector(7 downto 0); 
... 
DataOut <= (      5=>'1',  -- Instruction defined 
            4=>'1',  -- Data length control bit, high=8bit bus mode selected 
            3=>'1',  -- Display Line Number ctrl bit, high & N3 option pin to VDD=3 lines display 
            2=>'0',  -- Double height font type control byte, not selected 
            1 downto 0=>"01", -- Select Instruction table1 
            others=>'0' -- for bits 6,7 
            ); 

不過,我有一個問題與「DOWNTO」的聲明,我得到採用Xilinx ISE以下錯誤:

Type std_ulogic does not match with a string litteral 

任何解決方案,以避免使用等效

1=>'0', 
0=>'1', 

並允許我逐塊設置?

回答

7

當A是數組的元素時,賦值X downto Y => 'A'正確。例如,該片段是正確的:

1 downto 0 => '1', 

而且這個片段是錯誤的:

1 downto 0 => "01", 

因此,你的任務是非法的。當你的代碼,你可以分配爲:

DataOut <= (      5 downto 3 =>'1',  
            2 downto 1 =>'0',  
            0 => '1', 
            others=>'0' 
            ); 

如果您想訪問/通過陣列的費爾德分配,可以使用串聯:

DataOut <= Something_0 & Something_1 & "01"; 

雖然Something_*std_logic_vector

2

做到這一點:

DataOut(7 downto 6)<="00"; 
DataOut(5)<='1'; 
DataOut(4)<='1'; 
DataOut(3)<='1'; 
DataOut(2)<='1'; 
DataOut(1 downto 0)<="01"; 
+0

是,它是一種解決方案,但與'1 =>'0'相同, 0 =>'1','。如果你只是想初始化矢量,例如,這是更好,但還不完美... – feronjb 2013-03-11 11:55:02

+0

將位1..0設置爲零,可以使用「,... 1 downto 0 =>'0',...」(與「其他」相同)。 – baldyHDL 2013-03-11 12:50:44

3

另一個答案是用「&」,它失去了命名關聯的清晰度串聯,雖然你可以使用命名常量恢復一些自我文檔的

constant Instr_Defined : std_ulogic := '1'; 
constant Bus_8_Bit  : std_ulogic := '1'; 

DataOut <= "00" & Instr_Defined 
       & Bus_8_Bit 
       & '1'  -- description 
       & '0'  -- ditto 
       & "01"; 

另一個答案是編寫一個函數來創建指令:這可以使主流程非常簡單明瞭,同時保持指令編碼完全獨立並且在一個地方,例如在任何地方使用,你需要知道的指令格式(也許在一個彙編程序以及對CPU)包

DataOut <= Encode_Instruction(Instr_Defined, Bus_8_Bit, Font_Mode); 

這是確定使用任何上述技術,但是冗長的,函數體。越明確越詳細越好;它不會讓主設計混亂,所以除非改變指令格式,否則你很少看它。