[Menu]>[CPLD]>[8-3 Encoder]


Source code and Explanation
for 8-3 Encoder

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
--******************************************************************************
--*                                                                            *
--*                              8 - 3 Encoder                                 *
--*                                                     Device : XC9536-PC44   *
--*                                                     Author : Seiichi Inoue *
--******************************************************************************

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

entity Encoder1 is
  port ( A, B, C, D, E, F, G, H : in std_logic;  -- Defines ports
         Q : out std_logic_vector(2 downto 0);
         ERROR : out std_logic);
end Encoder1;

architecture Encoder1_arch of Encoder1 is
  signal IN_DATA : std_logic_vector(7 downto 0); -- Defines internal signals
begin
  IN_DATA <= H & G & F & E & D & C & B & A;      -- Binding vector
  process( IN_DATA ) begin
    ERROR <= '0';                                -- Clear error bit
    case IN_DATA is                              -- Encode with input data
      when "00000001" => Q <= "000";
      when "00000010" => Q <= "001";
      when "00000100" => Q <= "010";
      when "00001000" => Q <= "011";
      when "00010000" => Q <= "100";
      when "00100000" => Q <= "101";
      when "01000000" => Q <= "110";
      when "10000000" => Q <= "111";
      when others => ERROR <= '1';               -- Illegal condition
    end case;
  end process;
end Encoder1_arch;

--******************************************************************************
--*                             end of 3 - 8 Encoder                           *
--******************************************************************************

Explanation
Line #Comment
009The std_logic library is specified.
012
-014
The pins of the input/output are specified.
018 The signal which is used by the Case sentence is defined.
It is specified by the 8-bit vector.
020The inputs are connected with the inner signal. Because the input is 1 bit respectively, they are binded using &.
022It clears an error bit. (Initialization)
023
-031
It is generated in the output code with correspondence with the input code by the Case sentence.
032When the input is not the pattern which was specified by the Case sentence, ERROR is made 'H level '.