Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Homemade TestBench attmept

Hola All,

I recently made a vhd file from scratch that tested some simple logic circuits successfully. All I have had as resources in this task is the tutorial files from ModelSim (counter.vhd, and tcounter.vhd), and a single text on vhdl (Circuit Design with VHDL by Peroni). Things were looking good until I attempted to make and test a frequency divider.

http://sphotos.ak.fbcdn.net/hphotos-ak-snc4/hs148.snc4/36780_10150214314760055_754135054_13023800_1551964_n.jpg

This frequency divider has one input (clk) and two outputs (out1, and out2). The code for this divider is below as well as the testbench I made for it. The problem is I get an undefined signal coming out of both my outputs. Any explanation as to why would be much appreciated.

Thanks for the assist,

Triston

****************************Freq Divider code*******************************

Library ieee;

Use ieee.std_logic_1164.all;

------------------------------------>

Entity Freq_Div_1 is

Generic(n : integer := 4);

Port(

clk : IN std_logic;

out1,out2 : buffer std_logic

);

End Freq_Div_1;

------------------------------------>

Architecture Div of Freq_Div_1 is

Signal count1 : Integer Range 0 to 7;

Begin

Process (clk)

Variable count2 : integer range 0 to 7;

Begin

if (clk'EVENT and clk='1') then

count1 <= count1 + 1;

count2 := count2 + 1;

if ( count1 = n) then

out1 <= not out1;

count1 <= 0;

end if;

if(count2 = 2) then

out2 <= not out2;

count2 := 0;

end if;

end if;

End Process;

End Div;

*************************** My TestBench Debacle *************************

Library ieee;

Use ieee.std_logic_1164.all;

------------------------------------->

Entity tFreq_Div_1 is

Port(

out1,out2 : buffer std_logic

);

End tFreq_Div_1;

------------------------------------->

Architecture testBench of tFreq_Div_1 is

-- ******** Component ******** ----->

Component Freq_Div_1

Port(

clk : in std_logic;

out1,out2 : buffer std_logic

);

End Component Freq_Div_1;

--**** Test Signals ******* -------->

Signal clk : std_logic :='0';

------------------------------------->

Begin

dut:Freq_Div_1

Port MAP

(

clk => clk,

out1 => out1,

out2 => out2

);

clk_In : Process

Begin

wait for 10 ns; clk <= not clk;

End Process clk_In;

intialize : process

begin

wait for 1 ns; out1 <= '0';

wait for 1 ns; out2 <='0';

wait;

End process intialize;

End testBench;

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The alternative is this:

    declare out1_int and out2_int as signals. do your read/drive then wire up out1 port to out1_int...

    You now can see what buffer is doing, it is meant to bypass the double work but causes confusion since it is meant to be output only (not input) but that can be read internally ???

    Future vhdl is meant to allow reading output ports without declaring them as buffer.

    --- Quote End ---

    I'm waiting for that new VHDL standard. It's just silly to not be able to read the output port, I think. But I still don't get why you should not use the buffer syntax? Except for the "tradition" for not using it, why is it not used by experienced?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I'm waiting for that new VHDL standard. It's just silly to not be able to read the output port, I think. But I still don't get why you should not use the buffer syntax? Except for the "tradition" for not using it, why is it not used by experienced?

    --- Quote End ---

    Be prepared to wait a while. Vendors can be really slow at adding new standards to products. I know altera have started to support 2008, but only parts of it, and mentor hardly support any of it yet (which means being safely able to write 2008 compliant code isnt going to happen for a while).

    As for the out port question - I think you're looking at it from the wrong angle. VHDL does not have formal "parts" like register, tri-state buffers, multipliers etc. It is all implied using behavioural code. Therefore an out port is simply that - an output. It is the process that actually implements the register.

    I think thats why buffer is hardly used - it doesnt really fit in with the rest of the language.