Jump to content
    

Сдвиговый регистр на VHDL

Не получается с помощью ф-й: SHR SHL самого простого сдвигового регистра сгородить.

Может надо место сигналов переменные использовать или еще какой то заковык...

Дайте плиз кусочек кода который реализует сдвиг и выдачу результата заборт.

Share this post


Link to post
Share on other sites

скачайте с сайта xilinx xst.pdf Многие вопросы отпадут сами собой

library ieee;

use ieee.std_logic_1164.all;

entity shift is

port(

C, SI, LEFT_RIGHT : in std_logic;

PO : out std_logic_vector(7 downto 0));

end shift;

architecture archi of shift is

signal tmp : std_logic_vector(7 downto 0);

begin

process ©

begin

if (C'event and C='1') then

if (LEFT_RIGHT='0') then

tmp <= tmp(6 downto 0) & SI;

else

tmp <= SI & tmp(7 downto 1);

end if;

end if;

end process;

PO <= tmp;

end archi;

Share this post


Link to post
Share on other sites

library IEEE;

use IEEE.std_logic_1164.all;

entity sr is

port (CLK: in STD_LOGIC;

Enable: in STD_LOGIC;

new_bit: in STD_LOGIC;

out_reg: out STD_LOGIC_VECTOR (3 downto 0) );

end sr;

 

architecture sr of sr is

begin

process (CLK)

variable Reg: STD_LOGIC_VECTOR (3 downto 0);

begin

if CLK = '1' and CLK'event then

if Enable = '1' then

for A in 3 downto 1 loop

Reg (A) := Reg (A-1);

end loop;

Reg(0) := new_bit;

end if;

end if;

end process;

out_reg <= Reg;

end sr;

 

///////////////

P.S.: ан разных ПЛИС разные по описанию регистра сдвига имеют разную производительность (3-5% )

а так, все об одном и том же :)

Share this post


Link to post
Share on other sites

:)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity shift_reg is

port(clk,reset : in std_logic;

shift_reg: inout std_logic_vector(3 downto 0);

in_bit: in std_logic);

end entity;

architecture behav of shift_reg is

 

begin

shift:process(clk,reset)

begin

if reset ='1' then

shift_reg<=(others=>'0'); --shift_reg="0000"

elsif rising_edge(clk) then

shift_reg<=shr(shift_reg,"01");

shift_reg(1)<=in_bit;

end if;

end process;

end architecture;

Share this post


Link to post
Share on other sites

Не получается с помощью ф-й: SHR SHL самого простого сдвигового регистра сгородить.

Может надо место сигналов переменные использовать или еще какой то заковык...

signal MyShReg : unsigned(7 downto 0);
signal Din     : std_logic;

process(Clk,MyShReg,Din)
begin
  if rising_edge(Clk) then
     MyShReg <= MyShReg sll 1;
     MyShReg(0) <= Din;    
  end if;
end process;

Конкретно этот код не проверял, но должно работать

Edited by =AK=

Share this post


Link to post
Share on other sites

Сдвиговый регистр можно реализовать несколькими способами, смотря какая конфигурация - входы/выходы последовательные или параллельные, синхронный или асинхронный сброс/установка, с возможностью загрузки значения или без, ... Вариантов масса.

 

Для примера, сдвиговый регистр с последовательным входом и выходом:

1) shreg <= shreg (6 downto 0) & SI;

2) for i in 0 to 6 loop

shreg(i+1) <= shreg(i);

end loop;

hreg(0) <= SI;

3) используя предопределенные функции SLL, SRL и др. Для этого небходимо подключить библиотеку

ieee.numeric_std или

ieee.std_logic_arith или

ieee.std_logic_unsigned или

ieee.std_logic_signed

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...