SHOW:
|
|
- or go back to the newest paste.
| 1 | ---------------------------------------------------------------------------------- | |
| 2 | -- Company: | |
| 3 | -- Engineer: | |
| 4 | -- | |
| 5 | -- Create Date: 15:29:44 03/10/2012 | |
| 6 | -- Design Name: | |
| 7 | -- Module Name: sculpture - sculpture_a | |
| 8 | -- Project Name: | |
| 9 | -- Target Devices: | |
| 10 | -- Tool versions: | |
| 11 | -- Description: | |
| 12 | -- | |
| 13 | -- Dependencies: | |
| 14 | -- | |
| 15 | -- Revision: | |
| 16 | -- Revision 0.01 - File Created | |
| 17 | -- Additional Comments: | |
| 18 | -- | |
| 19 | ---------------------------------------------------------------------------------- | |
| 20 | library IEEE; | |
| 21 | use IEEE.STD_LOGIC_1164.ALL; | |
| 22 | use IEEE.STD_LOGIC_unsigned.ALL; | |
| 23 | ||
| 24 | -- Uncomment the following library declaration if using | |
| 25 | -- arithmetic functions with Signed or Unsigned values | |
| 26 | --use IEEE.NUMERIC_STD.ALL; | |
| 27 | ||
| 28 | -- Uncomment the following library declaration if instantiating | |
| 29 | -- any Xilinx primitives in this code. | |
| 30 | --library UNISIM; | |
| 31 | --use UNISIM.VComponents.all; | |
| 32 | ||
| 33 | entity sculpture is | |
| 34 | Port ( clk : in STD_LOGIC; | |
| 35 | res : in STD_LOGIC; | |
| 36 | touch_sens : in STD_LOGIC_VECTOR (3 downto 0); | |
| 37 | motion_sens : in STD_LOGIC; | |
| 38 | state_out : out STD_LOGIC_VECTOR (1 downto 0); | |
| 39 | count_out : out STD_LOGIC_VECTOR (6 downto 0); | |
| 40 | panes : out STD_LOGIC_VECTOR (2 downto 0)); | |
| 41 | end sculpture; | |
| 42 | ||
| 43 | architecture sculpture_a of sculpture is | |
| 44 | ||
| 45 | component delay_counter is | |
| 46 | Port ( clk : in STD_LOGIC; | |
| 47 | res : in STD_LOGIC; | |
| 48 | start_count : in STD_LOGIC; | |
| 49 | count_done : out STD_LOGIC); | |
| 50 | end component; | |
| 51 | ||
| 52 | signal start_timer : std_logic; | |
| 53 | signal end_timer : std_logic; | |
| 54 | signal reset_cnt : std_logic; | |
| 55 | signal state : std_logic_vector(1 downto 0); | |
| 56 | signal next_state : std_logic_vector(1 downto 0); | |
| 57 | signal inc_cnt : std_logic; | |
| 58 | signal idle_cnt : std_logic_vector(6 downto 0); | |
| 59 | signal idle_cnt_done : std_logic; | |
| 60 | signal next_frame : std_logic_vector (2 downto 0); | |
| 61 | signal frame : std_logic_vector (2 downto 0); | |
| 62 | signal next_toggles : std_logic_vector (2 downto 0); | |
| 63 | signal toggles : std_logic_vector (2 downto 0); | |
| 64 | signal frame_cnt : std_logic_vector (3 downto 0); | |
| 65 | signal touch : std_logic_vector (2 downto 0); | |
| 66 | signal reset_frame_cnt : std_logic; | |
| 67 | signal reset_frame : std_logic; | |
| 68 | signal reset_toggle : std_logic; | |
| 69 | signal frame_on : std_logic; | |
| 70 | signal frame_done : std_logic; | |
| 71 | ||
| 72 | type frame_rom is array(0 to 15) of std_logic_vector(2 downto 0); | |
| 73 | ||
| 74 | constant RAND_ROM : frame_rom := ("111", "110", "101", "100", "011", "010", "001", "010", "100", "101", "110", "111", "000", "010", "101", "100");
| |
| 75 | ||
| 76 | constant ANIM_ROM : frame_rom := ("101", "010", "011", "100", "000", "111", "001", "101", "111", "110", "011", "010", "100", "001", "111", "010");
| |
| 77 | ||
| 78 | constant ANIM_COND : std_logic_vector(2 downto 0) := "111"; | |
| 79 | ||
| 80 | -- State 0 : RESET_S "00" | |
| 81 | -- State 1 : BORED "01" | |
| 82 | -- State 2 : PLAY "10" | |
| 83 | -- State 3 : ANIMATE "11" | |
| 84 | ||
| 85 | begin | |
| 86 | ||
| 87 | delay: delay_counter port map ( | |
| 88 | clk => clk, | |
| 89 | res => res, | |
| 90 | start_count => start_timer, | |
| 91 | count_done => end_timer | |
| 92 | ); | |
| 93 | ||
| 94 | --State Register | |
| 95 | process(clk, res) | |
| 96 | begin | |
| 97 | if (rising_edge(clk)) then | |
| 98 | if (res = '1') then | |
| 99 | state <= "00"; | |
| 100 | else | |
| 101 | state <= next_state; | |
| 102 | end if; | |
| 103 | end if; | |
| 104 | end process; | |
| 105 | ||
| 106 | --Next State Logic | |
| 107 | process(state,motion_sens,idle_cnt_done,end_timer,frame,toggles,touch_sens,frame_done,idle_cnt) | |
| 108 | begin | |
| 109 | case state is | |
| 110 | when "00" => | |
| 111 | inc_cnt <= '0'; | |
| 112 | reset_frame_cnt <= '1'; | |
| 113 | reset_frame <= '1'; | |
| 114 | reset_cnt <= '1'; | |
| 115 | reset_toggle <= '1'; | |
| 116 | start_timer <= '1'; | |
| 117 | frame_on <= '0'; | |
| 118 | next_state <= "01"; | |
| 119 | when "01" => | |
| 120 | if(motion_sens = '1') then | |
| 121 | inc_cnt <= '0'; | |
| 122 | reset_frame_cnt <= '0'; | |
| 123 | reset_frame <= '0'; | |
| 124 | reset_cnt <= '1'; | |
| 125 | reset_toggle <= '0'; | |
| 126 | start_timer <= '0'; | |
| 127 | frame_on <= '0'; | |
| 128 | next_state <= "10"; | |
| 129 | elsif(idle_cnt_done = '1') then | |
| 130 | inc_cnt <= '0'; | |
| 131 | reset_toggle <= '0'; | |
| 132 | reset_frame <= '0'; | |
| 133 | start_timer <= '0'; | |
| 134 | frame_on <= '1'; | |
| 135 | reset_cnt <= '1'; | |
| 136 | next_state <= "01"; | |
| 137 | elsif(end_timer = '1') then | |
| 138 | inc_cnt <= '1'; | |
| 139 | reset_toggle <= '0'; | |
| 140 | reset_frame <= '0'; | |
| 141 | reset_cnt <= '0'; | |
| 142 | start_timer <= '1'; | |
| 143 | frame_on <= '0'; | |
| 144 | next_state <= "01"; | |
| 145 | end if; | |
| 146 | when "10" => | |
| 147 | if((frame xor toggles) = "111") then | |
| 148 | inc_cnt <= '0'; | |
| 149 | reset_toggle <= '1'; | |
| 150 | reset_frame <= '0'; | |
| 151 | start_timer <= '0'; | |
| 152 | frame_on <= '0'; | |
| 153 | reset_cnt <= '1'; | |
| 154 | next_state <= "11"; | |
| 155 | elsif(touch_sens(0) = '1') then | |
| 156 | inc_cnt <= '0'; | |
| 157 | reset_toggle <= '0'; | |
| 158 | reset_frame <= '0'; | |
| 159 | start_timer <= '0'; | |
| 160 | frame_on <= '0'; | |
| 161 | touch(0) <= '1'; | |
| 162 | reset_cnt <= '1'; | |
| 163 | next_state <= "10"; | |
| 164 | elsif(touch_sens(1) = '1') then | |
| 165 | inc_cnt <= '0'; | |
| 166 | reset_toggle <= '0'; | |
| 167 | reset_frame <= '0'; | |
| 168 | start_timer <= '0'; | |
| 169 | frame_on <= '0'; | |
| 170 | touch(1) <= '1'; | |
| 171 | reset_cnt <= '1'; | |
| 172 | next_state <= "10"; | |
| 173 | elsif(touch_sens(2) = '1') then | |
| 174 | inc_cnt <= '0'; | |
| 175 | reset_toggle <= '0'; | |
| 176 | reset_frame <= '0'; | |
| 177 | start_timer <= '0'; | |
| 178 | frame_on <= '0'; | |
| 179 | touch(2) <= '1'; | |
| 180 | reset_cnt <= '1'; | |
| 181 | next_state <= "10"; | |
| 182 | elsif(idle_cnt_done = '1') then | |
| 183 | inc_cnt <= '0'; | |
| 184 | reset_toggle <= '0'; | |
| 185 | reset_frame <= '0'; | |
| 186 | start_timer <= '0'; | |
| 187 | frame_on <= '0'; | |
| 188 | reset_cnt <= '1'; | |
| 189 | next_state <= "01"; | |
| 190 | elsif(end_timer = '1') then | |
| 191 | inc_cnt <= '1'; | |
| 192 | reset_toggle <= '0'; | |
| 193 | reset_frame <= '0'; | |
| 194 | reset_cnt <= '0'; | |
| 195 | frame_on <= '0'; | |
| 196 | start_timer <= '1'; | |
| 197 | next_state <= "10"; | |
| 198 | end if; | |
| 199 | when "11" => | |
| 200 | if(frame_done = '1') then | |
| 201 | inc_cnt <= '0'; | |
| 202 | reset_toggle <= '0'; | |
| 203 | reset_frame <= '0'; | |
| 204 | start_timer <= '0'; | |
| 205 | frame_on <= '0'; | |
| 206 | reset_cnt <= '0'; | |
| 207 | next_state <= "10"; | |
| 208 | elsif(idle_cnt = "0000001") then | |
| 209 | inc_cnt <= '0'; | |
| 210 | reset_toggle <= '0'; | |
| 211 | reset_frame <= '0'; | |
| 212 | start_timer <= '0'; | |
| 213 | reset_cnt <= '1'; | |
| 214 | frame_on <= '1'; | |
| 215 | next_state <= "11"; | |
| 216 | elsif(end_timer = '1') then | |
| 217 | inc_cnt <= '1'; | |
| 218 | reset_toggle <= '0'; | |
| 219 | reset_frame <= '0'; | |
| 220 | reset_cnt <= '0'; | |
| 221 | frame_on <= '0'; | |
| 222 | start_timer <= '1'; | |
| 223 | next_state <= "11"; | |
| 224 | end if; | |
| 225 | when others => | |
| 226 | inc_cnt <= inc_cnt; | |
| 227 | - | reset_toggle <= '0'; |
| 227 | + | reset_toggle <= reset_toggle; |
| 228 | - | reset_frame <= '0'; |
| 228 | + | reset_frame <= reset_frame; |
| 229 | - | start_timer <= '0'; |
| 229 | + | start_timer <= start_timer; |
| 230 | frame_on <= frame_on; | |
| 231 | - | reset_cnt <= '0'; |
| 231 | + | reset_cnt <= reset_cnt; |
| 232 | - | next_state <= "00"; |
| 232 | + | next_state <= next_state; |
| 233 | end case; | |
| 234 | end process; | |
| 235 | ||
| 236 | -- Array Register | |
| 237 | process(clk, res, reset_frame_cnt, frame_on) | |
| 238 | begin | |
| 239 | if(rising_edge(clk)) then | |
| 240 | if(res = '1') then | |
| 241 | frame_cnt <= X"0"; | |
| 242 | elsif(reset_frame_cnt = '1') then | |
| 243 | frame_cnt <= X"0"; | |
| 244 | elsif(frame_on = '1') then | |
| 245 | frame_cnt <= frame_cnt + '1'; | |
| 246 | else | |
| 247 | frame_cnt <= frame_cnt; | |
| 248 | end if; | |
| 249 | end if; | |
| 250 | end process; | |
| 251 | ||
| 252 | frame_done <= '1' when (frame_cnt = X"F") else '0'; | |
| 253 | ||
| 254 | -- Frame Register | |
| 255 | process(clk, res, reset_frame, state) | |
| 256 | begin | |
| 257 | if(rising_edge(clk)) then | |
| 258 | if(res = '1') then | |
| 259 | next_frame <= "000"; | |
| 260 | elsif(reset_frame = '1') then | |
| 261 | next_frame <= "000"; | |
| 262 | elsif(state = "01") then | |
| 263 | next_frame <= RAND_ROM(conv_integer(frame_cnt)); | |
| 264 | elsif(state = "11") then | |
| 265 | next_frame <= ANIM_ROM(conv_integer(frame_cnt)); | |
| 266 | end if; | |
| 267 | end if; | |
| 268 | end process; | |
| 269 | ||
| 270 | -- Idle counter | |
| 271 | process(clk, res, reset_cnt, inc_cnt) | |
| 272 | begin | |
| 273 | if(rising_edge(clk)) then | |
| 274 | if (res = '1') then | |
| 275 | idle_cnt <= "0000000"; | |
| 276 | elsif (reset_cnt = '1') then | |
| 277 | idle_cnt <= "0000000"; | |
| 278 | elsif (inc_cnt = '1') then | |
| 279 | idle_cnt <= idle_cnt + '1'; | |
| 280 | else | |
| 281 | idle_cnt <= idle_cnt; | |
| 282 | end if; | |
| 283 | end if; | |
| 284 | end process; | |
| 285 | ||
| 286 | idle_cnt_done <= '1' when (idle_cnt = "1111111") else '0'; | |
| 287 | ||
| 288 | -- Toggles Register | |
| 289 | process(clk, res, reset_toggle, touch) | |
| 290 | begin | |
| 291 | if(rising_edge(clk)) then | |
| 292 | if(res = '1') then | |
| 293 | next_toggles <= "000"; | |
| 294 | elsif(reset_toggle = '1') then | |
| 295 | next_toggles <= "000"; | |
| 296 | elsif(touch(0) = '1') then | |
| 297 | next_toggles <= NOT(toggles xor "001"); | |
| 298 | elsif(touch(1) = '1') then | |
| 299 | next_toggles <= NOT(toggles xor "010"); | |
| 300 | elsif(touch(2) = '1') then | |
| 301 | next_toggles <= NOT(toggles xor "100"); | |
| 302 | else | |
| 303 | next_toggles <= next_toggles; | |
| 304 | end if; | |
| 305 | end if; | |
| 306 | end process; | |
| 307 | ||
| 308 | frame <= next_frame; | |
| 309 | toggles <= next_toggles; | |
| 310 | panes <= frame xor toggles; | |
| 311 | state_out <= state; | |
| 312 | count_out <= idle_cnt; | |
| 313 | ||
| 314 | end sculpture_a; |