Altera_Forum
Honored Contributor
14 years agoTrying to constrain I2C interface
I am designing an I2C serial interface, but I'm running into confusion setting up the timing constraints for it.
module Test
(
input wire scl_in,
input wire sda_in,
output reg sda_out
);
reg start_det;
reg stop_det;
reg sreg;
always @(negedge sda_in)
start_det <= scl_in;
always @(posedge sda_in)
stop_det <= scl_in;
always @(posedge scl_in)
sreg <= { sreg, sda_in };
always @(negedge scl_in)
sda_out <= (sreg == 8'hA5);
endmodule
The basic period is 1uS, and in general SDA will transition near the middle of the SCL low time. The only time this isn't true is when SDA is driven low at the falling edge of SCL create_clock -name "scl" -period 1000.000ns -waveform {0.000 500.000}
create_clock -name "sda" -period 1000.000ns -waveform {250.000 750.000}
For a repeated start condition, SCL is high a minimum of 260nS before the falling edge of SDA. (Tsu;sta) For a start condition, SCL is held high at least 260nS after the falling edge of SDA. (Thd;sta) For a stop condition, SCL is high a minimum of 260nS before the rising edge of SDA. (Tsu;sto)
set_input_delay -clock "sda" -max 740ns
set_input_delay -clock "sda" -max 740ns -clock_fall
set_input_delay -clock "sda" -min 260.000ns -clock_fall
For data input, SDA must be valid 50nS before the rising edge of SCL (Tsu;dat) and held for 0nS after the falling edge of SCL.
set_input_delay -clock "scl" -max 950ns
set_input_delay -clock "scl" -max 550ns -clock_fall
So, does this look right? Also, (at the risk of tldr) the second attachment (tsu.jpg) shows th measured from the rising edge of the clock, but tsu measured back from the Falling edge of the clock. Shouldn't both of them be measured from the same clock edge? Thanks