Serial sequential adder  v.1.0
Example documentation project, author Vladimir Petrović
fsm_adder.vhd
Go to the documentation of this file.
1 
22 
23 library ieee;
24 use ieee.std_logic_1164.all;
25 
42 entity fsm_adder is
43  generic (
44  reg_width : integer := 4
45  );
46 
47  port
48  (
50  reset : in std_logic;
52  clk : in std_logic;
53 
55  par_add : in std_logic;
57  serial_active : in std_logic;
58 
60  a_s : in std_logic;
62  b_s : in std_logic;
63 
65  a_p : in std_logic_vector(reg_width-1 downto 0);
67  b_p : in std_logic_vector(reg_width-1 downto 0);
68 
70  sum_s : out std_logic;
72  sum_p : out std_logic_vector(reg_width downto 0);
73 
75  out_valid: out std_logic
76  );
77 end fsm_adder;
78 
87 architecture fsm_adder_behav of fsm_adder is
88  type state_type is (idle, load_data, wait_shift_reg_full, calculate_paralel, data_valid_state, calculate_serial);
90 
91  component shiftreg is
92  generic (
93  reg_width : integer := 8
94  );
95  port (
96  clk : in std_logic;
97  reset : in std_logic;
98  load : in std_logic;
99  do_shift : in std_logic;
100  sin : in std_logic;
101  sout : out std_logic;
102  pin : in std_logic_vector(reg_width - 1 downto 0);
103  pout : out std_logic_vector(reg_width - 1 downto 0)
104  );
105  end component;
106 
107  component serial_adder is
108  port
109  (
110  reset : in std_logic;
111  clk : in std_logic;
112  a_s : in std_logic;
113  b_s : in std_logic;
114  sum_s : out std_logic
115  );
116  end component;
117 
118  signal load: std_logic;
119  signal do_shift: std_logic;
120  signal a_s_out: std_logic;
121  signal b_s_out: std_logic;
122  signal sum_in: std_logic;
123  signal generic_pin_for_sum_reg: std_logic_vector(reg_width downto 0);
124 
125  signal timeout_counter: integer range 0 to reg_width+1;
126 
127 begin
128  shift_reg_a: shiftreg generic map (reg_width) port map (clk, reset, load, do_shift, a_s, a_s_out, a_p, pout => open);
129  shift_reg_b: shiftreg generic map (reg_width) port map (clk, reset, load, do_shift, b_s, b_s_out, b_p, pout => open);
130  shift_reg_sum: shiftreg generic map (reg_width+1) port map (clk, reset, load, do_shift, sum_in, sum_s, generic_pin_for_sum_reg, sum_p);
131  generic_pin_for_sum_reg <= (others => '0');
132 
134 
135  fsm_adder_state_transition: process (clk, reset) is
136  begin
137  if (reset = '1') then
138  state_reg <= idle;
139  elsif (rising_edge(clk)) then
141  end if;
142  end process;
143 
144  fsm_adder_next_state_logic: process (state_reg, par_add, serial_active, timeout_counter) is
145  begin
146  case (state_reg) is
147  when idle =>
148  if (par_add = '1') then
149  next_state <= load_data;
150  elsif (serial_active = '1') then
151  next_state <= wait_shift_reg_full;
152  else
153  next_state <= idle;
154  end if;
155 
156  when load_data =>
157  next_state <= calculate_paralel;
158 
159  when wait_shift_reg_full =>
160  if (timeout_counter = 0) then
161  next_state <= calculate_serial;
162  else
163  next_state <= wait_shift_reg_full;
164  end if;
165 
166  when calculate_paralel =>
167  if (timeout_counter = 0) then
168  next_state <= data_valid_state;
169  else
170  next_state <= calculate_paralel;
171  end if;
172 
173  when calculate_serial =>
174  if (serial_active = '0') then
175  next_state <= idle;
176  else
177  next_state <= calculate_serial;
178  end if;
179 
180  when data_valid_state =>
181  next_state <= idle;
182  end case;
183  end process;
184 
185  shift_reg_logic: process (state_reg, next_state, serial_active, timeout_counter) is
186  begin
187  case (state_reg) is
188  when idle =>
189  load <= '0';
190  do_shift <= '0';
191  out_valid <= '0';
192  when load_data =>
193  load <= '1';
194  do_shift <= '0';
195  out_valid <= '0';
196  when wait_shift_reg_full =>
197  load <= '0';
198  do_shift <= '1';
199  out_valid <= '0';
200  when calculate_paralel =>
201  load <= '0';
202  do_shift <= '1';
203  out_valid <= '0';
204  when calculate_serial =>
205  load <= '0';
206  do_shift <= '1';
207  if ((timeout_counter /= 0) or (next_state = idle)) then
208  out_valid <= '0';
209  else
210  out_valid <= '1';
211  end if;
212  when data_valid_state =>
213  load <= '0';
214  do_shift <= '0';
215  out_valid <= '1';
216  end case;
217  end process;
218 
219  cnt_process: process (clk) is
220  begin
221  if (rising_edge(clk)) then
222  case (state_reg) is
223  when load_data =>
225  when wait_shift_reg_full =>
226  if (timeout_counter = 0) then
228  else
230  end if;
231  when calculate_paralel =>
232  if (timeout_counter /= 0) then
234  end if;
235  when calculate_serial =>
236  if (timeout_counter /= 0) then
238  end if;
239  when others =>
240  timeout_counter <= reg_width - 1;
241  end case;
242  end if;
243  end process;
244 
245 end fsm_adder_behav;
246 
247 
in resetstd_logic
Reset signal.
Definition: fsm_adder.vhd:50
in clkstd_logic
Definition: shiftreg.vhd:37
Entitiy declaration for shiftreg.
Definition: shiftreg.vhd:32
in a_sstd_logic
Serial input 1.
in clkstd_logic
clk signal
Definition: fsm_adder.vhd:52
in b_sstd_logic
Serial input 2.
Definition: fsm_adder.vhd:62
in loadstd_logic
Definition: shiftreg.vhd:39
in resetstd_logic
Sequential circuit reset signal.
in resetstd_logic
Definition: shiftreg.vhd:38
shiftreg shift_reg_sumshift_reg_sum
Definition: fsm_adder.vhd:130
out soutstd_logic
Definition: shiftreg.vhd:41
integer range 0 to reg_width+ 1 timeout_counter
Definition: fsm_adder.vhd:125
out out_validstd_logic
Output valid.
Definition: fsm_adder.vhd:76
reg_widthinteger := 8
Definition: shiftreg.vhd:35
in clkstd_logic
clk signal
in b_pstd_logic_vector( reg_width- 1 downto 0)
Paralel input 2.
Definition: fsm_adder.vhd:67
in b_sstd_logic
Serial input 2.
in a_sstd_logic
Serial input 1.
Definition: fsm_adder.vhd:60
in do_shiftstd_logic
Definition: shiftreg.vhd:39
in pinstd_logic_vector( reg_width- 1 downto 0)
Definition: shiftreg.vhd:42
serial_adder serial_adder_instserial_adder_inst
Definition: fsm_adder.vhd:133
std_logic_vector( reg_width downto 0) generic_pin_for_sum_reg
Definition: fsm_adder.vhd:123
out sum_sstd_logic
Serial output sum.
Definition: fsm_adder.vhd:70
out sum_sstd_logic
Serial output sum.
reg_widthinteger := 4
Definition: fsm_adder.vhd:45
shiftreg shift_reg_ashift_reg_a
Definition: fsm_adder.vhd:128
out poutstd_logic_vector( reg_width- 1 downto 0)
Definition: shiftreg.vhd:44
Entitiy declaration for serial_adder.
in par_addstd_logic
Paralel input/output data write/read control signal.
Definition: fsm_adder.vhd:55
in a_pstd_logic_vector( reg_width- 1 downto 0)
Paralel input 1.
Definition: fsm_adder.vhd:65
shiftreg shift_reg_bshift_reg_b
Definition: fsm_adder.vhd:129
in serial_activestd_logic
Serial input/output data write/read control signal.
Definition: fsm_adder.vhd:57
in sinstd_logic
Definition: shiftreg.vhd:40
out sum_pstd_logic_vector( reg_width downto 0)
Paralel output sum.
Definition: fsm_adder.vhd:72
(idle,load_data,wait_shift_reg_full,calculate_paralel,data_valid_state,calculate_serial) state_type
Definition: fsm_adder.vhd:88
Entitiy declaration for fsm_adder component.
Definition: fsm_adder.vhd:42