Inout question in testbench

Status
Not open for further replies.

faust861

Newbie level 6
Joined
Jun 23, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Italy
Activity points
1,406
Hi to all
after doing a certain number of exercizes, about a PWM and an Encoder, I'm doing the first example of a simple PLD. In this example, I use two bus from a DSP: an address bus, and a data bus.
The address bus permits, thanks to 2 encoders, to tell the PLD what functionality or module to be active.
The data bus gives and receives data to and from this modules.

The problem I can't solve is this. The data bus has to be bidirectional, so inout type.
My aim is this: when write signals for PWM arrive, this bus has to be read, while when read signal for Encoder arrives the bus has to be write.
This is the code I have written:

Code:
             dat_A <= dat_dsp(13 downto 0) when wr_pwmA = '1' else dat_dsp_reg(13 downto 0);
	dat_B <= dat_dsp(13 downto 0) when wr_pwmB = '1' else dat_dsp_reg(13 downto 0);
	dat_C <= dat_dsp(13 downto 0) when wr_pwmC = '1' else dat_dsp_reg(13 downto 0);
	dat_rit <= dat_dsp(14 downto 0) when rit_pwm = '1' else dat_dsp_reg(14 downto 0);
	
	uscita_bus_dati : process(rd_enc1,rd_enc2)
	begin
		if rd_enc1 = '1' then
			dat_dsp <= 	out_enc1;
		elsif rd_enc2 = '1' then
			dat_dsp <= out_enc2;
		else
			dat_dsp <= (others => 'Z');
		end if;
	end process;

where:
- dat_A, dat_B and so on are data to be given to the PWM
- wr_pwmA and so on are abilitation write signals
- rd_enc1 and rd_enc2 are abilitation read signals
- dat_dsp is the bidirectional port
The first part is about dat_dsp used as input, the second as output.

After this, I tried a testbench. I wanted to simulate this behaviour:
I send on dat_dsp the input for PWM, after I enable the Encoder and, after a certain time, I want to read it, so sending the reading on dat_dsp.
I wrote this:

Code:
dato_PWM : process
	begin
		tdat_dsp <= "00000000000000000000001110000100";
		wait;
end process;

where I force dat_dsp (tdat_dsp is the name in the testbench) at this value at the beginning to make work PWM.
Now the problem is that i think that it works, but Modelsim thinks that I force dat_dsp on this values as I would do with an output so I would see errors in the functionality of the circuit.
So, when it would have to write on data bus, the result is a vector where there are some X for the bits of the encoder exit different from the value I have forced at the beginning!

Is there any other mode, maybe righter, to tell a testbench that I want only to use that value as a signal, instead of force it for all the simulation time?

Thanks and sorry for the very long question
 

after tb forces the value, the tb can release by tdap_dsp <= (OTHERS=>'z');

to symplify your code, you can also used the x to define value in hexa instead binary format.

the only issue is for vector not multiple of 4.

example:
a define as 9 bit vector.

a<= "101101001";
or
a<= '1'&x"69";
 

thanks for the advice

it works, but I have another question on the issue.
I wrote this:

Code:
dato_PWM : process
	begin
		tdat_dsp <= "00000000000000000000001000000000";
		wait for (50 ns);
		tdat_dsp <= "00000000000000000000001110000100";
		wait for (200 ns);
		tdat_dsp <= (others => 'Z');
		wait;
end process;

So, after time 250 ns, modelsim thinks that it's like tdata_dsp is forced to Z. So, when I enable the writing on the bus it writes, but when I remove the enable, tdat_dsp returns Z...
so it's like tdata_dsp is always a input, except when I enable the write...
I would like that when I enable the write, tdata_dsp changes its status to an output, until it will return an input (if this happens).

Anyway, my doubt is: is this a problem of the testbench, or I will see a similar behaviour even in real?

thank you
 

eh, sorry I did not follow you, in your text, i didn't know whose drives or not.. or wante to drive the tdat_dsp or tdata_dsp ?
 

sorry, maybe I wasn't so clear
where I wrote tdata_dsp I mistaked...I wanted to say tdat_dsp

the aim is this:
I want to simulate how a PWM and an Encoder work.
In the case of PWM, on the data bus (tdat_dsp) arrives a data that tells the PWM what velocity it must have. So, in that case tdat_bus is an input.
After this exigency, the data bus goes to Z state.
This is what the part of testbench that I wrote does. (don't worry for the fact that there are 2 inputs, it's a need of my own pwm).

Then, the Encoder starts to work (with a enable signal) and, when a read signal arrive, he wants to write on the data bus its data. So, in that case tdata_bus would be an output.

But after the during of the read signal, the encoder's data is no longer on the bus, that returns to Z.
Yesterday I asked how to take this data forever, or until a new data or a change or direction (for the pin to transform another time in a input, for example), like the bus would be an output.

But this morning, talking with a collegue, he said me that this is reasonable, because the data bus must be ready for a new data (of input or output) and until that event it must be in Z state.
So, when used like an output, it must be read during the time of read signal.

thank you for the attention :wink:
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…