FPGA
现场可编程逻辑门阵列,硬件描述语言Verilog和VHDL;
input, output
不能给output初始值,不然在simulate的时候很有可能发生错误.
在进行clear的时候,不要给clock和output的signal进行值clear,在simulate的时候wave会发生错误
Signal or Variable
- 如果要使用temp := temp + 1去计算某样事物,那么最好使用variable. 例如
process(CLK) -- variable 必须在process中declare variable count : integer range 0 to 32; begin count := 0; if (CLK'event and CLK = '1') then for i in 31 downto 0 loop if DATAIN(i) = '1' then count := count + 1; end if; end loop; if count > 16 then DATAOUT <= '1'; else DATAOUT <= '0'; end if; end if; end process;
Process
Process中的statement是从上到下按顺序执行(sequential statement). 注意⚠️:FPGA中的普通statement实际上都是在同一个cycle中的parallel running.
- Sensitive list: Process中的sensitive list至关重要,当sensitive中的signal发生变化时,process才会被trigger并且执行其中的sequential statement. 例如
-- assume code here -- clk in sensitive list Process(clk) begin -- event 实际上并不需要,但是某些synthesis工具需要 if (clk'event and clk = '1') then -- statement end if; end process; -- assume code here
Package
IEEE.std_logic_1164.all
- wait: Wait for and wait are useful in behavioural models and test benches. Wait on it's own suspends a process indefinitely. reference from https://www.ics.uci.edu/~jmoorkan/vhdlref/waits.html.
直接使用wait会使process无限期等待自己,其实相当于结束该process.
wait会经常使用在testbench当中.
IEEE.numeric_std.all
Function
shift_left(unsigned, natural);
把unsigned二进制向左进位natrual位.to_integer(unsigned);
如字面意思.