Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.72 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. entity SigGenControl is
  7.   port( reset, sCLK, mCLK, FreqBTN, AmplBTN, ShapeBTN: in std_logic;
  8.         MOSI, SS: in std_logic;
  9.           MISO, SigEn : out std_logic;
  10.         Shape  : inout std_logic_vector(2 downto 0);
  11.         Ampl   : inout std_logic_vector(7 downto 0);
  12.           DataOut: inout std_logic_vector(19 downto 0);
  13.         Freq   : inout std_logic_vector(7 downto 0));
  14. end SigGenControl;
  15.  
  16. architecture Behavioral of SigGenControl is
  17.  
  18. signal DataStreamInternal, DatastreamInternalSync: std_logic_vector(39 downto 0);
  19. signal StartByte, AckByte, AckByteLoaded, CalcChecksum, FreqInternal, AmplInternal: std_logic_vector(7 downto 0);
  20. signal SetEnable: std_logic;
  21. signal ShapeInternal: std_logic_vector(2 downto 0);
  22. signal DataOutInternal: std_logic_vector(19 downto 0);
  23.  
  24. type StateType is (FreqS, AmplS, ShapeS, ResS);
  25. signal State, NextState: StateType;
  26.  
  27. begin
  28.  
  29. StartByte <= "01010101";    -- X"55"
  30. AckByte <= "10011001";      -- X"99"
  31.  
  32. CalcChecksum <= DatastreamInternalsync(39 downto 32) xor DatastreamInternalsync(31 downto 24) xor DatastreamInternalsync(23 downto 16) xor DatastreamInternalsync(15 downto 8) xor DatastreamInternalsync(7 downto 0);
  33.  
  34. SigEN <= '1';
  35.  
  36. ----------------------------------------------------------------MOSIReg-------------------------------------------------------------   
  37. MOSIReg: process(reset, sCLK, SS)
  38.     begin
  39.         if reset = '1' then
  40.             DataStreamInternal <= X"0000000000";
  41.                    
  42.         elsif SS = '0' then
  43.             if sClk'event and sClk = '1' then
  44.                 DatastreamInternal <= DatastreamInternal(38 downto 0) & MOSI;
  45.             else
  46.                 DatastreamInternal <= DatastreamInternal;
  47.             end if;
  48.         end if;
  49.    
  50.        
  51. end process;
  52.    
  53. ----------------------------------------------------------------MISOReg-------------------------------------------------------------   
  54. MISOReg: process(reset, sCLK, SetEnable, AckByteLoaded)
  55.     begin
  56.         if reset = '1' then
  57.                 AckByteLoaded <= X"00";
  58.                    
  59.         elsif sCLK'event and sCLK = '0' then
  60.             if SetEnable = '1' then
  61.                 AckByteLoaded <= AckByte;
  62.             else
  63.                 AckByteLoaded <= AckByteLoaded(6 downto 0) & '0';
  64.             end if;
  65.         end if;
  66.        
  67.         MISO <= AckByteLoaded(7);
  68.        
  69. end process;
  70. ----------------------------------------------------------------SyncReg-------------------------------------------------------------
  71. SyncReg: process(Reset, mClk)
  72. begin
  73.   if Reset='1' then DatastreamInternalsync <= X"0000000000";
  74.  
  75.   elsif mClk'event and mClk = '1' then  
  76.         DatastreamInternalsync <= DatastreamInternal;
  77.   end if;
  78. end process;
  79.  
  80.  
  81. ----------------------------------------------------------------StateReg-------------------------------------------------------------
  82.  
  83. StateReg: process (reset, mClk)
  84. begin
  85.   if reset = '1' then State <= ResS;
  86.  
  87.   elsif mClk'event and mClk = '1' then
  88.         State <= NextState;
  89.     end if;
  90. end process;
  91.  
  92. ----------------------------------------------------------------DispReg--------------------------------------------------------------
  93. StateDec: process (State, Reset, Reset, FreqBTN, AmplBTN, ShapeBTN, Freq, Ampl, Shape)
  94. begin
  95.     case State is
  96.         when FreqS =>
  97.                     DataOutInternal(19 downto 16) <= X"0";
  98.                
  99.                     DataOutInternal(3 downto 0) <= X"F";
  100.                     DataOutInternal(7 downto 4) <= X"0";
  101.                     DataOutInternal(11 downto 8) <= Freq(7 downto 4);
  102.                     DataOutInternal(15 downto 12) <= Freq(3 downto 0);
  103.                
  104.                if Reset = '1' then
  105.                NextState <= ResS;
  106.                elsif FreqBTN = '1' then
  107.                NextState <= FreqS;                 
  108.                elsif AmplBTN = '1' then
  109.                NextState <= AmplS;
  110.                elsif ShapeBTN = '1' then
  111.                NextState <= ShapeS;
  112.                 else
  113.                     NextState <= State;
  114.             end if;
  115. -------------------------------------------------------------------
  116.         when AmplS =>
  117.                     DataOutInternal(19 downto 16) <= X"0";
  118.            
  119.                     DataOutInternal(3 downto 0) <= X"A";
  120.                     DataOutInternal(7 downto 4) <= X"0";
  121.                     DataOutInternal(11 downto 8) <= Ampl(7 downto 4);
  122.                     DataOutInternal(15 downto 12) <= Ampl(3 downto 0);
  123.  
  124.                if Reset = '1' then
  125.                NextState <= ResS;
  126.                elsif AmplBTN = '1' then
  127.                NextState <= AmplS;                 
  128.                elsif FreqBTN = '1' then
  129.                NextState <= FreqS;
  130.                elsif ShapeBTN = '1' then
  131.                NextState <= ShapeS;
  132.                 else
  133.                     NextState <= State;
  134.             end if;
  135. -------------------------------------------------------------------
  136.         when ShapeS =>
  137.                     DataOutInternal(19 downto 16) <= X"0";
  138.                
  139.                     DataOutInternal(3 downto 0) <= X"5";
  140.                     DataOutInternal(7 downto 4) <= X"0";
  141.                     DataOutInternal(11 downto 8) <= X"0";
  142.                     DataOutInternal(15 downto 12) <= "0" & Shape;
  143.                    
  144.                if Reset = '1' then
  145.                NextState <= ResS;
  146.                elsif FreqBTN = '1' then
  147.                NextState <= FreqS;
  148.                elsif AmplBTN = '1' then
  149.                NextState <= AmplS;
  150.                elsif ShapeBTN = '1' then
  151.                NextState <= ShapeS;
  152.                 else
  153.                     NextState <= State;
  154.             end if;
  155. -------------------------------------------------------------------
  156.         when ResS =>
  157.                 DataOutInternal <= X"f05e1"; --skriv "res" med alternativ databank
  158.  
  159.                if FreqBTN = '1' then
  160.                NextState <= FreqS;
  161.                elsif AmplBTN = '1' then
  162.                NextState <= AmplS;
  163.                elsif ShapeBTN = '1' then
  164.                NextState <= ShapeS;
  165.                elsif Reset = '1' then
  166.                NextState <= ResS;
  167.                 else
  168.                     NextState <= State;                
  169.             end if;
  170. -------------------------------------------------------------------    
  171.         when others =>
  172.             NextState <= State;
  173. -------------------------------------------------------------------
  174.     end case;
  175.      
  176.      DataOut <= DataOutInternal;
  177.    
  178. end process;
  179.  
  180. ----------------------------------------------------------------Checksum-------------------------------------------------------------  
  181. ChecksumDec: process (DatastreamInternalSync, CalcCheckSum, StartByte, mClk, Reset)
  182. begin
  183.  
  184.         if (DatastreamInternalSync(39 downto 32) = StartByte) and (CalcCheckSum = X"00") then
  185.             SetEnable <= '1';
  186.         else
  187.             SetEnable <= '0';
  188.         end if;
  189.    
  190.     end process;
  191.  
  192. ----------------------------------------------------------------Frekvens-------------------------------------------------------------
  193. FreqReg: process (reset, mCLK, FreqInternal, ShapeBTN, DatastreamInternalSync)
  194. begin
  195.     if reset = '1' then
  196.             FreqInternal <= X"00";
  197.             Freq <= X"00";
  198.            
  199.     elsif mCLK'event and mCLK = '1' then
  200.         if SetEnable = '1' then
  201.             FreqInternal <= DatastreamInternalSync(31 downto 24);
  202.         else
  203.             FreqInternal <= FreqInternal;
  204.         end if;
  205.     end if;
  206.    
  207.     Freq <= FreqInternal;
  208. end process;
  209.  
  210. ----------------------------------------------------------------Amplitude-------------------------------------------------------------
  211. AmplitudeReg: process (reset, mCLK, AmplInternal, DatastreamInternalSync)
  212. begin
  213.     if reset = '1' then
  214.             AmplInternal <= X"00";
  215.             Ampl <= X"00";
  216.  
  217.     elsif mCLK'event and mCLK = '1' then
  218.         if SetEnable = '1' then
  219.             AmplInternal <= DatastreamInternalSync(23 downto 16);
  220.         else
  221.             AmplInternal <= AmplInternal;
  222.         end if;
  223.     end if;
  224.    
  225.     Ampl <= AmplInternal;
  226. end process;
  227.  
  228. ----------------------------------------------------------------Shape-------------------------------------------------------------
  229. ShapeReg: process (reset, mCLK, ShapeInternal, DatastreamInternalSync)
  230. begin
  231.     if reset = '1' then
  232.             ShapeInternal <= "000";
  233.            
  234.     elsif mCLK'event and mCLK = '1' then
  235.         if SetEnable = '1' then
  236.             ShapeInternal <= DatastreamInternalSync(10 downto 8);
  237.         else
  238.             ShapeInternal <= ShapeInternal;
  239.         end if;
  240.     end if;
  241.    
  242.     Shape <= ShapeInternal;
  243. end process;
  244. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement