EmbDev.net

Forum: FPGA, VHDL & Verilog Writing Testbench for Bidirectional/Inout Port


von Ahmed A. (Company: None) (newbiespartan)


Rate this post
useful
not useful
Hello! I have to write a testbench for I2C. I have an inout SDA port, 
which I drive to either zero or high impedance state in the module.I 
want to make sure that on the 9th clock cycle, when the SDA port is 
driven to a high impedance state for the slave to issue an acknowledge, 
the test bench drives the port low, indicating successful 
acknowledgement by the slave. Currently, I know when I want to drive the 
port low, this cycle is marked by an IO signal in simulation which goes 
high on the 9th clock cycle.

The function should be something like this :

//reg IO; //IO is controlled in the testbench, not exported from module.
 if (IO)  SDA = 1'b0;
 else     SDA = SDA;
///

The following approach did not work.

 assign SDA = IO? 1'b0 : SDA;

: Edited by User
von Vancouver (Guest)


Rate this post
useful
not useful
The problem may be that you never set SDA = 1'bZ when IO===0. So your 
SDA signal is always driven by the test bench. ( I am not sure if 1'bZ 
is the correct notation for high impedance in Verilog, you have to look 
up)

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Ahmed A. wrote:
> which I drive to either zero or high impedance
You don't. Instead you built a latch...
http://electronics.stackexchange.com/questions/219776/what-exactly-does-a-high-impedance-imply-in-verilog

: Edited by Moderator
von Ahmed A. (Company: None) (newbiespartan)


Rate this post
useful
not useful
assign SDA = IO? 1'b0 : 1'bz;

This works.
Thank you!

: Edited by User
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.