after slot5
[dide_16.git] / bsp4 / Designflow / src / vga_control_arc.vhd
1 -------------------------------------------------------------------------------\r
2 -- Title      : vga_control architecture\r
3 -- Project    : LU Digital Design\r
4 -------------------------------------------------------------------------------\r
5 -- File       : vga_control.vhd\r
6 -- Author     : Thomas Handl\r
7 -- Company    : TU Wien\r
8 -- Created    : 2004-12-15\r
9 -- Last update: 2006-02-24\r
10 -------------------------------------------------------------------------------\r
11 -- Description: generation of colors (RGB)\r
12 -------------------------------------------------------------------------------\r
13 -- Copyright (c) 2004 TU Wien\r
14 -------------------------------------------------------------------------------\r
15 -- Revisions  :\r
16 -- Date        Version  Author  Description\r
17 -- 2004-12-15  1.0      handl   Created\r
18 -- 2006-02-24  2.0      ST      revised\r
19 -------------------------------------------------------------------------------\r
20 \r
21 -------------------------------------------------------------------------------\r
22 -- LIBRARIES\r
23 -------------------------------------------------------------------------------\r
24 \r
25 library IEEE;\r
26 use IEEE.std_logic_1164.all;\r
27 use IEEE.std_logic_unsigned.all;\r
28 use IEEE.std_logic_arith.all;\r
29 \r
30 use work.vga_pak.all;\r
31 \r
32 -------------------------------------------------------------------------------\r
33 -- ARCHITECTURE\r
34 -------------------------------------------------------------------------------\r
35 \r
36 architecture behav of vga_control is\r
37 \r
38 \r
39   attribute syn_preserve          : boolean;\r
40   attribute syn_preserve of behav : architecture is true;\r
41 \r
42 \r
43   -- signal and constant declarations  \r
44   signal   r_next, g_next, b_next  : std_logic;                                 -- auxiliary signals for next state logic\r
45   signal   toggle_sig   : std_logic;                                            -- auxiliary signal to allow read back of toggle\r
46   signal   toggle_counter_sig  : std_logic_vector(TOG_CNT_WIDTH-1 downto 0);    -- auxiliary signal to allow read back of blinker\r
47   signal   toggle_next  : std_logic;                                            -- auxiliary signal for next state logic\r
48   signal   toggle_counter_next : std_logic_vector(TOG_CNT_WIDTH-1 downto 0);    -- auxiliary signal for next state logic\r
49   --constant HALFPERIOD   : std_logic_vector(TOG_CNT_WIDTH-1 downto 0) := "1100000000010001111011000";\r
50   constant HALFPERIOD   : std_logic_vector(TOG_CNT_WIDTH-1 downto 0) := "0000011111110010100000010"; -- 41,6666ms\r
51   --constant HALFPERIOD   : std_logic_vector(TOG_CNT_WIDTH-1 downto 0) :=   "0000101101110001101100000"; --60ms\r
52                                                                                 -- define half period of toggle frequency in clock ticks\r
53 \r
54 begin  \r
55   -----------------------------------------------------------------------------\r
56   -- draw rectangle on screen\r
57   -----------------------------------------------------------------------------\r
58     \r
59   DRAW_SQUARE_syn: process(clk, reset)\r
60   begin\r
61     if (reset = RES_ACT) then   -- draw black screen upon reset\r
62       r <= COLR_OFF;\r
63       g <= COLR_OFF;\r
64       b <= COLR_OFF;\r
65     elsif (clk'event and clk = '1') then     -- synchronous capture\r
66       r <= r_next;\r
67       g <= g_next;\r
68       b <= b_next;\r
69     end if;\r
70   end process;\r
71 \r
72 \r
73   DRAW_SQUARE_next: process (column_counter, line_counter, v_enable, h_enable, toggle_sig)\r
74   begin\r
75     if v_enable = ENABLE and h_enable = ENABLE then        \r
76       if (column_counter >= X_MIN and column_counter <= X_MAX and    -- if pixel within the rectangle borders\r
77           line_counter   >= Y_MIN and line_counter   <= Y_MAX) then\r
78         r_next <= COLR_OFF;\r
79         g_next <= COLR_OFF;                                          -- ...green\r
80         b_next <= toggle_sig;                                    -- ...blue\r
81       else                                                           -- if somewhere else on screen...\r
82         r_next <= COLR_OFF;\r
83         g_next <= COLR_OFF;                                          -- ... draw background color\r
84         b_next <= COLR_OFF;\r
85       end if;\r
86     else                                                             -- if out of screen...\r
87       r_next <= COLR_OFF;\r
88       g_next <= COLR_OFF;                                            -- ... do not activate any color\r
89       b_next <= COLR_OFF;                                            --     (black screen)\r
90     end if;\r
91   end process;\r
92 \r
93 \r
94   -----------------------------------------------------------------------------\r
95   -- control blinking of rectangle\r
96   -----------------------------------------------------------------------------\r
97 \r
98   BLINKER_syn: process(clk, reset)\r
99   begin\r
100     if (reset = RES_ACT) then                       -- asyn reset\r
101       toggle_counter_sig  <= (others => '0');\r
102       toggle_sig  <= COLR_OFF;\r
103     elsif(clk'event and clk = '1') then             -- synchronous capture\r
104       toggle_counter_sig <= toggle_counter_next;\r
105       toggle_sig  <= toggle_next;\r
106     end if;\r
107   end process;\r
108 \r
109 \r
110   BLINKER_next : process(toggle_counter_sig, toggle_sig)\r
111   begin\r
112     if toggle_counter_sig >= HALFPERIOD then           -- after half period ...\r
113       toggle_counter_next <= (others => '0');          -- ... clear counter\r
114       toggle_next  <= not(toggle_sig);                 -- ... and toggle colour.\r
115     else                                               -- before half period ...\r
116       toggle_counter_next <= toggle_counter_sig + '1'; -- ... increment counter\r
117       toggle_next  <= toggle_sig;                      -- ... and hold colour\r
118     end if;\r
119   end process;\r
120 \r
121 \r
122 -- assign auxiliary signals to module outputs\r
123 toggle <= toggle_sig;\r
124 toggle_counter <= toggle_counter_sig;\r
125 \r
126 end behav;\r
127 \r
128 -------------------------------------------------------------------------------\r
129 -- END ARCHITECTURE\r
130 -------------------------------------------------------------------------------\r