OpenCores
URL https://opencores.org/ocsvn/lpd8806/lpd8806/trunk

Subversion Repositories lpd8806

[/] [lpd8806/] [trunk/] [fpga.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jclaytons
--------------------------------------
2
-- LPD8806 RGB LED string driver FPGA
3
--------------------------------------
4
--
5
-- Capable of lighting up a string of
6
-- colorful LEDs with any desired
7
-- colors, at a specific update rate.
8
--
9
--------------------------------------
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.numeric_std.all;
14
use ieee.math_real.all;
15
 
16
use ieee.std_logic_textio.all;
17
 
18
library work;
19
use work.lpd8806_pack.all;
20
use work.convert_pack.all;
21
 
22
entity fpga is
23
  port (
24
    -- System Clock & Reset_n
25
    sys_clk      : in    std_logic; -- FPGA clock
26
    sys_rst_n    : in    std_logic;
27
 
28
    -- lpd8806 I/O
29
    rgb_led_clk  : out   std_logic;
30
    rgb_led_dat  : out   std_logic;
31
 
32
    -- Standardized Board Inputs / Outputs
33
    switch       : in    unsigned(7 downto 0);
34
    led          : out   unsigned(7 downto 0)
35
 
36
  );
37
end fpga;
38
 
39
architecture beh of fpga is
40
  -- Constants
41
  constant SYS_CLK_RATE    : real :=  25000000.0; -- The clock rate at which the FPGA runs
42
 
43
  --Component Declarations
44
 
45
  ----------------------------------------------------------------------------
46
  --Internal signal declarations
47
 
48
    -- Reset signals (can be asserted through syscon)
49
  signal fpga_rst_n        : std_logic;
50
 
51
  -----------------------------------------------
52
  -- Board Input & Output related
53
 
54
  signal switch_l         : unsigned(7 downto 0);
55
 
56
  -- Colorful Display related
57
  signal lpd8806_c_adr    : unsigned(7 downto 0);
58
  signal lpd8806_c_dat    : unsigned(6 downto 0);
59
  signal lpd8806_sclk     : std_logic;
60
  signal lpd8806_sdat     : std_logic;
61
 
62
  -- Test and Debug related
63
  signal spi_sclk         : std_logic;
64
  signal spi_sdat         : std_logic;
65
 
66
-------------------------------------------------
67
begin
68
 
69
 
70
  -- Invert switch inputs.  On this board, "switch on" is a low logic level.
71
  switch_l <= not (switch);
72
 
73
  -- System clock enable currently not used.
74
  sys_clk_en <= '1';
75
 
76
  -- Assign LED outputs.  These LEDs illuminate when driven low.
77
  led <= switch;
78
 
79
  ------------------------------
80
  -- Drive lpd8806 RGB LED string
81
  lpd8806_0 : lpd8806_LED_chain_driver
82
    generic map(
83
      SCLK_FREQ    => 2000000.0, -- Desired lpd8806 serial clock frequency
84
      UPDATE_FREQ  => 20.0,      -- Desired LED chain update frequency
85
      SYS_CLK_RATE => SYS_CLK_RATE,  -- underlying clock rate
86
      N_LEDS       => 8           -- Number of LEDs in chain
87
    )
88
    port map(
89
 
90
      -- System Clock, Reset and Clock Enable
91
      sys_rst_n   => sys_rst_n,
92
      sys_clk     => sys_clk,
93
      sys_clk_en  => sys_clk_en,
94
 
95
      -- Selection of color information
96
      c_adr_o     => lpd8806_c_adr,
97
      c_dat_i     => lpd8806_c_dat,
98
 
99
      -- Output
100
      sclk_o      => lpd8806_sclk,
101
      sdat_o      => lpd8806_sdat
102
    );
103
 
104
  with to_integer(lpd8806_c_adr) select
105
    lpd8806_c_dat <=
106
                             -- LED 0
107
      "1111111"            when 16#00#, -- Green
108
      "0000000"            when 16#01#, -- Red
109
      "0000000"            when 16#02#, -- Blue
110
                             -- LED 1
111
      "1111111"            when 16#04#, -- Green
112
      "1111111"            when 16#05#, -- Red
113
      "0000000"            when 16#06#, -- Blue
114
                             -- LED 2
115
      "0000000"            when 16#08#, -- Green
116
      "1111111"            when 16#09#, -- Red
117
      "0000000"            when 16#0A#, -- Blue
118
                             -- LED 3
119
      "0000000"            when 16#0C#, -- Green
120
      "0000000"            when 16#0D#, -- Red
121
      "1111111"            when 16#0E#, -- Blue
122
                             -- LED 4
123
      "0000000"            when 16#10#, -- Green
124
      switch_l(6 downto 0) when 16#11#, -- Red
125
      "0000000"            when 16#12#, -- Blue
126
                             -- LED 5
127
      switch_l(6 downto 0) when 16#14#, -- Green
128
      "0000000"            when 16#15#, -- Red
129
      "0000000"            when 16#16#, -- Blue
130
                             -- LED 6
131
      "0000000"            when 16#18#, -- Green
132
      "0000000"            when 16#19#, -- Red
133
      switch_l(6 downto 0) when 16#1A#, -- Blue
134
                             -- LED 7
135
      switch_l(6 downto 0) when 16#1C#, -- Green
136
      switch_l(6 downto 0) when 16#1D#, -- Red
137
      switch_l(6 downto 0) when 16#1E#, -- Blue
138
 
139
      "1111111"           when others;
140
 
141
 
142
  ------------------------------
143
  -- Debug lpd8806 RGB LED string
144
  spi_writer_0 : spi_byte_writer
145
    generic map(
146
      SCLK_FREQ    => 2000000.0,    -- Desired lpd8806 serial clock frequency
147
      SYS_CLK_RATE => SYS_CLK_RATE  -- underlying clock rate
148
    )
149
    port map(
150
 
151
      -- System Clock, Reset and Clock Enable
152
      sys_rst_n   => sys_rst_n,
153
      sys_clk     => sys_clk,
154
      sys_clk_en  => sys_clk_en,
155
 
156
      -- Data to send.
157
      sel_i       => sel_led,
158
      we_i        => bus_we,
159
      dat_i       => bus_dat_wr(7 downto 0),
160
 
161
      -- Output
162
      ssel_o      => open,
163
      sclk_o      => spi_sclk,
164
      sdat_o      => spi_sdat
165
    );
166
 
167
  rgb_led_clk <= lpd8806_sclk when switch_l(7)='0' else spi_sclk;
168
  rgb_led_dat <= lpd8806_sdat when switch_l(7)='0' else spi_sdat;
169
 
170
 
171
 
172
end beh;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.