6 - Synchronous elements - a 4-bit accumulator
This example will focus on:
- VHDL synchronous processes with combinatory logic
- RTL (Register Transfer Level)
- IEEE unsigned type
- IEEE "others" assignment
Let's implement a four-bit accumulator. An accumulator works by adding an input value to the current value each clock
cycle. Here's an example of how it works (inputs always before clock, outputs after). DIN and DOUT were converted to
||DOUT (after clock)
Here's the diagram:
entity accumulator is
DIN: in std_logic_vector(3 downto 0);
CLK: in std_logic;
RST: in std_logic;
DOUT: out std_logic_vector(3 downto 0)
end entity accumulator;
architecture behave of accumulator is
signal our_ffs: std_logic_vector(3 downto 0);
if rising_edge(CLK) then
if RST='1' then
our_ffs <= (others => '0'); -- reset all of flip flop values to 0
our_ffs <= std_logic_vector( unsigned(our_ffs) + unsigned(DIN) );
-- Assign output
DOUT <= our_ffs;
Let's see what out synthesis tool now says about this design:
* HDL Synthesis *
Synthesizing Unit <accumulator>.
Found 4-bit up accumulator for signal <our_ffs>.
inferred 1 Accumulator(s).
Unit <accumulator> synthesized.
Advanced HDL Synthesis Report
# Accumulators : 1
4-bit up accumulator : 1
Wow, our synthesis tool was even clever than we thought. Instead of actually inferring four flip-flops and an adder,
it recognized the design as a 4-bit up accumulator. Excellent!
But let's see what actually will go into the FPGA.
* Final Report *
Cell Usage :
# BELS : 6
# LUT2 : 1
# LUT2_L : 1
# LUT3 : 1
# LUT4 : 2
# LUT4_D : 1
# FlipFlops/Latches : 4
# FDR : 4
Ah, there are the four flip flops, and with them a few LUT. A LUT is a Look-Up-Table, and it's used by FPGA to
implement combinatory logic. On this design, those LUT were created to implement the 4-bit adder.