VHDLシンタックス・ハイライティング

WordPress用のEnlighter Pluginのテストをかねて、冬休みの間に作ったVHDLコードを貼り付けます。

-- LED display demo on BeMicro MAX10
-- Shifting LED pattern every second. 


library ieee;
use ieee.std_logic_1164.all;

entity blink_top is 
    port (      reset : in std_logic;
                clock : in std_logic;   -- assign 50Mhz clock.
                led : out std_logic_vector( 7 downto 0 ) );
end blink_top;


architecture rtl of blink_top is 
    signal count : integer;                             -- 50Mhz divider
    signal pattern : std_logic_vector( 15 downto 0 );   -- LED internal pattern.
    
    type stateType is ( counting, saturated );          -- for State machine
    signal state : stateType ;
begin
    process( clock, reset )
    begin
        if reset = '0' then
                -- async reset the internal state and signals; 
            led <= ( others => '0' );
            pattern <= "0000000011111111";
            count <= 1;
            state <= saturated;
        elsif clock'event and clock = '1' then
                -- State transition
            case state is
                        -- count up till 50M 
                when counting =>
                    count <= count + 1;
                    
                    if count > 50000000 then
                        state <= saturated;
                    end if;
                    
                        -- output the display pattern to LED, then, rotate the pattern
                        -- initialize the counter 
                when saturated =>
                    led <= pattern( 15 downto 8 );                      -- output to LED
                    pattern <= pattern( 14 downto 0 ) & pattern(15);    -- rotate pattern
                    count <= 1;                                         -- reset counter
                    
                    state <= counting;
            end case;
        
        end if;
    end process;
end rtl;

 

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください