Advertisement
Guest User

Untitled

a guest
May 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.32 KB | None | 0 0
  1. library ieee ;
  2. use ieee.std_logic_1164.all ;
  3. -- simplified 5 states bitrec
  4. -- Dudy Bar On, lab 1 Dept of EE
  5. -- Copyright  technion IIT  2016
  6.  
  7. -- DO NOT CHANGE IN THIS PART OF CODE --------------------------
  8. entity bitrec is
  9.    port ( resetN        : in  std_logic ;
  10.              clk        : in  std_logic ;
  11.              kbd_clk    : in  std_logic ;
  12.              kbd_dat    : in  std_logic ;
  13.              dout_new   : out std_logic ;
  14.              dout       : out std_logic_vector(7 downto 0) ) ;
  15. end bitrec ;
  16.  
  17. architecture arc_bitrec of bitrec is
  18.    signal shift_reg : std_logic_vector(9 downto 0) ;
  19.    signal parity_ok : std_logic                    ;
  20.    type state is (idle , --initial state
  21.                 HighClk,
  22.                 LowClk,
  23.                 ChkData,
  24.                 NewData );
  25.    constant numOfBits : integer  := 11 ;
  26. begin
  27.     parity_ok <=  shift_reg(8) -- same as kbd_dat
  28.                 xor shift_reg(7) xor shift_reg(6)
  29.                 xor shift_reg(5) xor shift_reg(4)
  30.                 xor shift_reg(3) xor shift_reg(2)
  31.                 xor shift_reg(1) xor shift_reg(0) ;
  32.                
  33. process ( resetN , clk )
  34.  
  35.   variable present_state : state;
  36.   variable count : integer range 0 to 15;
  37.  
  38. begin
  39.  
  40. -- END OF DO NOT CHANGE PART ---------------------------
  41.  
  42.     ---- ASYNC PART ----
  43.     if resetN = '0' then
  44.         dout_new <= '0';
  45.         count := 0 ;
  46.         present_state := idle;
  47.      ---- SYNCHRONOUS PART ----  
  48.     elsif rising_edge (clk) then
  49.  
  50.         ---- DEFAULT PART ----
  51.          dout_new <= '0';
  52.  
  53.         ---- State Machine ----
  54.          case present_state is
  55.        
  56.             when idle =>
  57.                 if (kbd_dat = '0' ) and (kbd_clk = '0') then
  58.                     present_state := LowClk;
  59.                 end if;
  60.                
  61.             when LowClk =>
  62.                 if (kbd_clk = '1') then
  63.                     counter := counter + 1;
  64.                     shift_reg <= kbd_dat & shift_reg(9 downto 1);
  65.  
  66.                     if (counter < numOfBits) then
  67.                         present_state := HighClk;
  68.                     else
  69.                         present_state := ChkData;
  70.                     end if;
  71.                 end if;
  72.  
  73.             when HighClk =>
  74.                 if (kbd_clk = '0') then
  75.                     present_state := LowClk;
  76.                 end if;
  77.  
  78.             when ChkData =>
  79.                 counter := 0;
  80.                 if (parity_ok = '1') then
  81.                     present_state := NewData;
  82.                 else
  83.                     present_state := idle;
  84.                 end if;
  85.  
  86.             when NewData =>
  87.                 dout_new <= '1';
  88.                 dout <= shift_reg(7 downto 0);
  89.                 present_state := idle;
  90.  
  91.        
  92.         end case;
  93.     end if;
  94. end process;
  95. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement