This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > FPGA Technical Tutorials > Design Recipes for FPGAs Using Verilog and VHDL > Latches, Flip-Flops, and Registers > Registers

TABLE OF CONTENTS

Xilinx FPGA FPGA Forum

Registers

FONT SIZE : AAA

Registers use a bank of flip-flops to load and store data in a bus. The difference between a basic flip-flop and a register is that, while there is a data input, clock and usually a reset (or clear), there is also a load signal that defines whether the data on the input is to be loaded onto the register or not. The VHDL code for an example 8-bit register would be as follows:

library ieee;

use ieee.std_logic_1164.all;

entity register is

generic (

n : natural := 8

);

port (

d : in std_logic_vector(n−1 downto 1);

clk : in std_logic;

nrst : in std_logic;

load : in std_logic;

q : out std_logic_vector(n−1 downto 1)

);

end entity register;

architecture beh of register is

begin

process (clk, nrst) is

begin

if (nrst = ’0’) then

q <= (others => ’0’);

elsif (rising_edge(Clock) and (load = 1)) then

q <= d;

end if;

end process;

end architecture beh;

This can also use a more indented form of if-then-else structure to separate the check on the clk and the load values as shown here:

library ieee;

use ieee.std_logic_1164.all;

entity register is

generic (

n : natural := 8

);

port (

d : in std_logic_vector(n−1 downto 1);

clk : in std_logic;

nrst : in std_logic;

load : in std_logic;

q : out std_logic_vector(n−1 downto 1)

);

end entity register;

architecture beh of register is

begin

process (clk, nrst) is

begin

if (nrst = ’0’) then

q <= (others => ’0’);

elsif (rising_edge(Clock) then

if (load = ’1’)) then

q <= d;

end if;

end if;

end process;

end architecture beh;

Notice that although there are four inputs (clk, nrst, load, and d), only clk and nrst are included in the process sensitivity list. If load and d change, then the process will ignore these changes until the clk rising edge or nrst goes low. If the load is not used, then the register will load the data on every clock rising edge unless the reset is low. This can be useful in applications such as pipelining, where efficiency is paramount. The VHDL for this slightly simpler register is given here:

library ieee;

use ieee.std_logic_1164.all;

entity reg_rst is

port (

d,

clk,

nrst : in std_logic;

q : out std_logic

);

end entity reg_rst;

architecture beh of reg_rst is

begin

process (clk, nrst) is

begin

if (nrst = ’0’) then

q <= ’0’;

elsif rising_edge(clk) then

q <= d;

end if;

end process;

end architecture beh;

In a similar manner we can write a register model with an input d, load, and nrst control signals, with a clock input and the output q. In this case we use the posedge (positive edge) of the clock and the nest variable as the sensitivity list to the always block.

module register (

d,

clk,

nrst,

load,

q

);

parameter n =8;

input [n−1:0] d;

input clk;

input nrst;

input load;

output q;

reg [n−1:0] q;

always @ (posedge clk or nrst)

if(nrst == 1b’0) then begin

q <= 0;

end

else

if (load == 1b’1) then begin

q <= d;

end

end

endmodule

  • XCV300-4BG432I

    Manufacturer:Xilinx

  • FPGA Virtex Family 322.97K Gates 6912 Cells 250MHz 0.22um Technology 2.5V 432-Pin BGA
  • Product Categories: Voltage regulator tube

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC5VLX110-2FF676C

    Manufacturer:Xilinx

  • FPGA Virtex-5 LX Family 110592 Cells 65nm Technology 1V 676-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Active Active

    RoHS: No RoHS

  • XC5VLX110-2FFG1760I

    Manufacturer:Xilinx

  • FPGA Virtex-5 LX Family 110592 Cells 65nm Technology 1V 1760-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Active Active

    RoHS:

  • XC5VLX110-3FFG676C

    Manufacturer:Xilinx

  • FPGA Virtex-5 LX Family 110592 Cells 65nm Technology 1V 676-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Active Active

    RoHS:

  • XC2V2000-5BG575I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 750MHz 0.15um Technology 1.5V 575-Pin BGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS: No RoHS

Need Help?

Support

If you have any questions about the product and related issues, Please contact us.