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

Subversion Repositories usb_fpga_2_13

[/] [usb_fpga_2_13/] [trunk/] [examples/] [usb-fpga-2.16/] [2.16b/] [lightshow/] [fpga/] [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
      led1     : out std_logic_vector(9 downto 0);   -- LED1 on debug board
9
      led2     : out std_logic_vector(19 downto 0);  -- LED2 + LED3 on debug board
10
      sw       : in std_logic_vector(3 downto 0);
11
      fxclk    : in std_logic
12
   );
13
end lightshow;
14
 
15
--signal declaration
16
architecture RTL of lightshow is
17
 
18
type tPattern1 is array(9 downto 0) of integer range 0 to 255;
19
type tPattern2 is array(19 downto 0) of integer range 0 to 255;
20
 
21
signal pattern1  : tPattern1 := (0, 10, 41, 92, 163, 255, 163, 92, 41, 10);                                      -- pattern for LED1
22
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
23
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
24
signal pattern2  : tPattern2;                                                                                   -- pattern20 + pattern21
25
 
26
signal cnt1,cnt20, cnt21  : std_logic_vector(22 downto 0);
27
signal pwm_cnt            : std_logic_vector(19 downto 0);
28
signal pwm_cnt8           : std_logic_vector(7 downto 0);
29
 
30
begin
31
    pwm_cnt8 <= pwm_cnt(19 downto 12);
32
 
33
    dp_fxclk: process(fxclk)
34
    begin
35
         if fxclk' event and fxclk = '1' then
36
 
37
            -- pattern for led 1
38
            if ( cnt1 >= conv_std_logic_vector(7200000,23) )  -- 1/1.5 Hz
39
            then
40
                if ( sw(0) = '1' )
41
                then
42
                    pattern1(8 downto 0) <= pattern1(9 downto 1);
43
                    pattern1(9) <= pattern1(0);
44
                else
45
                    pattern1(9 downto 1) <= pattern1(8 downto 0);
46
                    pattern1(0) <= pattern1(9);
47
                end if;
48
                cnt1  <= (others => '0');
49
            else
50
                cnt1 <= cnt1  + 1;
51
            end if;
52
 
53
            -- pattern for led 2
54
            if ( ( cnt20 >= conv_std_logic_vector(4800000,23) ) or ( (sw(2)= '1') and (cnt20 >= conv_std_logic_vector(1600000,23)) ) )  -- SW1 off: 1/3Hz, SW1 on: 1Hz
55
            then
56
                pattern20(18 downto 0) <= pattern20(19 downto 1);
57
                pattern20(19) <= pattern20(0);
58
                cnt20 <= (others => '0');
59
            else
60
                cnt20 <= cnt20 + 1;
61
            end if;
62
 
63
            if ( ( cnt21 >= conv_std_logic_vector(2000000,23) ) or ( (sw(3)= '1') and (cnt21 >= conv_std_logic_vector(500000,23)) ) )
64
            then
65
                if ( sw(1) = '1' )
66
                then
67
                    pattern21(18 downto 0) <= pattern21(19 downto 1);
68
                    pattern21(19) <= pattern21(0);
69
                else
70
                    pattern21(19 downto 1) <= pattern21(18 downto 0);
71
                    pattern21(0) <= pattern21(19);
72
                end if;
73
                cnt21 <= (others => '0');
74
            else
75
                cnt21 <= cnt21 + 1;
76
            end if;
77
 
78
            for i in 0 to 19 loop
79
                pattern2(i) <= pattern20(i) + pattern21(i);
80
            end loop;
81
 
82
            -- pwm
83
            if ( pwm_cnt8 = conv_std_logic_vector(255,8) )
84
            then
85
                pwm_cnt <= ( others => '0' );
86
            else
87
                pwm_cnt <= pwm_cnt + 1;
88
            end if;
89
            -- led1
90
            for i in 0 to 9 loop
91
                if ( pwm_cnt8 < pattern1(i) )
92
                then
93
                    led1(i) <= '1';
94
                else
95
                    led1(i) <= '0';
96
                end if;
97
            end loop;
98
            for i in 0 to 19 loop
99
                if (pwm_cnt8 < pattern2(i) )
100
                then
101
                    led2(i) <= '1';
102
                else
103
                    led2(i) <= '0';
104
                end if;
105
            end loop;
106
 
107
        end if;
108
    end process dp_fxclk;
109
 
110
end RTL;

powered by: WebSVN 2.1.0

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