Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   VHDL (http://www.velocityreviews.com/forums/f18-vhdl.html)
-   -   How to write testbench file? (http://www.velocityreviews.com/forums/t713002-how-to-write-testbench-file.html)

RaulGonz 01-27-2010 06:18 AM

How to write testbench file?
 
Hi, i am using an actel fpga to generate pwm signal. There are these
IP cores in the libero software for you to drage and drop into your
design. I have the following .vhd code and is having a hard time
trying to write the testbench for it..

"library ieee;
use ieee.std_logic_1164.all;

entity FSM_CorePWM is
GENERIC (PWM_NUM : integer := 1);
port (PCLK, PRESET_N, PSEL, PENABLE, PWRITE: in std_logic;
DUTY_CYC: in std_logic_vector (2 downto 0);
PWM: out std_logic_vector (PWM_NUM downto 1);
PRDATA: out std_logic_vector (7 downto 0);
INT: out std_logic);
end entity FSM_CorePWM;

architecture HIERARCHICAL of FSM_CorePWM is
component FSM
port (PCLK, PRESET_N: in std_logic;
DUTY_CYC: in std_logic_vector (2 downto 0);
PADDR: out std_logic_vector (7 downto 0);
PWDATA: out std_logic_vector (7 downto 0));
end component;
component core_pwm
GENERIC (PWM_NUM : integer := 8);
port (PCLK, PRESET_N, PSEL, PENABLE,
PWRITE: in std_logic;
PADDR: in std_logic_vector(7
downto 0);
PWDATA: in std_logic_vector(7
downto 0);
PWM: out std_logic_vector
(PWM_NUM downto 1);
PRDATA: out std_logic_vector(7
downto 0);
INT: out std_logic);
end component;
signal PADDR_TOP: std_logic_vector(7 downto 0);
signal PWDATA_TOP: std_logic_vector(7 downto 0);
begin
FSM_TOP: FSM port map
(PCLK=>PCLK,PRESET_N=>PRESET_N,DUTY_CYC=>DUTY_CYC, PADDR=>PADDR_TOP,PWDATA=>PWDATA_TOP);
COREPWM_TOP: core_pwm
GENERIC MAP (PWM_NUM =>PWM_NUM)
port map
(PCLK=>PCLK,PRESET_N=>PRESET_N,PSEL=>PSEL,PENABLE= >PENABLE,PWRITE=>PWRITE,
PADDR=>PADDR_TOP,PWDATA=>PWDATA_TOP,PWM=>PWM,PRDAT A=>PRDATA,INT=>INT);
end HIERARCHICAL; "

In the above, component "FSM" is another .vhd code while component
"core_pwm" is the IP core. please help to guide me how to generate the
testbench/stimulus for this.

Andy 01-27-2010 05:02 PM

Re: How to write testbench file?
 
Instantiate your unit under test (fsm_corepwm in this case) in a test
bench entity/architecture. Write processes, procedures, etc. in the
architecture as required to drive the UUT inputs to excercise the UUT
(i.e. give the UUT data to work on, command it to do specific
operations, etc.)

Now you have two options. For simple UUTs you can simply gather up all
the UUT inputs and outputs in a waveform viewer and manually determine
whether or not it is working as you expected.

Or you can write more processes, procedures, etc. to examine the UUT
inputs and outputs, to determine if they are functioning as expected.
This is called a self checking test bench. This method is more work to
create, but is easier to use, especially by someone else who may not
be as familiar with your design as you are (that someone else could be
yourself after you've left the project for a while). Sometimes the
verification uses a separate reference model of what the UUT is
supposed to do, and the outputs of the UUT and reference model are
compared to determine whether the UUT works. Remember, this reference
model does not need to be synthesizable, so you can use lots of tricks
in vhdl that are not available in synthesis, like waiting on arbitrary
signals, inserting time delays, etc. Also, your checking code can use
assertion statements to report failures (easy), or you can log
failures to a separate text file for later review (harder, but can be
more elaborate). I usually write self checking testbenches with
assertion statements to report failures, and it works well for me.

Hope this helps,

Andy

RaulGonz 01-28-2010 06:26 AM

Re: How to write testbench file?
 
hi Andy,

i wrote the following testbench for "fsm_pwmcore.vhd"

"library ieee;
use ieee.std_logic_1164.all;

entity TB_FSM is
end TB_FSM;

architecture behv of TB_FSM is

component FSM_CorePWM is
GENERIC (PWM_NUM : integer := 8);
port (PCLK, PRESET_N, PSEL, PENABLE, PWRITE: in std_logic;
DUTY_CYC: in std_logic_vector (2 downto 0);
PWM: out std_logic_vector (8 downto 1);
PRDATA: out std_logic_vector (8 downto 1);
INT: out std_logic);
end component;

signal TB_PCLK: std_logic;
signal TB_PRESET_N: std_logic;
signal TB_PSEL: std_logic;
signal TB_PENABLE: std_logic;
signal TB_PWRITE: std_logic;
signal TB_DUTY_CYC: std_logic_vector (2 downto 0);
signal TB_PWM: std_logic_vector (8 downto 1);
signal TB_PRDATA: std_logic_vector (8 downto 1);
signal TB_INT: std_logic;

begin

unit: FSM_CorePWM --GENERIC map (PWM_NUM)
port map (TB_PCLK, TB_PRESET_N, TB_PSEL, TB_PENABLE, TB_PWRITE,
TB_DUTY_CYC, TB_PWM, TB_PRDATA, TB_INT);

process
begin

TB_PSEL <= '1';
TB_PENABLE <= '1';
TB_PWRITE <= '1';
TB_PCLK <= '0';
wait for 5 ns;
TB_PCLK <= '1';
wait for 5 ns;

end process;
end behv; "

now the problem is this fsm_pwmcore consist of two components which
are the corepwm and fsm. How can i like this fsm_pwmcore to the two
components in testbench format?? Please advise. Thank you.


RaulGonz 01-28-2010 06:29 AM

Re: How to write testbench file?
 
Sorry, i mean how can i ADD this fsm_pwmcore to the two
components in testbench format?? Please advise. Thank you.

Andy 01-28-2010 04:55 PM

Re: How to write testbench file?
 
On Jan 28, 12:29*am, RaulGonz <raull...@hotmail.com> wrote:
> Sorry, i mean how can i ADD this fsm_pwmcore to the two
> components in testbench format?? Please advise. Thank you.


I'm not sure I understand your question, but when you instantiate the
FSM_CorePWM in your testbench, that brings in the lower two modules
instantiated within it. You are testing both of those modules together
within FSM_CorePWM, through the FSM_CorePWM external interface.

BTW, you can avoid component declarations, configurations, default
binding, etc. by directly instantiating the entity (and optionally
specifying the architecture):

unit: entity work.FSM_CorePWM(HIERARCHICAL) --GENERIC map (PWM_NUM)
port map (TB_PCLK, TB_PRESET_N, TB_PSEL,
TB_PENABLE, TB_PWRITE,
TB_DUTY_CYC, TB_PWM, TB_PRDATA, TB_INT);

You can do this for any entity/architecture for which you have the
source code. You cannot do this for primitives, or cores for which you
do not have vhdl source. For instance, if you do not have the vhdl
source for the FSM and core_pwm modules, you must use component
declarations and instantiations like you have done.

Andy

RaulGonz 01-29-2010 01:38 AM

Re: How to write testbench file?
 
Hi Andy, you are correct. FSM_CorePWM is my top level design file and
it calls on two lower modules instantiated with it. Now, do i have to
create a testbench for each of the two lower modules in order to
simulate the design as a whole?

This is because in the actel libero IDE software project manager, i
was told that i can set FSM_CorePWM as the root and the modelsim
simulation can actually be initiated from the libero project manager.
That brings me to my question... do i have to write individual
testbench for the two lower modules and then link them up to the top
level design file (FSM_CorePWM) before i initiated modelsim from
libero?

Or from what i understand from your reply, i can just write what i
want to do with what components/entity (be it the FSM_CorePWM, FSM or
the corePWM IP) in just a single testbench file?

Please advise. Thank you so much..

Andy wrote:
> On Jan 28, 12:29*am, RaulGonz <raull...@hotmail.com> wrote:
> > Sorry, i mean how can i ADD this fsm_pwmcore to the two
> > components in testbench format?? Please advise. Thank you.

>
> I'm not sure I understand your question, but when you instantiate the
> FSM_CorePWM in your testbench, that brings in the lower two modules
> instantiated within it. You are testing both of those modules together
> within FSM_CorePWM, through the FSM_CorePWM external interface.
>
> BTW, you can avoid component declarations, configurations, default
> binding, etc. by directly instantiating the entity (and optionally
> specifying the architecture):
>
> unit: entity work.FSM_CorePWM(HIERARCHICAL) --GENERIC map (PWM_NUM)
> port map (TB_PCLK, TB_PRESET_N, TB_PSEL,
> TB_PENABLE, TB_PWRITE,
> TB_DUTY_CYC, TB_PWM, TB_PRDATA, TB_INT);
>
> You can do this for any entity/architecture for which you have the
> source code. You cannot do this for primitives, or cores for which you
> do not have vhdl source. For instance, if you do not have the vhdl
> source for the FSM and core_pwm modules, you must use component
> declarations and instantiations like you have done.
>
> Andy


KJ 01-29-2010 03:27 AM

Re: How to write testbench file?
 
On Jan 28, 8:38*pm, RaulGonz <raull...@hotmail.com> wrote:
> Now, do i have to
> create a testbench for each of the two lower modules in order to
> simulate the design as a whole?


No.

KJ

KJ 01-29-2010 03:43 AM

Re: How to write testbench file?
 
> I usually write self checking testbenches with
> assertion statements to report failures, and it works well for me.
>


Another approach is to write a self checking design. All of that non-
synthesizable stuff can be included right in the architecture with the
design itself...safely surrounded by
-- synthesis translate_off
-- synthesis translate_on

Then the testbench itself only generate stimulus. The nice thing here
is that if you make a change to a widget but don't run the testbench
for widget, jumping right to the top level testbench instead you've
still got the same checking code running for you in that environment.

Alternatively, you can view this as checking code for the widget
regardless of the test environment since it will always run. When you
can do this, you've probably got a more robust checker since it is
will not be dependent on any anomolies, coverage holes or other corner
cutting that might be implicitly there in the traditional testbench
approach that generates stimulus and verifies response.

Testing in more environments is always better from a design
verification standpoint, putting the checking logic right in the
design allows you to test in any environment that the widget will ever
get used.

KJ

RaulGonz 01-29-2010 06:02 AM

Re: How to write testbench file?
 
hi KJ,

Do u mean that i can just create a testbench and then include whatever
components/signals, in the two lower modules, to this sole testbench?

KJ wrote:
> On Jan 28, 8:38*pm, RaulGonz <raull...@hotmail.com> wrote:
> > Now, do i have to
> > create a testbench for each of the two lower modules in order to
> > simulate the design as a whole?

>
> No.
>
> KJ


Mike Treseler 01-29-2010 07:07 PM

Re: How to write testbench file?
 
KJ wrote:

> Another approach is to write a self checking design. All of that non-
> synthesizable stuff can be included right in the architecture with the
> design itself...safely surrounded by
> -- synthesis translate_off
> -- synthesis translate_on


I can even include simulation libraries in
my synthesis code the same way.
This is also a quick way to add some visibility
for debugging a variable deep in the design.

-- Mike Treseler


All times are GMT. The time now is 10:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.