OpenCores
URL https://opencores.org/ocsvn/artificial_neural_network/artificial_neural_network/trunk

Subversion Repositories artificial_neural_network

[/] [artificial_neural_network/] [trunk/] [ANN_kernel/] [RTL_VHDL_files/] [shiftreg_pl.vhd] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ojosynariz
----------------------------------------------------------------------------------
2
-- Company: CEI - UPM
3
-- Engineer: David Aledo
4
--
5
-- Create Date:    11:31:38 05/14/2014
6
-- Design Name:    Configurable ANN
7
-- Module Name:    shiftreg_pl - Behavioral
8
-- Project Name:
9
-- Target Devices:
10
-- Tool versions:
11
-- Description: Shift register with parallel load.
12
--
13
-- Dependencies:
14
--
15
-- Revision:
16
-- Revision 0.01 - File Created
17
-- Additional Comments:
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
 
23
 
24
entity shiftreg_pl is
25
   generic
26
   (
27
      Nreg : natural := 64;  ---- Number of elements
28
      Nbit : natural := 8    ---- Bit width
29
   );
30
 
31
   port
32
   (
33
      -- Input ports
34
      reset   : in  std_logic;
35
      clk     : in  std_logic;
36
      run_in  : in  std_logic; -- Start and input data validation
37
      inputs  : in  std_logic_vector((Nbit*Nreg)-1 downto 0); -- Input data (parallel)
38
      -- Output ports
39
      run_out : out std_logic; -- Output data validation, run_in for the next layer
40
      outputs : out std_logic_vector(Nbit-1 downto 0) -- Output data (serial)
41
   );
42
end shiftreg_pl;
43
 
44
architecture Behavioral of shiftreg_pl is
45
 
46
   signal count : integer range 0 to Nreg-1;
47
   signal en_r : std_logic;    --- Shift register enable
48
   type dreg_type is array (Nreg-1 downto 0) of std_logic_vector(Nbit-1 downto 0); -- Shift register type
49
   signal dreg : dreg_type;   ---- Shift register
50
   type reg_st_type is (idle, counting); -- Register state type
51
   signal reg_st : reg_st_type; -- Register state
52
 
53
begin
54
 
55
-- Shift register with parallel load:
56
   process (clk)
57
   begin
58
      if clk'event and clk = '1' then
59
         if reset = '1' then
60
            dreg <= (others=> (others => '0'));
61
         else
62
            if en_r = '1' then -- Shift register enable
63
               if count = 0 then -- Parallel load
64
                  for i in 0 to Nreg-1 loop
65
                     dreg(i) <= inputs((Nbit*(i+1))-1 downto Nbit*i);
66
                  end loop;
67
               else  -- Other cycles, register is shifted
68
                  dreg(Nreg-1) <= (others => '-');
69
                  shift:
70
                  for i in 1 to Nreg-1 loop
71
                     dreg(i-1) <= dreg(i);
72
                  end loop;
73
               end if;
74
            end if;
75
         end if;
76
      end if;
77
   end process;
78
   outputs <= dreg(0);
79
 
80
-- Shift register control
81
   process (clk)
82
   begin
83
      if clk'event and clk = '1' then
84
         if reset = '1' then
85
            count <= 0;
86
            reg_st <= idle;
87
            run_out <= '0';
88
         else
89
            run_out <= en_r;
90
            case reg_st is
91
               when idle =>
92
                  if run_in = '1' then
93
                     reg_st <= counting;
94
                  else
95
                     reg_st <= idle;
96
                  end if;
97
               when counting =>
98
                  if count = (Nreg-1) then
99
                     reg_st <= idle;
100
                     count <= 0;
101
                  else
102
                     reg_st <= counting;
103
                     count <= count +1;
104
                  end if;
105
            end case;
106
         end if;
107
      end if;
108
   end process;
109
   process (reg_st)
110
   begin
111
      if reg_st = counting then
112
         en_r <= '1';
113
      else
114
         en_r <= '0';
115
      end if;
116
   end process;
117
 
118
end Behavioral;
119
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.