[Menu]>[CPLD]>[10bits Shift Register]


Source code and Explanation
for 10bits Shift Register



001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
--******************************************************************************
--*                                                                            *
--*                           10 bits Shift Register                           *
--*                                                     Device : XC9536-PC44   *
--*                                                     Author : Seiichi Inoue *
--******************************************************************************

library ieee;                                    -- Defines std_logic types
use ieee.std_logic_1164.all;

entity Shift_reg is
  port ( DIN, CLK : in std_logic;                -- Defines ports
         Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9 : out std_logic);
end Shift_reg;

architecture Shift_reg_arch of Shift_reg is
  signal QIN0,QIN1,QIN2,QIN3,QIN4 : std_logic;   -- Internal signal
  signal QIN5,QIN6,QIN7,QIN8,QIN9 : std_logic;
begin
  Q0 <= QIN0;                                    -- Output data
  Q1 <= QIN1;
  Q2 <= QIN2;
  Q3 <= QIN3;
  Q4 <= QIN4;
  Q5 <= QIN5;
  Q6 <= QIN6;
  Q7 <= QIN7;
  Q8 <= QIN8;
  Q9 <= QIN9;
  process( CLK ) begin
    if CLK='1' and CLK'event then                -- Clock rising edge ?
      QIN0 <= DIN;                               -- Data shifting
      QIN1 <= QIN0;
      QIN2 <= QIN1;
      QIN3 <= QIN2;
      QIN4 <= QIN3;
      QIN5 <= QIN4;
      QIN6 <= QIN5;
      QIN7 <= QIN6;
      QIN8 <= QIN7;
      QIN9 <= QIN8;
    end if;
  end process;
end Shift_reg_arch;

--******************************************************************************
--*                        end of 10 bits Shift Register                       *
--******************************************************************************

Explanation
Line #Comment
009The std_logic library is specified.
012
013
The pins of the input/output are specified.
017
018
The registers to use by the logical operation inside is defined.
This is limitation on VHDL. The object which was specified as output (OUT) can not be used inside the entity.
020
-029
It ties registers for the inner calculation to the output registers.
031 The judgement when clock (CLK) changes from 0 to 1 is done.
"CLK='1' and CLK'event" is the description which detects that CLK changed into '1' from '0'.
032
-041
It shifts the contents of the register by 1 bit.