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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [examples/] [lightshow/] [fpga-2.18/] [lightshow.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
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 lightshow is
7
   port(
8
      led0     : out std_logic;                      -- LED on FPGA Board
9
      led1     : out std_logic_vector(9 downto 0);   -- LED1 on Debug Board
10
      led2     : out std_logic_vector(19 downto 0);  -- LED2 + LED3 on Debug Board
11
      sw       : in std_logic_vector(3 downto 0);
12
      fxclk    : in std_logic
13
   );
14
end lightshow;
15
 
16
--signal declaration
17
architecture RTL of lightshow is
18
 
19
type tPattern1 is array(9 downto 0) of integer range 0 to 255;
20
type tPattern2 is array(19 downto 0) of integer range 0 to 255;
21
 
22
signal pattern1  : tPattern1 := (0, 10, 41, 92, 163, 255, 163, 92, 41, 10);                                      -- pattern for LED1
23
signal pattern20 : tPattern2 := (0, 1, 2, 9, 16, 25, 36, 49, 64, 81, 64, 49, 36, 25, 16, 9, 2, 1, 0, 0);   -- 1st pattern for LED2
24
signal pattern21 : tPattern2 := (0, 19, 77, 174, 77, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);            -- 2nd pattern for LED2
25
signal pattern2  : tPattern2;                                                                                   -- pattern20 + pattern21
26
 
27
signal cnt1,cnt20, cnt21  : std_logic_vector(21 downto 0);
28
signal cnt3               : std_logic_vector(231 downto 0);
29
signal pwm_cnt            : std_logic_vector(18 downto 0);
30
signal pwm_cnt8           : std_logic_vector(7 downto 0);
31
signal led0_buf           : std_logic;
32
 
33
begin
34
    pwm_cnt8 <= pwm_cnt(18 downto 11);
35
 
36
    led0 <= led0_buf;
37
 
38
    dp_fxclk: process(fxclk)
39
    begin
40
         if fxclk' event and fxclk = '1' then
41
 
42
            -- pattern for led 0
43
            if ( cnt3 >= conv_std_logic_vector(13000000,24) )  -- 1 Hz
44
            then
45
                led0_buf <= not led0_buf;
46
                cnt3  <= (others => '0');
47
            else
48
                cnt3 <= cnt3 + 1;
49
            end if;
50
 
51
            -- pattern for led 1
52
            if ( cnt1 >= conv_std_logic_vector(3900000,22) )  -- 1/1.5 Hz
53
            then
54
                if ( sw(0) = '1' )
55
                then
56
                    pattern1(8 downto 0) <= pattern1(9 downto 1);
57
                    pattern1(9) <= pattern1(0);
58
                else
59
                    pattern1(9 downto 1) <= pattern1(8 downto 0);
60
                    pattern1(0) <= pattern1(9);
61
                end if;
62
                cnt1  <= (others => '0');
63
            else
64
                cnt1 <= cnt1  + 1;
65
            end if;
66
 
67
            -- pattern for led 2
68
            if ( ( cnt20 >= conv_std_logic_vector(2600000,22) ) or ( (sw(2)= '1') and (cnt20 >= conv_std_logic_vector(1040000,22)) ) )  -- SW1 off: 0.2Hz, SW1 on: 0.5Hz
69
            then
70
                pattern20(18 downto 0) <= pattern20(19 downto 1);
71
                pattern20(19) <= pattern20(0);
72
                cnt20 <= (others => '0');
73
            else
74
                cnt20 <= cnt20 + 1;
75
            end if;
76
 
77
            if ( ( cnt21 >= conv_std_logic_vector(1000000,22) ) or ( (sw(3)= '1') and (cnt21 >= conv_std_logic_vector(250000,22)) ) )
78
            then
79
                if ( sw(1) = '1' )
80
                then
81
                    pattern21(18 downto 0) <= pattern21(19 downto 1);
82
                    pattern21(19) <= pattern21(0);
83
                else
84
                    pattern21(19 downto 1) <= pattern21(18 downto 0);
85
                    pattern21(0) <= pattern21(19);
86
                end if;
87
                cnt21 <= (others => '0');
88
            else
89
                cnt21 <= cnt21 + 1;
90
            end if;
91
 
92
            for i in 0 to 19 loop
93
                pattern2(i) <= pattern20(i) + pattern21(i);
94
            end loop;
95
 
96
            -- pwm
97
            if ( pwm_cnt8 = conv_std_logic_vector(255,8) )
98
            then
99
                pwm_cnt <= ( others => '0' );
100
            else
101
                pwm_cnt <= pwm_cnt + 1;
102
            end if;
103
            -- led1
104
            for i in 0 to 9 loop
105
                if ( pwm_cnt8 < pattern1(i) )
106
                then
107
                    led1(i) <= '1';
108
                else
109
                    led1(i) <= '0';
110
                end if;
111
            end loop;
112
            for i in 0 to 19 loop
113
                if (pwm_cnt8 < pattern2(i) )
114
                then
115
                    led2(i) <= '1';
116
                else
117
                    led2(i) <= '0';
118
                end if;
119
            end loop;
120
 
121
        end if;
122
    end process dp_fxclk;
123
 
124
end RTL;

powered by: WebSVN 2.1.0

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