| 1 |
2 |
panda_emc |
-----------------------------------------------------------------------------------------------
|
| 2 |
|
|
--
|
| 3 |
|
|
-- Copyright (C) 2011 Peter Lemmens, PANDA collaboration
|
| 4 |
|
|
-- p.j.j.lemmens@rug.nl
|
| 5 |
|
|
-- http://www-panda.gsi.de
|
| 6 |
|
|
--
|
| 7 |
|
|
-- As a reference, please use:
|
| 8 |
|
|
-- E. Guliyev, M. Kavatsyuk, P.J.J. Lemmens, G. Tambave, H. Loehner,
|
| 9 |
|
|
-- "VHDL Implementation of Feature-Extraction Algorithm for the PANDA Electromagnetic Calorimeter"
|
| 10 |
|
|
-- Nuclear Inst. and Methods in Physics Research, A ....
|
| 11 |
|
|
--
|
| 12 |
|
|
--
|
| 13 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 14 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by
|
| 15 |
|
|
-- the Free Software Foundation; either version 3 of the License, or
|
| 16 |
|
|
-- (at your option) any later version.
|
| 17 |
|
|
--
|
| 18 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 19 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
-- GNU Lesser General Public License for more details.
|
| 22 |
|
|
--
|
| 23 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 24 |
|
|
-- along with this program; if not, write to the Free Software
|
| 25 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
|
| 26 |
|
|
--
|
| 27 |
|
|
-----------------------------------------------------------------------------------------------
|
| 28 |
|
|
-----------------------------------------------------------------------------------------------
|
| 29 |
|
|
-- Company : KVI (Kernfysisch Versneller Instituut -- Groningen, The Netherlands
|
| 30 |
|
|
-- Author : P.J.J. Lemmens
|
| 31 |
|
|
-- Design Name : Feature Extraction
|
| 32 |
|
|
-- Module Name : SISO_sub_a.vhd
|
| 33 |
|
|
-- Description : Signed In Signed Out Subtractor Asynchronous
|
| 34 |
|
|
--
|
| 35 |
|
|
-----------------------------------------------------------------------------------------------
|
| 36 |
|
|
|
| 37 |
|
|
library IEEE;
|
| 38 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 39 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 40 |
|
|
use IEEE.STD_LOGIC_SIGNED.ALL;
|
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
|
|
entity SISO_sub_a is
|
| 44 |
|
|
generic( A_MINUS_B : boolean := true);
|
| 45 |
|
|
Port (dataa : in STD_LOGIC_VECTOR;
|
| 46 |
|
|
datab : in STD_LOGIC_VECTOR;
|
| 47 |
|
|
result : out STD_LOGIC_VECTOR
|
| 48 |
|
|
);
|
| 49 |
|
|
end SISO_sub_a;
|
| 50 |
|
|
|
| 51 |
|
|
architecture Behavioral of SISO_sub_a is
|
| 52 |
|
|
|
| 53 |
|
|
constant WIDTH : natural := dataa'length;
|
| 54 |
|
|
constant MAXVAL : integer := 2**(WIDTH - 1) - 1;
|
| 55 |
|
|
constant MINVAL : integer := - 2**(WIDTH - 1);
|
| 56 |
|
|
|
| 57 |
|
|
signal a_in_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
| 58 |
|
|
signal b_in_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
| 59 |
|
|
signal diff_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
| 60 |
|
|
signal status_S : std_logic_vector(1 downto 0) := (others => '0');
|
| 61 |
|
|
-- signal overflow_S : std_logic := '0';
|
| 62 |
|
|
|
| 63 |
|
|
begin
|
| 64 |
|
|
|
| 65 |
|
|
a_in_S <= dataa(dataa'high) & dataa;
|
| 66 |
|
|
b_in_S <= datab(datab'high) & datab;
|
| 67 |
|
|
|
| 68 |
|
|
diff_S <= conv_std_logic_vector((conv_integer(signed(a_in_S)) - conv_integer(signed(b_in_S))), WIDTH + 1);
|
| 69 |
|
|
status_S <= diff_S(WIDTH) & diff_S(WIDTH - 1);
|
| 70 |
|
|
-- overflow_S <= diff_S(WIDTH) XOR diff_S(WIDTH - 1);
|
| 71 |
|
|
|
| 72 |
|
|
aminusb:
|
| 73 |
|
|
if (A_MINUS_B = true) generate
|
| 74 |
|
|
diff_S <= conv_std_logic_vector((conv_integer(signed(a_in_S)) - conv_integer(signed(b_in_S))), WIDTH + 1);
|
| 75 |
|
|
|
| 76 |
|
|
status_S <= diff_S(WIDTH) & diff_S(WIDTH - 1);
|
| 77 |
|
|
-- overflow_S <= diff_S(WIDTH) XOR diff_S(WIDTH - 1);
|
| 78 |
|
|
|
| 79 |
|
|
result <= conv_std_logic_vector(MAXVAL, WIDTH) when (status_S = b"01") else
|
| 80 |
|
|
conv_std_logic_vector(MINVAL, WIDTH) when (status_S = b"10") else
|
| 81 |
|
|
conv_std_logic_vector(conv_integer(signed(diff_S)), WIDTH);
|
| 82 |
|
|
end generate;
|
| 83 |
|
|
|
| 84 |
|
|
bminusa:
|
| 85 |
|
|
if (A_MINUS_B = false) generate
|
| 86 |
|
|
diff_S <= conv_std_logic_vector((conv_integer(signed(b_in_S)) - conv_integer(signed(a_in_S))), WIDTH + 1);
|
| 87 |
|
|
|
| 88 |
|
|
status_S <= diff_S(WIDTH) & diff_S(WIDTH - 1);
|
| 89 |
|
|
-- overflow_S <= diff_S(WIDTH) XOR diff_S(WIDTH - 1);
|
| 90 |
|
|
|
| 91 |
|
|
result <= conv_std_logic_vector(MAXVAL, WIDTH) when (status_S = b"01") else
|
| 92 |
|
|
conv_std_logic_vector(MINVAL, WIDTH) when (status_S = b"10") else
|
| 93 |
|
|
conv_std_logic_vector(conv_integer(signed(diff_S)), WIDTH);
|
| 94 |
|
|
end generate;
|
| 95 |
|
|
|
| 96 |
|
|
end Behavioral;
|
| 97 |
|
|
|