Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

shift register coding problem

Hi,

I wonder if someboy could take a look on my code on 5x9 shift register. It seems to me that input d is connected to the design. I am using multidimensional array.

I am new to VHDL :confused:

library ieee ;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity ShiftReg is

port( d: IN STD_LOGIC_VECTOR(4 downto 0);

Q: OUT STD_LOGIC_VECTOR(4 downto 0);

Clk: IN STD_LOGIC

);

end ShiftReg;

architecture archi of ShiftReg is

type register5x9 is array (0 to 4) of STD_LOGIC_VECTOR (8 downto 0);

signal tmp: register5x9;

begin

process (Clk)

begin

if Clk'event and Clk='1' then

tmp(0)(8) <= d(0);

tmp(1)(8) <= d(1);

tmp(2)(8) <= d(2);

tmp(3)(8) <= d(3);

tmp(4)(8) <= d(4);

for i in 8 downto 1 loop

for j in 4 downto 1 loop

tmp(j-1)(i-1) <= tmp(j)(i);

end loop;

end loop;

end if;

Q(0) <= tmp(0)(0);

Q(1) <= tmp(1)(0);

Q(2) <= tmp(2)(0);

Q(3) <= tmp(3)(0);

Q(4) <= tmp(4)(0);

end process;

end archi;

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    To infer a shift register, your signal is ok, just do this in the clocked process:

    tmp(0) <= d;

    for i in 1 to 4 loop

    tmp(i) <= tmp(i-1);

    end loop;

    -- outside process:

    Q <= tmp(4);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    you also need to correct the data width to 5 bits. reverse the array orientation

    type register5x9 is array (0 to 8) of STD_LOGIC_VECTOR (4 downto 0);

    signal tmp: register5x9;

    for i in 1 to 8 ..etc
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Because of the strange two-dimensional shift operation, input d is ignored and all-zero shifted to the output.

    Actually I don't see a clear intention with the code.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It was just an experiment for me. I am trying to learn more about Digital design.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Karl Hi

    In Quartus, when Your VHDL file opened in text editor, select:

    Edit -> Insert Template -> VHDL -> Full Designs ...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    For single bit shift, one can also use this compact statement:

    --assuming input is d (one bit) output is Q(one bit), tmp is 16 bit:

    --in a clocked process

    tmp<= tmp(14 downto 0) & d;

    Q <= tmp(15);