Guest User

Untitled

a guest
Feb 5th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.69 KB | None | 0 0
  1.     transition : process (currentState, writeEnable, bitCounter)
  2.     begin
  3.         case currentState is
  4.         when IDLE =>
  5.             if writeEnable = '1' then
  6.                 nextState <= START_BIT;
  7.             else
  8.                 nextState <= IDLE;
  9.             end if;
  10.         when START_BIT =>
  11.             nextState <= DATA_BIT;
  12.         when DATA_BIT =>
  13.             if bitCounter = 0 then
  14.                 nextState <= STOP_BIT;
  15.             else
  16.                 nextState <= DATA_BIT;
  17.             end if;
  18.         when STOP_BIT =>
  19.             nextState <= IDLE;
  20.         when others =>
  21.             nextState <= IDLE;
  22.         end case;
  23.     end process;
  24.  
  25.     stateMemory : process (baudClock)
  26.     begin
  27.         if rising_edge(baudClock) then
  28.             if reset='1' then
  29.                 currentState <= IDLE;
  30.             else
  31.                 currentState <= nextState;
  32.             end if;
  33.         end if;
  34.     end process;
  35.  
  36.     outputs : process (currentState, bitCounter)
  37.     begin
  38.         case currentState is
  39.         when IDLE =>
  40.             txReady <= '1';
  41.             txData <= '1';
  42.         when START_BIT =>
  43.             txReady <= '0';
  44.             txData <= '0';
  45.         when DATA_BIT =>
  46.             txReady <= '0';
  47.             txData <= txReg(0);
  48.         when STOP_BIT =>
  49.             txReady <= '0';
  50.             txData <= '1';
  51.         end case;
  52.     end process;
  53.  
  54.     -- shift register
  55.     shiftRegister : process (baudClock, reset)
  56.     begin
  57.         if reset = '1' then
  58.             txReg <= (others => '0');
  59.         elsif rising_edge(baudClock) then
  60.             if currentState = DATA_BIT then
  61.                 txReg <= '0' & txReg(7 downto 1);
  62.             else
  63.                 txReg <= writeData;
  64.             end if;
  65.         end if;
  66.     end process;
  67.    
  68.     -- bit counter
  69.     baudCount : process (baudClock, reset)
  70.     begin
  71.         if reset = '1' then
  72.             bitCounter <= 7;
  73.         elsif rising_edge(baudClock) then
  74.             if currentState = DATA_BIT then
  75.                 if bitCounter > 0 then
  76.                     bitCounter <= bitCounter - 1;
  77.                 else
  78.                     bitCounter <= 0;
  79.                 end if;
  80.             else
  81.                 bitCounter <= 7;
  82.             end if;
  83.         end if;
  84.     end process;
Advertisement
Add Comment
Please, Sign In to add comment