top.vhd


1
library ieee;
2
library ice40UP;
3
use ice40UP.Components.all;
4
use ieee.std_logic_1164.all;
5
use ieee.std_logic_unsigned.all;
6
7
entity top is 
8
  port (
9
    led_red: out std_logic;
10
    led_green: out std_logic;
11
    led_blue: out std_logic
12
  );
13
end top;
14
15
architecture rtl of top is
16
  signal cnt : std_logic_vector(27 downto 0) := (others => '0');
17
  signal clkHSOSC : std_logic := '0';
18
  signal led_red_int : std_logic := '0';
19
  signal led_green_int : std_logic := '0';
20
  signal led_blue_int : std_logic := '0';
21
begin
22
  top_state : process(clkHSOSC)
23
    begin
24
    if (rising_edge(clkHSOSC)) then
25
      cnt <= cnt + 1;
26
      led_red_int <= cnt(25) and cnt(24);
27
      led_green_int <= cnt(25) and not cnt(24);
28
      led_blue_int <= not cnt(25) and cnt(24);
29
    end if;        
30
  end process top_state;
31
  
32
  -- oscillator instantiation
33
  hsosc2 : HSOSC
34
    generic map (
35
      CLKHF_DIV  => "0b00"
36
    )
37
    port map (
38
      CLKHFPU => '1',
39
      CLKHFEN => '1',
40
      CLKHF   => clkHSOSC
41
    );
42
  
43
  -- led instantiation
44
  rgb2 : RGB
45
    generic map (
46
      CURRENT_MODE  => "0",
47
      RGB0_CURRENT  => "0b000001",
48
      RGB1_CURRENT  => "0b000001",
49
      RGB2_CURRENT  => "0b000001"
50
    )
51
    port map (
52
      CURREN   => '1',  -- I
53
      RGBLEDEN => '1',  -- I
54
      RGB0PWM  => led_red_int,  -- I
55
      RGB1PWM  => led_green_int,  -- I
56
      RGB2PWM  => led_blue_int,  -- I
57
      RGB2     => led_red,  -- O
58
      RGB1     => led_green,  -- O
59
      RGB0     => led_blue   -- O
60
    );
61
end rtl;