Home Contacts Terms Send money Cookie policy


Personal blogs


Acme's Friends

We would like to inform our clients that our shipping office will be closed from Aug 8 to Aug 23
PLEASE NOTE: This article is obsolete or related to a discontinued product.

FVBE - EqualComparator16bit1

by Roberto Asquini

Make a simple equality comparator with 16 bit

Block diagram of the EqualComparator16bit1 VHDL code

This example presents another very simple peripheral written in VHDL. We will show the VHDL code and the results of its simulation with the Libero suite. For a working example using this comparator as a building block please refer to the Fox VHDL by Example: EventCounter1 The source code for the 16 bit equal comparator we are presenting here is: EqualComparator16bit1.vhd.

The first lines are the declaration of the needed libraries:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library proasic3;
Then there is the entity declaration for this file that represents the interface port for this VHDL unit. Every other external block of VHDL code, to be able to use this counter, needs to declare the very same port interface as a component and needs to instantiate it.

This is the entity declaration:

entity EqualComparator16bit1 is
         A_VECTOR : in std_logic_vector(15 downto 0); -- 16 bit vector A for the comparison.
         B_VECTOR : in std_logic_vector(15 downto 0); -- 16 bit vector B for the comparison.
         EQUAL : out std_logic -- positive equality output signal.
end EqualComparator16bit1;

In this entity we see the declaration of two 16 bit ports in input: A_VECTOR and B_VECTOR that receive the external 16 bit values to compare. The third port signal is an output: EQUAL that will become high whenever the two vectors A and B are equal.

Now, continuing in the file, there is the architecture declaration. It is called Dataflow since the only statement realizing the complete equality comparator is a direct statement. Direct statements (not inside a process) are used in the concurrent way to describe a logic circuit since they are all executed in parallel. The concurrent way (it means the parallel execution way) is called also Dataflow:

architecture Dataflow of EqualComparator16bit1 is

  EQUAL <= '1' when A_VECTOR = B_VECTOR else '0';

end Dataflow;	

No processes are needed here since the equal comparator is a pure combinatorial function.

The single line between begin and end is self explaining. The EQUAL port signal is put at '1' logic state when the two input vectors are equal. Otherwise the EQUAL port signal is maintained at '0' level.

From this little example you can see the concise and clear way to express statements that will involve lots of logic gates. The power of expression of VHDL can be seen if we would like to change the design up to a 128 bit comparator for example. We will have changed only the bounds inside the entity declaration but no change will be needed inside the architecture declaration since the logic operation is the same.

Simulation of EqualComparator16bit1.vhd

In the following you can see the simulation output diagram of the EqualComparator16bit1.vhd VHDL code. This simulation has been realized using the standard tools inside the Actel suite of programs Libero 7.1:

Simulation diagram of EqualComparator16bit1 VHDL code

Remember that VHDL is not case sensitive! So, even if we declared the port signals in upper case, the simulator shows anyway all names in lower case.

It is possible to see that immediately after the two 16 bit vectors become equal the output equal is set to high logic level.

This example is very simple but is completely working. If we should map the A_VECTOR, the B_Vector and the EQUAL output on physical external pins of the FOX_VHDL FPGA, we could have the comparator hardware function up and running. More interesting it will surely be instead to use this function inside some other more interesting peripheral as a building block like in this example: Fox VHDL by Example: EventCounter1.

Acme Systems srl
Via Aldo Moro 53 - 00055 Ladispoli (RM) - Italy
P.IVA/C.F. 08114831004
Tel + - Fax +39.06.622.765.31
PEC: acmesystemssrl@pec.it
Iscritta al Registro delle Imprese di Roma al n. 08114831004

Atmel© Certified Partner

Acme Systems provides this documentation "as is" without warranty or guarantees of any kind. We not provide any direct support for the Open Source preinstalled software but, through these pages and forum posts, all of the information required to obtain the sources, install, use and update the Open Source software that can be run on the Acme boards. Please note that all of the preinstalled software, used on the Acme Systems products, are Open Source so you have to check the license terms provided by the authors (usually the GPL) before using it in any commercial or non-commercial product, by yourself. Before to contact us please note that WE ARE MAINLY HARDWARE DESIGNERS and NOT LINUX GURUS and therefore could be better to post your questions to the Acme Systems forum and ensure that all of the site contributors and large software community can read and reply to your questions.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.