verilog code for D flip flop

Thread Starter

vead

Joined Nov 24, 2011
629
I have googled for D flip flop verilog code there are different type of code like synchronous set
synchronous rest
synchronous with positive edge clock
now my question is that if I want to design flip Ic what code may be use I think i need to write code for synchronous set rest with positive edge clock I am not sure please anyone clear my doubt
 

tshuck

Joined Oct 18, 2012
3,534
It is a matter of what you, the designer, require. If you feel you need a set and reset, put it in, if not, leave it out.

You need to figure out the specifications you need the device to have, then implement them...
 

Thread Starter

vead

Joined Nov 24, 2011
629
It is a matter of what you, the designer, require. If you feel you need a set and reset, put it in, if not, leave it out.

You need to figure out the specifications you need the device to have, then implement them...
when we design D flip flop in digital circuit we need to all like set , reset data clock, Q and Q0 now I can say this is complete D flip flop It work as flip flop
but when we design in verilog I confused why we write code only for set or reset if we write verilog code only for set or reset does they work as flip flop?
 

tshuck

Joined Oct 18, 2012
3,534
A flip flop doesn't need any set or preset. It just needs to be an edge-triggered bistable element (stores 1 or 0 at a clock edge).
 

Thread Starter

vead

Joined Nov 24, 2011
629
thats little bit different I explain what I am asking If I need D flip flop for counter
so i need to write code for D flip flop but now I have choice
synchronous set
synchronous rest
synchronous with positive edge clock

which one should i used for counter
 

t06afre

Joined May 11, 2009
5,934
A counter may look someting like this in Verilog
Rich (BB code):
module behav_counter( d, clk, clear, load, up_down, qd);
 
// Port Declaration
 
input   [7:0] d;
input   clk;
input   clear;
input   load;
input   up_down;
output  [7:0] qd;
 
reg     [7:0] cnt;
 
 
assign qd = cnt;
 
 
always @ (posedge clk)
begin
    if (!clear)
        cnt = 8'h00;
    else if (load)
        cnt = d;
    else if (up_down)
        cnt = cnt + 1;
    else
        cnt = cnt - 1;
end 
 
endmodule
At least this is the typical setup.
 

Thread Starter

vead

Joined Nov 24, 2011
629
that's i am not asking I am asking about D flip flop I want to implement hardware of D flip flop (just paper work for my understanding) Now I have choice

1) synchronous set
2) synchronous rest
3) synchronous set/reset with positive edge clock

you meant that all are d flip flop I want to ask , can i get the above ICs of all D flip flop in market
 

kubeek

Joined Sep 20, 2005
5,795
I think you can get a D with no sets or resets and a D with async set and reset, both in positive and negative edge triggered if I am not mistaken.
Synchronous set and reset is more complicated to make, so I don´t think you can get them as single chips.
 

t06afre

Joined May 11, 2009
5,934
I am confused about this post. Your heading was verilog code for D flip flop. But now your request looks more like a request for a single chip with some D flip flop function.
 

tshuck

Joined Oct 18, 2012
3,534
There are plenty of ICs in the wild - just check out some of them (check out 7474, 74171, and 7479 in particular).

Your Verilog code for a D flip-flop will, again, be whatever you feel you need. If you want to load it out with all possible features, go for it, in the end, if you don't need it, it's no big deal, just don't use it.

What does it matter if you can get it in the market? You are designing this device yourself, it doesn't matter what is out there unless you want to convert the HDL to a schematic and hook the device up.

I'm not sure why we had to tell you this. You are the designer for the application, you decide what is required to get the job done.
 

Thread Starter

vead

Joined Nov 24, 2011
629
ok, we can write verilog code for below

1) synchronous set
2) synchronous rest
3) synchronous set/reset with positive edge clock

can anyone explain what is difference between them
 
Top