Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to declare inout in behavioral modeling in Verilog HDL

Status
Not open for further replies.

iyyappanbala

Newbie level 5
Joined
Nov 6, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
karnadaka
Activity points
49
Dear friends,

please help me to solve this problem,
How to swap number in behavioral modeling(non Blocking) Verilog Hdl,

module swap(a,b);
inout [3:0] a,b;
reg [3:0] a,b;
always@(a,b)
begin
b<=a;
a<=b;
end
endmodule
 

You can't. Better read your Verilog book again.

And don't use non-blocking in a non-posedge sensitive always block unless you like to have the potential for simulation synthesis mismatches (resulting in hardware that doesn't work correctly).

i.e. do this:

Code Verilog - [expand]
1
2
3
4
5
6
7
always @ (posedge clk) begin
  non_blocking_assignment <= used_here;
end
 
always @ (used_here) begin
  blocking_assignment = used_here;
end



...and avoid this:

Code Verilog - [expand]
1
2
3
4
5
6
7
always @ (posedge clk) begin
  blocking_assignment = dont_use_this;
end
 
always @ (dont_use_this) begin
  non_blocking_assignment <= dont_use_this;
end



If you want to swap (for simulation purposes only) then use blocking assignments like so:

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
`timescale 1ns/1ns
module t;
 
reg [7:0] old_a, a, b;
initial begin
  a = 7;
  b = 3;
  $display ("Initial values:\n%t - a = %h, b = %h, old_a = %h", $time, a, b, old_a);
  #100;
  a = 5;
  b = 8;
  $display ("Initial values:\n%t - a = %h, b = %h, old_a = %h", $time, a, b, old_a);
  #100;
end
 
always @* begin
  old_a = a;
  a = b;
  b = old_a;
end
 
initial begin
  $monitor ("Swapped values:\n%t - a = %h, b = %h, old_a = %h", $time, a, b, old_a);
end
 
endmodule


Of course this is unrealistic behavior and is only for simulation purposes.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top