Advertisement
Guest User

blaŽ

a guest
Nov 14th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.32 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. entity LEDMatrixCNTRL is
  5.  
  6. PORT(
  7.     rst, wake, send_data, send_reg, clk_in: IN STD_LOGIC;
  8.     data: IN STD_LOGIC_VECTOR(0 to 63);
  9.     CNTRL_reg: IN STD_LOGIC_VECTOR(0 to 15);
  10.     load, d_out: OUT STD_LOGIC;
  11.     clk_out: BUFFER STD_LOGIC
  12. );
  13.  
  14. end LEDMatrixCNTRL;
  15.  
  16. architecture Behavioral of LEDMatrixCNTRL is
  17.  
  18.     SIGNAL decoded_data: STD_LOGIC_VECTOR(0 to 15);
  19.     SIGNAL decode: integer range 0 to 7;
  20.  
  21.     CONSTANT wake_signal: STD_LOGIC_VECTOR(0 to 15) := "1000000000000000";
  22.     CONSTANT shutDOWN_signal: STD_LOGIC_VECTOR(0 to 15) := "0000000000000000";
  23.  
  24.     TYPE state IS(ShutDown, WakeState, SSD, NormalOP, SendData, SendReg);
  25.     SIGNAL current_state, next_state: state;
  26.  
  27.     SIGNAL sent, sentMatrix: STD_LOGIC;
  28.    
  29.  
  30. begin
  31.  
  32.     freq: entity work.generic_divider port map(clk_in);
  33.  
  34.     FSMSequential: process(clk_out, rst)
  35.     begin
  36.         if(rst = '1') then
  37.             current_state <= SSD;
  38.         elsif(rising_edge(clk_out)) then
  39.             current_state <= next_state;
  40.         end if;
  41.     end process;
  42.  
  43.     process(current_state, wake, send_data, send_reg, sent, sentMatrix)
  44.     begin
  45.  
  46.         case current_state IS
  47.        
  48.             when ShutDown =>
  49.                 if(wake = '1') then
  50.                     next_state <= WakeState;
  51.                 else
  52.                     next_state <= ShutDown;
  53.                 end if;
  54.             when WakeState =>
  55.                 if(sent = '1') then
  56.                     next_state <= NormalOP;
  57.                 else
  58.                     next_state <= WakeState;
  59.                 end if;
  60.             when SSD =>
  61.                 if(sent = '1') then
  62.                     next_state <= ShutDown;
  63.                 else
  64.                     next_state <= SSD;
  65.                 end if;            
  66.             when NormalOP =>
  67.                 if(send_reg = '1') then
  68.                     next_state <= SendReg;
  69.                 elsif(send_data = '1') then
  70.                     next_state <= SendData;
  71.                 else
  72.                     next_state <= NormalOP;
  73.                 end if;
  74.             when SendReg =>
  75.                 if(sent = '1') then
  76.                     next_state <= NormalOP;
  77.                 else
  78.                     next_state <= SendReg;
  79.                 end if;
  80.             when SendData =>
  81.                 if(sentMatrix = '1') then
  82.                     next_state <= NormalOP;
  83.                 else
  84.                     next_state <= SendData;
  85.                 end if;
  86.             end case;
  87.     end process;
  88.  
  89.     setLoad: process(clk_out, rst)
  90.     begin
  91.         if (rst = '1') then
  92.             load <= '0';
  93.         elsif(rising_edge(clk_out)) then
  94.             if (sent = '1') then
  95.                 load <= '1';
  96.             else
  97.                 load <= '0';
  98.             end if;
  99.         end if;
  100.     end process;
  101.  
  102.     SendProcess: process(rst, clk_out)
  103.     variable counter_reg: integer range 0 to 15;
  104.     variable counter_data: integer range 0 to 7;
  105.    
  106.     begin
  107.         if( rst = '1') then
  108.            
  109.             sent <= '0';
  110.             sentMatrix <= '0';
  111.             d_out <= '0';
  112.             counter_reg := 0;
  113.             counter_data := 0;
  114.                        
  115.         elsif(clk_out'event AND clk_out = '0') then
  116.        
  117.             case current_state IS
  118.                 when ShutDown =>
  119.                     sent <= '0';
  120.                     counter_reg := 0;
  121.                     counter_data := 0;
  122.                                        
  123.                 when WakeState =>
  124.                     d_out <= wake_signal(counter_reg);
  125.                     counter_reg := counter_reg + 1;
  126.                    
  127.                     if(counter_reg >= 16) then
  128.                         sent <= '1';
  129.                         counter_reg := 0;                      
  130.                     end if;
  131.                    
  132.                 when SSD =>
  133.                     d_out <= shutDown_signal(counter_reg);
  134.                     counter_reg := counter_reg + 1;
  135.                    
  136.                     if(counter_reg >= 16) then
  137.                         sent <= '1';
  138.                         counter_reg := 0;  
  139.                     end if;                
  140.                 when NormalOP =>
  141.                     sent <= '0';
  142.                     sentMatrix <= '0';
  143.                     d_out <= '0';
  144.                     counter_reg := 0;
  145.                     counter_data := 0;
  146.                                    
  147.                 when SendReg =>
  148.                     d_out <= CNTRL_reg(counter_reg);
  149.                     counter_reg := counter_reg + 1;
  150.                    
  151.                     if(counter_reg >= 16) then
  152.                         sent <= '1';
  153.                         counter_reg := 0;
  154.                     end if;
  155.                    
  156.                 when SendData =>
  157.                     d_out <= decoded_data(counter_reg);
  158.                     counter_reg := counter_reg + 1;
  159.                    
  160.                     if(counter_reg >= 16) then
  161.                         sent <= '1';
  162.                         counter_reg := 0;
  163.                         counter_data := counter_data + 1;
  164.                    
  165.                        
  166.                     else
  167.                         sent <= '0';
  168.                     end if;
  169.                     if(counter_data >= 8) then
  170.                         sentMatrix <= '1';
  171.                         counter_data := 0;
  172.                     end if;        
  173.                    
  174.             end case;      
  175.         end if;
  176.    
  177.         decode <= counter_data;
  178.  
  179.     end process;
  180.    
  181.     decoded_data <= "XXXX" & "0001" & data(0 to 7) when decode = 0 else
  182.                         "XXXX" & "0010" & data(8 to 15) when decode = 1 else
  183.                         "XXXX" & "0011" & data(16 to 23) when decode = 2 else
  184.                         "XXXX" & "0100" & data(24 to 31) when decode = 3 else
  185.                         "XXXX" & "0101" & data(32 to 39) when decode = 4 else
  186.                         "XXXX" & "0110" & data(40 to 47) when decode = 5 else
  187.                         "XXXX" & "0111" & data(48 to 55) when decode = 6 else
  188.                         "XXXX" & "1000" & data(56 to 63);
  189. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement