CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
add3x2.vhd
Go to the documentation of this file.
1 
11 
12 LIBRARY ieee ;
13 USE ieee.std_logic_1164.all;
14 USE ieee.numeric_std.all;
15 Library cmm;
16 
17 ENTITY add3x2 IS
18  PORT(
19  a : IN std_logic_vector (2 DOWNTO 0);
20  b : IN std_logic_vector (2 DOWNTO 0);
21  sum : OUT std_logic_vector (2 DOWNTO 0);
22  clk : IN std_logic
23  );
24 
25 -- Declarations
26 
27 END add3x2 ;
28 
29 -- hds interface_end
30 --------------------------------------------------------------------------------
31 ARCHITECTURE rtl_abx OF add3x2 IS
32 --------------------------------------------------------------------------------
33 -- 3-bit by 2-value adder, saturates at 7
34 --
35  ----------
36  function add2 (
37  a: std_logic_vector (2 downto 0);
38  b: std_logic_vector (2 downto 0)
39  )
40  return std_logic_vector is
41  ----------
42  -- add two 3-bit numbers, return 3-bit result that saturates at 7.
43  --
44  variable isum: integer range 0 to 28;
45  variable vsum: std_logic_vector(3 downto 0);
46  ----------
47  begin
48  isum := to_integer(unsigned(a))
49  + to_integer(unsigned(b));
50  vsum := std_logic_vector(to_unsigned(isum, 4));
51  if (vsum(3) = '1') then
52  return "111";
53  else
54  return vsum(2 downto 0);
55  end if;
56  end add2;
57 
58 
59 --------------------------------------------------------------------------------
60 BEGIN
61 
62  clokprok: process (clk, a, b)
63  --
64  variable isum: integer range 0 to 14;
65  variable vsum: std_logic_vector(3 downto 0);
66  --
67  begin
68  if (clk'event and clk = '1') then
69  --
70  sum <= add2(a, b);
71  end if;
72  end process;
73 
74 END rtl_abx;
clokprokclk,a,b
Definition: add3x2.vhd:62
_library_ ieeeieee
Definition: add2x2.vhd:11
out sumstd_logic_vector (2 downto 0)
Definition: add3x2.vhd:21
std_logic_vector add2a,b,
Definition: add3x2.vhd:36
in clkstd_logic
Definition: add3x2.vhd:22
in bstd_logic_vector (2 downto 0)
Definition: add3x2.vhd:20
in astd_logic_vector (2 downto 0)
Definition: add3x2.vhd:19