Omar20
Newbie level 4
- Joined
- Feb 10, 2014
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 242
Guy, post your code so far and and we will help guy.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 -- Component: MULTIPLEXOR -------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity mux is port( rst, sLine: in std_logic; load, result: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 3 downto 0 ) ); end mux; architecture mux_arc of mux is begin process( rst, sLine, load, result ) begin if( rst = '1' ) then output <= "0000"; -- do nothing elsif sLine = '0' then output <= load; -- load inputs else output <= result; -- load results end if; end process; end mux_arc; -- Component: COMPARATOR --------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity comparator is port( rst: in std_logic; x, y: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 1 downto 0 ) ); end comparator; architecture comparator_arc of comparator is begin process( x, y, rst ) begin if( rst = '1' ) then output <= "00"; -- do nothing elsif( x > y ) then output <= "10"; -- if x greater elsif( x < y ) then output <= "01"; -- if y greater else output <= "11"; -- if equivalance. end if; end process; end comparator_arc; -- Component: SUBTRACTOR ---------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity subtractor is port( rst: in std_logic; cmd: in std_logic_vector( 1 downto 0 ); x, y: in std_logic_vector( 3 downto 0 ); xout, yout: out std_logic_vector( 3 downto 0 ) ); end subtractor; architecture subtractor_arc of subtractor is begin process( rst, cmd, x, y ) begin if( rst = '1' or cmd = "00" ) then -- not active. xout <= "0000"; yout <= "0000"; elsif( cmd = "10" ) then -- x is greater xout <= ( x - y ); yout <= y; elsif( cmd = "01" ) then -- y is greater xout <= x; yout <= ( y - x ); else xout <= x; -- x and y are equal yout <= y; end if; end process; end subtractor_arc; -- Component: REGISTER --------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity regis is port( rst, clk, load: in std_logic; input: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 3 downto 0 ) ); end regis; architecture regis_arc of regis is begin process( rst, clk, load, input ) begin if( rst = '1' ) then output <= "0000"; elsif( clk'event and clk = '1') then if( load = '1' ) then output <= input; end if; end if; end process; end regis_arc; -- component: FSM controller -------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity fsm is port( rst, clk, proceed: in std_logic; comparison: in std_logic_vector( 1 downto 0 ); enable, xsel, ysel, xld, yld: out std_logic ); end fsm; architecture fsm_arc of fsm is type states is ( init, s0, s1, s2, s3, s4, s5 ); signal nState, cState: states; begin process( rst, clk ) begin if( rst = '1' ) then cState <= init; elsif( clk'event and clk = '1' ) then cState <= nState; end if; end process; process( proceed, comparison, cState ) begin case cState is when init => if( proceed = '0' ) then nState <= init; else nState <= s0; end if; when s0 => enable <= '0'; xsel <= '0'; ysel <= '0'; xld <= '0'; yld <= '0'; nState <= s1; when s1 => enable <= '0'; xsel <= '0'; ysel <= '0'; xld <= '1'; yld <= '1'; nState <= s2; when s2 => xld <= '0'; yld <= '0'; if( comparison = "10" ) then nState <= s3; elsif( comparison = "01" ) then nState <= s4; elsif( comparison = "11" ) then nState <= s5; end if; when s3 => enable <= '0'; xsel <= '1'; ysel <= '0'; xld <= '1'; yld <= '0'; nState <= s2; when s4 => enable <= '0'; xsel <= '0'; ysel <= '1'; xld <= '0'; yld <= '1'; nState <= s2; when s5 => enable <= '1'; xsel <= '1'; ysel <= '1'; xld <= '1'; yld <= '1'; nState <= s0; when others => nState <= s0; end case; end process; end fsm_arc; ---------------------------------------------------------------------- -- GCD Calculator: top level design using structural modeling -- FSM + Datapath (mux, registers, subtracter and comparator) ---------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; use work.all; entity gcd is port( rst, clk, go_i: in std_logic; x_i, y_i: in std_logic_vector( 3 downto 0 ); d_o: out std_logic_vector( 3 downto 0 ) ); end gcd; architecture gcd_arc of gcd is component fsm is port( rst, clk, proceed: in std_logic; comparison: in std_logic_vector( 1 downto 0 ); enable, xsel, ysel, xld, yld: out std_logic ); end component; component mux is port( rst, sLine: in std_logic; load, result: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 3 downto 0 ) ); end component; component comparator is port( rst: in std_logic; x, y: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 1 downto 0 ) ); end component; component subtractor is port( rst: in std_logic; cmd: in std_logic_vector( 1 downto 0 ); x, y: in std_logic_vector( 3 downto 0 ); xout, yout: out std_logic_vector( 3 downto 0 ) ); end component; component regis is port( rst, clk, load: in std_logic; input: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 3 downto 0 ) ); end component; signal xld, yld, xsel, ysel, enable: std_logic; signal comparison: std_logic_vector( 1 downto 0 ); signal result: std_logic_vector( 3 downto 0 ); signal xsub, ysub, xmux, ymux, xreg, yreg: std_logic_vector( 3 downto 0 ); begin -- doing structure modeling here -- FSM controller TOFSM: fsm port map( rst, clk, go_i, comparison, enable, xsel, ysel, xld, yld ); -- Datapath X_MUX: mux port map( rst, xsel, x_i, xsub, xmux ); Y_MUX: mux port map( rst, ysel, y_i, ysub, ymux ); X_REG: regis port map( rst, clk, xld, xmux, xreg ); Y_REG: regis port map( rst, clk, yld, ymux, yreg ); U_COMP: comparator port map( rst, xreg, yreg, comparison ); X_SUB: subtractor port map( rst, comparison, xreg, yreg, xsub, ysub ); OUT_REG: regis port map( rst, clk, enable, xsub, result ); d_o <= result; end gcd_arc; ---------------------------------------------------------------------------
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 Library IEEE; Use IEEE.STD_CALC_PAK is Package MY_CALC_PAK is Type MY_RECORD is Record OP_CODE : std_logic_vector(3 downto 0); -- opcode A_IN : std_logic_vector(3 downto 0); --A operand B_IN : std_logic_vector(3 downto 0); --B operand C_IN : std_logic; -- C_In operand Exp out : std_logic_vector(3 downto 0); -- expected output End record; end MY_CALC_PAk; LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.ALL; use CALC1_PAK.ALL; ENTITY CNTRL_FSM_Tb-vhd IS END CNTRL_FSM_TB_vhd; ARCHITECTUTER behavior OF CNTRL_FSM_TB-vhd IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT CNTRL_FSM PORT( DATA_FRAME : IN MY_RECORD; CLK : IN std_logic; RESET: IN std_logic; MEM_EN : OUT std_logic; ADDR : OUT std_logic_vector(3 downto 0); ALU_EN : OUT std_logic; A_IN : OUT std_logic_vector(3 downto 0); B_IN : OUT std_logic_vector(3 downto 0); OP_CODE : OUT std_logic_vector(3 downto 0); C_IN : OUT std_logic; COMP_EN : OUT std_logic; EXP : OUT std_logic_vector(3 downto 0); ); END COMPONENT; -- Inputs SIGNAL DATA_FRAME : MY-RECORD := (A_IN=> *0111*, B_IN=>*0011*, OP_CODE =>*0000*, C_IN=> β0β, EXP_OUT=>β0111β); SIGNAL CLK : std_logic :=β0β; SIGNAL RESET: std_logic :='0'; -- Outputs SIGNAL MEM_EN : std_logic; SIGNAL ADDR : std_logic_vector(3 downto 0); SIGNAL ALU_EN : std_logic; SIGNAL A_IN : std_logic_vector(3 downto 0); SIGNAL B_IN : std_logic_vector(3 downto 0); SIGNAL OP_CODE : std_logic_vector(3 downto 0); SIGNAL C_IN : std_logic; SIGNAL COMP_EN : std_logic; SIGNAL EXP : std_logic_vector(3 downto 0); BEGIN -- Instantiate the Unit Under Test (UM) uut: CNTRL_FSM PORT MAP( DATA_FRAME => DATA_FRAME, CLK => CLK RESET => RESET. MEM_EN => MEM_EN. ADDR => ADDR. ALU_EN => ALU_EN, A IN => A_IN, B_IN => B_IN, OP_CODE => OP_CODE, C_IN => C_IN, COMP EN => COMP_EN, EXP=>EXP ); CLK <= not CLK after 10 ns; -- 50 MHz clock RESET <= '0','1' after 10 ns, '0' after 25ns, '1' after 800ns, '0' after 825ns; --test_proc : PROCESS --BEGIN tb : PROCESS BEGIN DATA_FRAME <= ("1000", "0100", "0000", "0000"); wait for 100 ns; DATA_FRAME <=("1000","0100β,β0101","0","0000β); wait for 100 ns; DATA_FRAME <=("1000","0100","0101","0","0000"); Wait; - will wait forever --END PROCESS test-proc; END; library ieee; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use MY_CALC_PAK.ALL entity CNTRL_FSM is port (DATA_FRAME : in MY_RECORD; CLK : in STD_LOGIC; RESET: in STD_LOGIC; MEM-EN: out STD_LOGIC; ADDR : out STD_LOGIC_VECTOR(4 downto 0); ALU_EN : out STD_LOGIC; A_IN: out STD_LOGIC_VECTOR(3 downto 0); B_IN: out STD_LOGIC_VECTOR(3 downto 0); OP_CODE : out STD_LOGIC_VECTOR(3 downto 0); C_IN : out STD_LOGIC; COMP EN : out std_logic; EXP : out std_logic_vector(3 downto 0); end CNTRL_FSM; architecture Behavioral of CNTRL_FSM is type State is (INIT, FETCH, ALU, COMP, DONE); signal Curr_State, Next_State: State; signal ADDR_INT : std_logic_vector(4 downto 0); signal ADDR_Q : std_logic_vector(4 downto 0); begin ADDR <= ADDR_Q Sync: process (CLK.RESET) begin if RESET = T then Curr_State <= Next_State; ADDR_Q <= (others => '0') else if rising_edge(CLK) then curr_State <= Next_State; ADDR_Q <= ADDR_INT: end if; end process Syne; find_Next_State: process (Curr_State,DATA_FRAME,ADDR_Q) begin A_IN <= DATA_FRAME.A_IN; B_IN <= DATA_FRAME.B_IN; C_IN <= DATA_FRAME.C_IN; OP_CODE <= DATA_FRAME.OP_CODE; ADDR_INT <= ADDR Q EXP<= DATA_FRAME.EXP_OUT; case (Curr_State) is when INIT => -- set up initial defaults MEM_EN <= '0'; Alu_en <= '0'; COMP_EN <= '0'; ADDR INT <= (others => '0' ); Next State <= FETCH; when FETCH => MEM_EN <= '1'; ALU_EN <= '0'; COMP_EN <= '0'; Next State <= ALU; when ALU => MEM_EN <= '0'; ALU_EN <= '1'; COMP_EN<= '0'; Next State <= COMP; when COMP => MEM_EN <= '0'; ALU_EN <= '0'; COMP_EN <= '1'; when DONE => MEM_EN <= '0'; ALU_EN <= '0'; COMP_EN <= '0'; IF ADDR_Q <= "11111" then ADDR INT <= ADDR Q + '1'; Next _state <= FETCH; else Next _State <= DONE; end if; when others => MEM_EN<= '0'; ALU_EN <= '0'; COMP_EN<= '0β; Next _State <= INIT; end case; end process Find_Next_State; end BEhavioral: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD LOGIC_UNSIGNED.ALL; entity COMP is port (COMP_EN : in STD_LOGIC; CLK : in STD LOGIC, EXPECTED: in STD_LOGIC_VECTOR(3 downto 0); ALU_OUT : in STD_LOGIC_VECTOR(3 downto 0); RESULT: out STD_LOGIC; End COMP; Architecture RTL of COMP is Begin Process (CLK) Begin If rising_edge(CLK) then If comp_en = '1' then If ALU_OUT = EXPECTED then RESULT <= ' l'; Else RESULT <= '0'; End if; End if; End if; End process; End RTL; LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.ALL; ENTITY COMP TB_vhd IS END COMP TB vhd; ARCHITECTURE test OF COMP_TB_vhd IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT COMP PORT( COMP_EN : in STD_LOGIC; CLK : in STD_LOGIC; EXPECTED: in STD_LOGIC_VECTOR(3 downto 0); ALU_OUT : in STD_LOGIC_VECTOR(3 downto 0); RESULT: out STD_LOGIC ); END COMPONENT, -- inputs SIGNAL COMP_EN: std_logic : = '1' SIGNAL CLK : std_logic : = '0' SIGNAL EXPECTED: std_logic_vector(3 downto 0);= "0001"; SIGNAL ALU_OUT : std_logic_vector(3 downto 0);= "0001"; --Output SIGNAL RESULT: std_logic; BEGIN --Instantiate the Unit Under Test (UUT) uut: COMP PORT MAP( COMP_EN => COMP_EN, CLK => CLK, EXPECTED => EXPECTED, ALU_OUT => ALU_OUT, RESULT => RESULT ); CLK <= not CLK after l0ns; test_proc : PROCESS BEGIN Wait for 5ns Expected <= "0010" after 100ns Wait; END PROCESS test_proc; END; library IEEE; use IEEE.STD_LOGIC_I164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IFEE.STD_LOGIC_UNSIGNED.ALL; use MY_CALC_PAK.ALL; Entity MY_CALC is generic (SYNTH: Boolean := false); Port (CLK : in STD_LOGIC; RESET: in STD_LOGIC; RESULT: out STD_LOGIC; and MY_CALC); architecture Structural of MY_CALC is component MEM port (CLK : in STD_LOGIC; ADDR : in STD_LOGIC_VECTOR (4 downto 0); READ_EN : in STD_LOGIC; DATA_FRAME : out MY_RECORD); End component; Component CNTRL_FSM Port (DATA_FRAME : in MY RECORD CLK : in STD_LOGIC; RESET: in STD_LOGIC; MEM_EN : out STD_LOGIC ADDR : out STD_LOGIC_VECTOR(4 downto 0); ALU_EN : out STD_LOGIC A_IN : out in STD_LOGIC_VECTOR(3 downto 0); B_IN : out STD_LOGIC_VECTOR(3 downto 0); OP_CODE : out STD LOGIC_VECTOR(3 downto 0); C_IN : out STD_LOGIC; COMP_EN : out std_logic; EXP : out std_logic_vector(3 downto 0); End component; Component ALU Port (A : in STD_LOGIC_VECTOR(3 downto 0); B: in STD_LOGIC_VECTOR(3 downto 0); C_IN : in STD_LOGIC OP_CODE : in STD_LOGIC_VECTOR(3 downto 0); CLK : in STD_LOGIC ALU_EN : in STD_LOGIC ALU OUT : out STD_LOGIC_VECTOR(3 downto 0)); End component; Component COMP Port (COMP_EN : in STD_LOGIC; CLK : in STD_LOGIC EXPECTED: in STD_LOGIC_VECTOR(3 downto 0); ALU_OUT : in STD LOGIC_VECTOR(3 downto 0); RESULT: out STD_LOGIC); End component; Signal DATA_FRAME_SIG : MY RECORD; Signal ADDR_SIG : STD LOGIC VECTOR(4 downto 0); Signal MEM_EN_SIG, ALU_EN_SIG, COMP_EN_SIG, C_IN_SIG : std logic; Signal A-IN_SIG, B_IN_SIG, OP_CODE_SIG, EXP_OUT_SIG, ALU_OUT_SIG; STD_LOGIC_VECTOR(3 downto 0); Begin U1 : MEM port map (CLK=>CLK.ADDR=>ADDR_SIG.READ_EN=>MEM_EN_SIG.DATA_FRA ME=>DATA_FRAME_SIG): U2 : CNTRL_FSM port map (DATA_FRAME=>DATA_FRAME_SIG,CLK=>CLK,RESET=>RESET, MEM_EN=>MEM_EN_SIG, ADDR=>ADDR_SIG,ALU_EN=>ALU_SIG,A_IN=>A_IN_SIG, B_IN=>B_IN_SIG,OP_CODE=>OP_CODE_SIG. C_IN=>C_IN_SIG,COMP_EN=>COMP_EN_SIG,EXP=>EXP_OUT_SIG); U3 : ALU port map (A=>A_IN_SIG,B=>B_IN_SIG,CLK=>CLK,EXPECTED=>EXP_OUT_SIG,ALU_OUT=>ALU_OUT_SIG, RESULT=>RESULT); End Structural; LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.ALL; ENTITY MY_CALC_TB_vhd IS END MY_CALC_TB_vhd; ARCHITECTURE test OF MY_CALC_TB_vhd IS COMPONENT MY_CALC PORT( CLK_IN : IN std_logic; RESET :IN std_logic; RESULT_OUT : OUT std_logic ); END COMPONENT; --Input SIGNAL CLK : std_logic : = '0'; SIGNAL RESET_TB : std_logic = '0'; -- Output SIGNAL RESULT: std_logic; BEGIN -- Instantiate tk Unit Under Test (UM) Uut: MY_CALC PORT MAP( CLK_IN=>CLK_TB, RESET=>RESET_TB RESULT_OUT=>RESULT ); CLK_TB <= not CLK_TB after lOns; RESET_TB <= T after 15ns, '0' after 25ns, T after 700ns, β0β after 725 ns, End architecture TEST; USE ieee.std_lOgic_1164.ALL; USE ieee.std_lOgic_unsigned.all; USE ieee.numeric_std.ALL; ENTITY ALU_TB_VHD IS END ALU_TB_VHD; Architecture behavior OF ALU_TB_vhd IS -- Component Declaration for the Unit Unver Test (UM) COMPONENT ALU PORT( A: IN std_logic_vector(3 downto 0); B: IN std_logic_vector(3 downto 0); C_IN : IN std_logic; OP_CODE : IN std_logic_vector(3 downto 0); CLK: IN std_logic; ALU_EN : IN std_logic; ALU_OUT : OUT std_logic_vector(3 downto 0); ); END COMPONENT; SIGNAL C_IN : std_logic : = β0'; -- nput signals SIGNAL CLK : std_logic : = '0'; SIGNAL ALU_EN: std_logic : = '1'; SIGNAL A : std_logic_vector(3 downto 0) : = "0111"; SIGNAL B : std_logic_vector(3 downto 0) : = "0011"; SIGNAL OP_CODE : std_logic_vector(3 downto 0) : = (others=>'0'); SIGNAL alu_out : std_logic_vector(3 downto 0); BEGIN -- Instantiate the Unit Under Test (UUT) Uut: ALU PORT MAP( A => A B => B, C_IN => C_IN, OP_CODE => OP_CODE, CLK => CLK, ALU_EN => ALU_EN, ALU_OUT => ALU_OUT CLK <= not CLK after 5ns; Test_proc : PROCESS BEGIN OP_CODE (3 downto 0) <= "0000"; --Ix a C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0001"; --txa . C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0001"; --inc C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0001"; --inc . C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0010"; --add C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0010"; --add C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0011"; --adde C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0011"; --adde C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0100"; --sub C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0100"; --sub C_IN <= ' 1 '; wait for 20ns: OP_CODE (3 downto 0) <= "0101"; --comp C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0101"; --comp C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0110"; --neg C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0110"; --neg C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "0111"; --dec C_IN <= '0'; wait for 20ns; OP_CODE (3 downto 0) <= "0111"; --dec C_IN <= '1'; wait for 20ns; OP_CODE (3 downto 0) <= "1000"; --txb C_IN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= β1000β; --txb C_IN <= β1β; wait for 20ns; OP_CODE (3 downto 0) <= β1001β; --and C_IN <= '0'; wail for 20ns; OP_CODE (3 downto 0) <= β1001β; --and C_IN <= β1β; wait for 20ns; OP_CODE (3 downto 0) <= β1010β; --or' C_lN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= β1010β; --or C_lN <= β1β; wait for 20ns; OP_CODE (3 downto 0) <= "1011"; --X01β C_IN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= "1011"; --X01β C_lN <= βl'; wait for 20ns; OP_CODE (3 downto 0) <= β1100β; --sl C_IN <= β0β; wait for 20ns; OP_CODE (3 dowNTo 0) <= β1100β; --sl C_IN <= β1β; wait for 20ns; OP_CODE (3 downto 0) <= β1101β; --sr C_IN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= β1101β; --sr C_IN <= β1β; wait for 20ns; OP_CODE (3 downto 0) <= β1110β; --par C_IN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= β1111β; --um C_lN <= β0β; wait for 20ns; OP_CODE (3 downto 0) <= β1111β; --zero C_lN <= β1'; wait for 20ns; wait; EnD PROCESS tes_proc; END; library IEEE; --Library Declaration use IEEE.STD_LOGIC_1164.ALL; --Packed Declaration use IEEE.STD_LOGIC_ARITH.ALL; --Packed operation and function use IEEE.STD_LOGIC_UNSIGNED.ALL; --Packagesstd_logic_vector use work. MY_CALC_PAK.ALL; Entity MEM_TB is -- Primary design unit MEM End MEM_TB; -- Close entity declaration Architecture test of MEM_TB is -- Secondary design unit Component MEM Port (CLK : in STD_LOGIC; ADDR : in STD_LOGIC_VECTOR (4 downto 0); --Port declaration READ_EN : in STD_LOGIC; DATA_FRAME: out MY_RECORD); End component; Signal CLK; std_logic ;='0' Signal ADDE_SIG : std_logic_vector (4 downto 0) = "0000"; --local signals Signal READ_EN_SIG :std_logic ;= '1'; Signal DATA_FRAME_SIG : MY_RECORD; Begin -- Begin Architecture Uut: MEM port map (CLK => CLK, ADDR => ADDR_SIG, -- unit under testing for testing READ_EN => READ_EN_SIG, DATA_FRAME =>DATA_FRAME_SIG); CLK <= not CLK after lOns; Process Begin --Begin the process ADDR_SIG <= "00000"; wait for 100ns; ADDR_SIG <= "00001"; wait for 100ns; ADDR_SIG <= "00010"; wait for 100ns; ADDR_SIG <= "00100"; wait for 100ns; ADDR_SIG <= "00101"; wait for 100ns; ADDR_SIG <= "00110"; wait for 100ns; ADDR_SIG <= "00111"; wait for 100ns; ADDR_SIG <= "01000"; wait for 100ns; ADDR_SIG <= "01001'; wait for 100ns; ADDR_SIG <= "01010"; wait for 100ns; --Statements operate sequentially ADDR_SIG <= "01011"; wait for 100ns; ADDR_SIG <= "01100"; wait for 100ns; ADDR_SIG <= "01101"; wait for 100ns; ADDR_SIG <= "01110"; wait for 100ns; ADDR_SIG c= "01111"; wait for 100ns; ADDR_SIG <= "10000"; wait for 100ns; ADDR_SIG <= "10001"; wait for 100ns; ADDR_SIG <= "10010"; wait for 100ns; ADDR_SIG <= "10011"; wait for 100ns; ADDR_SIG <= "10100"; wait for 100ns; ADDR_SIG <= "10101"; wait for 100ns; ADDR_SIG <= "10110"; wait for 100ns; ADDR_SIG <= "10111"; wait for 100ns; ADDR_SIG <= "11000"; wait for 100ns; ADDR_SIG <= "11001"; wait for 100ns; ADDR_SIG <= "11010"; wait for 100ns; ADDR_SIG <= β11011"; wait for l00ns; ADDR_SIG <= βl1100"; wait for l00ns; ADDR_SIG <= βl1101"; wait for l00ns; ADDR_SIG <= β11110"; wait for 100n5; ADDR_SIG <= β11111"; wait for 100n5; Wait; End process; -- End pmoess End architecture test; -- End the body amhiecnue (0 => (OP_CODE=>β0000",A_IN =>β0111",B_IN=>β0011β,c_in=>β0β,EXP_OUT=>"0111"), --txa l => (OP_CODE=>β0000β,A_IN =>β0111β,B_IN=>β0011β,c_in=>β0β,EXP_0UT=>β0111β), --tn 2 => (OP_CODE=>β0001β,A_IN=>β0111β,B_IN=>β0011β,c_in=>β0β,EXP_OUT=>β1000"), --inc 3 => (OP_CODE=>β000lβ,A_IN=>β0111β,B_IN=>β0011β,c_in=>β0β,EXP_OUT=>β1000β), --inc 4 => (OP_CODE=>β00l0β,A_IN=>β0111",B_IN=>β0011β,c_in=>β0β,EXP_0UT=>β1010β), --add 5 => (OP_CODE.=>β00l0",A_IN=>β0111β,B_IN=>β0011β,c_in=>β0',EXP_0UT=>βl0l0"), --add 6 => (OP_CODE=>β001lβ,A_IN=>β0111",B_IN=>β0011",c_in=>β0',EXP_0UT=>"l010β), --addc 7 => (OP_CODE=>"0011β,A_IN=>β0111β,B_IN=>β0011β,c_in=>β0β,EXP_0UT=>"1011β), --addc 8 => (OP_CODE=>"0100β,A_IN=>β0111",B_IN=>β0011β, c_in=>β0β,EXP_0UT=>"0100β), --sub 9 => (OP_CODE.=>β0100β,A_IN=>β0111",B_IN=>"0011β, c_in=>β0β,EXP_0UT=>"0100β), --sub 10 => (OP_CODE=>"0101β,A_IN=>β0111",B_IN=>β0011β, c_in=>β0β,EXP_0UT=>"1000β), --Comp 11 => (OP_CODE=>"0111",A_IN=>β0111β,B_IN=>β0011β, c_in=>β0β,EXP_0UT=>"1000β), --Comp 12 => (OP_CODE=>β0110β,A_IN=>β0111",B_IN=>β0011", c_in=>β0β,EXP_0UT=>"1001β), --neg 13 => (OP_CODE=>β0110β,A_IN=>β0111",B_IN=>β0011β, c_in=>β0β,EXP_0UT=>"1001β), --neg 14 => (OP_CODE=>β0111β,A_IN=>β0111",B_IN=>"0011", c_in=>β0β,EXP_0UT=>"0110β), --dec 15 => (OP_CODE=>β0111β,A_IN=>β0111",B_IN=>β0011β, c_in=>β0β,EXP_0UT=>"0110β), --dec 16 => (OP_CODE=>β1000β,A_IN=>β0111",B_IN=>"0011", c_in=>β0β,EXP_0UT=>"0011β), --txb 17 => (OP_CODE=>"1000β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0011β), --txb 18 => (OP_CODE=>"1001β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0011β), --and I9 => (OP_CODE=>"1001β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0011β), --and 20 => (OP_CODE=>"1010β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0111β), --or 21 => (OP_CODE=>"1010β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0111β), --or 22 =:> (OP_CODE=>"1011β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0100β), --xor 23 => (OP_CODE=>"1011β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0100β), --xor 24 => (OP_CODE=>"1100β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"1110β), --sl 25 => (OP_CODE=>"1100β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"1110β), --sl 26 => (OP_CODE=>"0011β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0011β), --sr 27 => (OP_CODE=>"1101β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0011β), --sr 28 => (OP_CODE=>"1110β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0001β), --Par 29 => (OP_CODE=>"1110β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UT=>"0000β), --Par 30 => (OP_CODE=>"1111β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UI'=>"0000β), --zero 31 => (OP_CODE=>"1111β,A_IN=>β0111β,B_IN=>β0011",c_in=>β0β,EXP_0UI'=>"0000β), --zero
Code VHDL - [expand] 1 2 3 Library IEEE; Use IEEE.STD_CALC_PAK is Package MY_CALC_PAK is
vcom -work work -2002 -explicit {C:/Modeltech_pe_edu_10.2c/examples/assignment vhdl.vhd}
Model Technology ModelSim PE Student Edition vcom 10.2c Compiler 2013.07 Jul 18 2013
-- Loading package STANDARD
** Error: C:/Modeltech_pe_edu_10.2c/examples/assignment vhdl.vhd(1): near "MY_CALC_PACKAGE": syntax error
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?