串行加法器的VHDL代码
描述4位串行加法器的状态转移图,如图 3。电路保持在S0状态直到接收到开始信号(St=1),然后电路输出En=1并且转入S1状态。然后在连续的时钟周期内,输入另外的三个En=1信号。图中的短划线说明,一旦进入了S1状态,电路将继续运行不管St的值是什么。

图 3 状态转换图
具体的实现代码,参考下文,这里全加器的进位存储在触发器中,同时寄存器在时钟的下降沿进行移位。
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 09:45:07 11/18/2007
-- Design Name:
-- Module Name: serial - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity serial is
port(St: in std_logic;
Clk: in std_logic;
Xout: out std_logic_vector(3 downto 0));
end serial;
architecture Behavioral of serial is
signal X, Y: std_logic_vector(3 downto 0);
signal En: std_logic;
signal Ci, Ciplus: std_logic;
signal Sumi: std_logic;
signal State, NextState: integer range 0 to 3;
begin
Sumi <= X(0) xor Y(0) xor Ci;
Ciplus <= (Ci and X(0)) or (Ci and Y(0)) or (X(0) and Y(0));
Xout <= X;
process(State, En)
begin
case State is
when 0 =>
if St ='1' then En <='1'; NextState <= 1;
else En <= '0'; NextState <= 0; end if;
when 1 => En <= '1'; NextState <= 2;
when 2 => En <= '1'; NextState <= 3;
when 3 => En <= '1'; NextState <= 0;
end case;
end process;
process (Clk)
begin
if (Clk' event and Clk = '0') then
State <= NextState;
if En = '1' then
X <= Sumi & X(3 downto 1);
Y <= Y(0) & Y(3 downto 1);
Ci <= Ciplus;
end if;
end if;
end process;
end Behavioral;
表1给出了该串行加法器的资源使用状况。
表 1 资源使用状况
Device Utilization Summary |
| Logic Utilization | Used | Available | Utilization | Note(s) |
| Number of Slice Flip Flops | 8 | 1,920 | 1% | |
| Number of 4 input LUTs | 3 | 1,920 | 1% | |
| Logic Distribution | | | | |
| Number of occupied Slices | 7 | 960 | 1% | |
| Number of Slices containing only related
logic | 7 | 7 |