Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

I find you lack of faith in the forth dithturbing. -- Darse ("Darth") Vader


devel / comp.lang.verilog / Re: How can I stop the simualtion at stop bit for i2c master verilog code?

SubjectAuthor
* How can I stop the simualtion at stop bit for i2c master verilog code?Qazi Zabeer
`- How can I stop the simualtion at stop bit for i2c master verilogCharlie

1
How can I stop the simualtion at stop bit for i2c master verilog code?

<e32f1a58-0da8-42f4-9d7f-d1db9dd31e23n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1&group=comp.lang.verilog#1

  copy link   Newsgroups: comp.lang.verilog
X-Received: by 2002:a0c:d84f:0:b0:5ef:4436:ef38 with SMTP id i15-20020a0cd84f000000b005ef4436ef38mr985253qvj.4.1686003310959;
Mon, 05 Jun 2023 15:15:10 -0700 (PDT)
X-Received: by 2002:a05:622a:1ba0:b0:3f6:b052:3431 with SMTP id
bp32-20020a05622a1ba000b003f6b0523431mr40767qtb.5.1686003310748; Mon, 05 Jun
2023 15:15:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.verilog
Date: Mon, 5 Jun 2023 15:15:10 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=43.246.220.222; posting-account=JXkWXQoAAAAF88FPm34p89A0oMk3_Fsg
NNTP-Posting-Host: 43.246.220.222
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e32f1a58-0da8-42f4-9d7f-d1db9dd31e23n@googlegroups.com>
Subject: How can I stop the simualtion at stop bit for i2c master verilog code?
From: qzabeer@gmail.com (Qazi Zabeer)
Injection-Date: Mon, 05 Jun 2023 22:15:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 154
 by: Qazi Zabeer - Mon, 5 Jun 2023 22:15 UTC

I am trying to write Verilog code for I2C master and there are a couple of problems I am facing. I was able to compile and run its testbench on Quartus and modelsim, respectively.However, what I am trying to do is to have it swtich back to reset mode on(reset = 1) once the state reaches STATE_STOP(Basically have it stay in STATE_IDLE), so what can I add to either the code or the testbench to make it that way? The simulation continues after STATE_STOP, which I am not able to understand, and so I have to, at an arbitrary time, add either $finish or reset = 1 in the testbench. Here is the code:

`timescale 1ns/1ps

module I2C_Master(
input wire clk,
input wire reset,
input wire [7:0]data,
input wire [6:0]add,
input wire readorwrite,
output reg i2c_sda,
output reg i2c_scl
);

localparam STATE_IDLE = 0;
localparam STATE_START = 1;
localparam STATE_ADDR = 2;
localparam STATE_RW = 3;
localparam STATE_WACK = 4;
localparam STATE_DATA = 5;
localparam STATE_STOP = 6;
localparam STATE_WACK2 = 7;


reg [7:0] state;
reg [7:0] count;

always @(posedge clk) begin
if (reset == 1)
i2c_scl <= 1;
else begin
if (state == STATE_START)
i2c_scl <= 0;
else if (state == STATE_IDLE || state == STATE_STOP)
i2c_scl <= 1;
else
i2c_scl <= ~i2c_scl;
end
end

always @(posedge clk) begin
if (reset == 1) begin
state <= 0;
i2c_sda <= 1;
count <= 8'd0;
end
else begin
case(state)

STATE_IDLE: begin
i2c_sda <= 1;
state <= STATE_START;
end

STATE_START: begin
i2c_sda <= 0;
state <= STATE_ADDR;
count <= 6;
end

STATE_ADDR: begin
i2c_sda <= add[count];
if (count == 0) state <= STATE_RW;
else count <= count - 1;
end

STATE_RW: begin
i2c_sda <= readorwrite;
state <= STATE_WACK;
end

STATE_WACK: begin
i2c_sda <= 0;
state <= STATE_DATA;
count <= 7;
end

STATE_DATA: begin
i2c_sda <= data[count];
if (count == 0) state <= STATE_WACK;
else count <= count - 1;
end

STATE_WACK2: begin
i2c_sda <= readorwrite;
state <= STATE_STOP;
end

STATE_STOP: begin
i2c_sda <= 0;
end
endcase
end

end
endmodule
The testbench:

module I2C_MasterTB;

reg clk;
reg reset;
reg [7:0]data;
reg [6:0]add;
reg readorwrite;

wire i2c_sda;
wire i2c_scl;

I2C_Master uut (
.clk(clk),
.reset(reset),
.data(data),
.add(add),
.readorwrite(readorwrite),
.i2c_sda(i2c_sda),
.i2c_scl(i2c_scl)
);

initial begin
clk = 0;
forever begin
clk = #1 ~clk;
end
end

initial begin
reset = 1;
add <= 7'h50;
data <= 8'haa;
readorwrite <= 0;

#10;

reset = 0;

#100;

reset = 1;

end

endmodule
As I already mentioned, I only arbitrarly chose a time period to finish the simulation, but I cant seem to think of the way to the end the simulation as soon as it reaches the last state and have it stay in idle state.

Re: How can I stop the simualtion at stop bit for i2c master verilog code?

<u5lvui$g5qr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2&group=comp.lang.verilog#2

  copy link   Newsgroups: comp.lang.verilog
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: charlieDOTd@verEYEzon.net (Charlie)
Newsgroups: comp.lang.verilog
Subject: Re: How can I stop the simualtion at stop bit for i2c master verilog
code?
Date: Mon, 5 Jun 2023 20:51:26 -0400
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <u5lvui$g5qr$1@dont-email.me>
References: <e32f1a58-0da8-42f4-9d7f-d1db9dd31e23n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 6 Jun 2023 00:51:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="daa91e6c785ebbd6b7aba351e0c8c2cc";
logging-data="530267"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18R0QuceCNBrb/nuMcyrsbuqRixGsjVcRU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.2
Cancel-Lock: sha1:mmqgY0FdKESaFUlsP6SmLOOieJc=
Content-Language: en-US
In-Reply-To: <e32f1a58-0da8-42f4-9d7f-d1db9dd31e23n@googlegroups.com>
 by: Charlie - Tue, 6 Jun 2023 00:51 UTC

On 6/5/2023 6:15 PM, Qazi Zabeer wrote:
>
> I am trying to write Verilog code for I2C master and there are a couple of problems I am facing. I was able to compile and run its testbench on Quartus and modelsim, respectively.However, what I am trying to do is to have it swtich back to reset mode on(reset = 1) once the state reaches STATE_STOP(Basically have it stay in STATE_IDLE), so what can I add to either the code or the testbench to make it that way? The simulation continues after STATE_STOP, which I am not able to understand, and so I have to, at an arbitrary time, add either $finish or reset = 1 in the testbench. Here is the code:
>
> `timescale 1ns/1ps
>
> module I2C_Master(
> input wire clk,
> input wire reset,
> input wire [7:0]data,
> input wire [6:0]add,
> input wire readorwrite,
> output reg i2c_sda,
> output reg i2c_scl
> );
>
> localparam STATE_IDLE = 0;
> localparam STATE_START = 1;
> localparam STATE_ADDR = 2;
> localparam STATE_RW = 3;
> localparam STATE_WACK = 4;
> localparam STATE_DATA = 5;
> localparam STATE_STOP = 6;
> localparam STATE_WACK2 = 7;
>
>
> reg [7:0] state;
> reg [7:0] count;
>
> always @(posedge clk) begin
> if (reset == 1)
> i2c_scl <= 1;
> else begin
> if (state == STATE_START)
> i2c_scl <= 0;
> else if (state == STATE_IDLE || state == STATE_STOP)
> i2c_scl <= 1;
> else
> i2c_scl <= ~i2c_scl;
> end
> end
>
> always @(posedge clk) begin
> if (reset == 1) begin
> state <= 0;
> i2c_sda <= 1;
> count <= 8'd0;
> end
> else begin
> case(state)
>
> STATE_IDLE: begin
> i2c_sda <= 1;
> state <= STATE_START;
> end
>
> STATE_START: begin
> i2c_sda <= 0;
> state <= STATE_ADDR;
> count <= 6;
> end
>
> STATE_ADDR: begin
> i2c_sda <= add[count];
> if (count == 0) state <= STATE_RW;
> else count <= count - 1;
> end
>
> STATE_RW: begin
> i2c_sda <= readorwrite;
> state <= STATE_WACK;
> end
>
> STATE_WACK: begin
> i2c_sda <= 0;
> state <= STATE_DATA;
> count <= 7;
> end
>
> STATE_DATA: begin
> i2c_sda <= data[count];
> if (count == 0) state <= STATE_WACK;
> else count <= count - 1;
> end
>
> STATE_WACK2: begin
> i2c_sda <= readorwrite;
> state <= STATE_STOP;
> end
>
> STATE_STOP: begin
> i2c_sda <= 0;
> end
> endcase
> end
>
> end
> endmodule

It looks like your 'state machine' goes into a loop at STATE_DATA and
never gets to STATE_STOP.

STATE_DATA line now: if (count == 0) state <= STATE_WACK;

Probably should be: if (count == 0) state <= STATE_WACK2;

Note the 2 at the end.

Charlie

<snip>


devel / comp.lang.verilog / Re: How can I stop the simualtion at stop bit for i2c master verilog code?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor