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.

Verilog Doubt in coding of D Flip Flop

Status
Not open for further replies.

Plzhelp

Junior Member level 3
Joined
Feb 18, 2012
Messages
31
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,288
Location
India
Activity points
1,535
Can I assign a wire value to a reg variable??

Is this code for a D- FF correct:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module dffnik(input clk,rst,S, output reg q); 
wire d, iwx,iwy;
always@(posedge clk,posedge rst,posedge S)
begin 
assign d<= iwx;
if (rst)
q<=0;
else if (clk && S)
begin
q<=S;
iwy<=q;
end
else
begin q<=d;
iwy<=q;
end
end
endmodule



Where iwx is coming from a previous D- FF and iwy is going to the next D-FF. I don't have the Xilinx software with me. If somebody could help me 2 know whether the code is correct or not, it will be of great help.

Thank you in advance.:smile::smile:
 
Last edited by a moderator:

Well.. Thank you for that code of D- FF but I know that code. I was actually trying to create a sub module which uses a D-FF with a set and a reset pin which can be instantiated for the code of ring counter. That is the reason I am using iwx and iwy. Can you plz help me now????
 

Hi,

Actually whats this iwx and iwy here.

The code seems to be like that the iwy is always 'd' and the iwx is "UNKNOWN"...

And one another thing is that the UNKNOWN iwx is assign to 'd', so 'd' also get unknown....
 

You can not write assign statement inside a always block. When you write always@(posedge clk) that indicates it is a sequential block but assign statement is a combinational statement.

Can I assign a wire value to a reg variable??

Is this code for a D- FF correct:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module dffnik(input clk,rst,S, output reg q); 
wire d, iwx,iwy;
always@(posedge clk,posedge rst,posedge S)
begin 
assign d<= iwx;
if (rst)
q<=0;
else if (clk && S)
begin
q<=S;
iwy<=q;
end
else
begin q<=d;
iwy<=q;
end
end
endmodule



Where iwx is coming from a previous D- FF and iwy is going to the next D-FF. I don't have the Xilinx software with me. If somebody could help me 2 know whether the code is correct or not, it will be of great help.

Thank you in advance.:smile::smile:
 

I was actually trying to create a sub module which uses a D-FF with a set and a reset pin which can be instantiated for the code of ring counter. That is the reason I am using iwx and iwy.
All connections to a module need to go through the interface. In your code iwx is simply unconnected and thus has an unknown state.
 
Last edited:

Golden_star,

Thank you for that tip.. I will remember that..

---------- Post added at 23:29 ---------- Previous post was at 23:25 ----------

FVM and imbichie,

I found out the faults in the my code. The approach itself was wrong.. Thank you guys...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top