[Menu]>[CPLD]>[5bits Shifter]


Source code and Explanation
for 5bits LED Shifter


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
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
--******************************************************************************
--*                                                                            *
--*                             5bits LED Shifter                              *
--*                                                     Device : XC9536-PC44   *
--*                                                     Author : Seiichi Inoue *
--******************************************************************************

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

entity LED_Shifter is
  port ( CLK : in std_logic;                     -- Defines ports
         RIGHT : in std_logic;
         QA : out std_logic_vector(4 downto 0);
         QB : out std_logic_vector(4 downto 0);
         QC : out std_logic_vector(4 downto 0);
         QD : out std_logic_vector(4 downto 0);
         QE : out std_logic_vector(4 downto 0));
  attribute pin_assign : string;                 -- Pin Assign
  attribute pin_assign of CLK : signal is "29";
  attribute pin_assign of RIGHT : signal is "28";
  attribute pin_assign of QA : signal is "36,35,38,37,39";
  attribute pin_assign of QB : signal is "40,43,42,1,44";
  attribute pin_assign of QC : signal is "2,5,4,8,6";
  attribute pin_assign of QD : signal is "13,12,11,9,7";
  attribute pin_assign of QE : signal is "24,22,20,18,19";
end LED_Shifter;

architecture LED_Shifter_ARCH of LED_Shifter is
signal COUNTER : std_logic_vector(2 downto 0);   -- Defines internal signals
signal Q_IN : std_logic_vector(4 downto 0);
begin
  QA <= Q_IN;                                    -- Set output
  QB <= Q_IN;
  QC <= Q_IN;
  QD <= Q_IN;
  QE <= Q_IN;
  process( CLK, RIGHT ) begin
    if CLK='1' and CLK'event then                -- Clock rising edge ?
      COUNTER <= COUNTER + '1';
      if RIGHT='1' then                          -- Blink CW
        if COUNTER=0 then
          Q_IN <= "11110";
        elsif COUNTER=1 then
          Q_IN <= "11101";
        elsif COUNTER=2 then
          Q_IN <= "11011";
        elsif COUNTER=3 then
          Q_IN <= "10111";
        elsif COUNTER=4 then
          Q_IN <= "01111";
          COUNTER <= "000";
        end if;
      else                                       -- Blink CCW
        if COUNTER=0 then
          Q_IN <= "01111";
        elsif COUNTER=1 then
          Q_IN <= "10111";
        elsif COUNTER=2 then
          Q_IN <= "11011";
        elsif COUNTER=3 then
          Q_IN <= "11101";
        elsif COUNTER=4 then
          Q_IN <= "11110";
          COUNTER <= "000";
        end if;
      end if;
    end if;
  end process;
end LED_Shifter_ARCH;

--******************************************************************************
--*                          end of 5bits LED Shifter                          *
--******************************************************************************

Explanation
Line #Comment
009The std_logic library is specified.
010A library for the arithmetic operation is specified.
013
-019
The ports of the input/output are specified.
020
-027
The pins of the input/output are specified.
031The counter to use in the inner logic is defined.
032 The register 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.
It is specified by the 5-bit vector like the output.
034
-038
It ties registers for the inner calculation to the output registers.
040"CLK='1' and CLK'event" is the description which detects that CLK changed into '1' from '0'.
041A counter is count-up.
042It judges the LED direction of the blink movement. In case of RIGHT='1', it makes shift clockwise.
043
-052
The bit pattern to output by the value of the counter is defined.
It is a pattern clockwise.
053When the counter becomes maximum(4), a counter is cleared.
055It is in the case counterclockwise.
056
-065
The bit pattern to output by the value of the counter is defined.
It is a pattern counterclockwise.
066When the counter becomes maximum(4), a counter is cleared.