Advertisement
maroashraf428

even bits detector

Oct 25th, 2019
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.65 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity even_bits_detector is
  5.     port( X: in STD_Logic;
  6.         clk: in STD_Logic;
  7.         Z: out STD_Logic);
  8. end even_bits_detector;
  9. architecture behavior of even_bits_detector is
  10. TYPE State_Type is (A,B,C,D,E,F,G,H,I);
  11. SIGNAL state: State_Type;
  12. begin
  13.     process(clk)
  14.     begin    
  15.         if rising_edge(clk) then
  16.             case state is
  17.                 when A =>
  18.                     if X = '0' then
  19.                         Z <= '0';
  20.                         state <= B;
  21.                     else
  22.                         Z <= '0';
  23.                         state <= C;
  24.                     end if;
  25.                 when B =>
  26.                     if X = '0' then
  27.                         Z <= '1';
  28.                         state <= D;
  29.                     else
  30.                         Z <= '0';
  31.                         state <= E;
  32.                     end if;
  33.                 when C =>
  34.                     if X = '0' then
  35.                         Z <= '0';
  36.                         state <= E;
  37.                     else
  38.                         Z <= '1';
  39.                         state <= F;
  40.                     end if;
  41.                 when D =>
  42.                     if X = '0' then
  43.                         Z <= '0';
  44.                         state <= B;
  45.                     else
  46.                         Z <= '1';
  47.                         state <= C;
  48.                     end if;
  49.                 when E =>
  50.                     if X = '0' then
  51.                         Z <= '1';
  52.                         state <= G;
  53.                     else
  54.                         Z <= '1';
  55.                         state <= H;
  56.                     end if;
  57.                 when F =>
  58.                     if X = '0' then
  59.                         Z <= '1';
  60.                         state <= B;
  61.                     else
  62.                         Z <= '0';
  63.                         state <= C;
  64.                     end if;
  65.                 when G =>
  66.                     if X = '0' then
  67.                         Z <= '0';
  68.                         state <= E;
  69.                     else
  70.                         Z <= '1';
  71.                         state <= I;
  72.                     end if;
  73.                 when H =>
  74.                     if X = '0' then
  75.                         Z <= '1';
  76.                         state <= I;
  77.                     else
  78.                         Z <= '0';
  79.                         state <= E;
  80.                     end if;
  81.                 when I =>
  82.                     if X = '0' then
  83.                         Z <= '1';
  84.                         state <= B;
  85.                     else
  86.                         Z <= '1`';
  87.                         state <= C;
  88.                     end if;
  89.                 when others =>
  90.                     state <= A;
  91.             end case;
  92.         end if;  
  93.     end process;   
  94. end behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement