VHDL Example of a shift register
- aurelianlazarut6
- Apr 14
- 1 min read
Below is a full project and Youtube video on how to design a shift register and display the state of the bits on the 8 LEDs on the board. As you can see in the video (quite long...) the first attempt was partially successful because the shift register was using the 100MHz clock available on the board and the led movement was to fast for the human eye.
In order to make things more visible for us mortals I had to divide the clock by using a counter and create an much slower enable signal for the shifter.
defining the counter and the enable first
signal counter : unsigned (23 downto 0);
signal enable : STD_LOGIC;
and create the process to generate the enable
process (clk)
begin
if rising_edge(clk) then
counter <= counter + 1;
end if;
end process;
enable <= '1' when counter = x"000000" else '0';
This enable will be active for one clock period (10ns for the 100MHz clock) every 2^23 cycles.
next we make the actual shift register and assign to the leds outputs. Note the reset which is outside of the "rising_edge" event which make it asynchronous with the clock. (not a great idea but will learn this later. The reset doesn't care about the clock that's the idea.
process (clk)
begin
if reset = '0' then
shift_register <= "00000001";
else
if rising_edge(clk) then
if enable = '1' then
shift_register(7 downto 0) <= shift_register(6 downto 0) & shift_register(7);
end if;
end if;
end if;
end process;
led <= shift_register(7 downto 0);
You can download the full project for Vivado from below
and of course the video
Enjoy!
Comments