Edge Detector in Verilog

OP #7726549

I have to design Posedge detector.I googled to clear understanding but nothing found usefull.I have question why we have to use this circuit for edge detection if we have D-Flip Flop.Simply put that signal in sensitivity of Always block and when posedge will come always block will run

Attached files:

Using external signals as clock is not a good design practice. Only use the real clock signal for posedge or negedge. For normal (slow) signals (e.g. pixel_ready, adc_done or spi_csn) it's often necessary to use a synchronizer and an edge detector as you described.

OP

Yes i understand little bit...Can we put clock signal in sensitivity list for sync and the signal for whoom i am detecting his posedge to be putted in if condition just like this

Always @(posedge clk) Begin If ( s==1 ) ..........

When posedge of s will be detected then we can do anytask...Is this right?

Asad Ur R. wrote:

Always @(posedge clk) Begin If ( s==1 ) ..........

I think this will only detect the high-level of s.

When posedge of s will be detected then we can do anytask...Is this right?

To detect an edge on signal 's', I would use something like this:

1
always @ (posedge clk)
2
begin
3
  if (( s == 1) and ( s_dly == 0))
4
  {
5
    // do something on rising s-edge
6
  }
7
  s_dly <= s;
8
end
Moderator (Company: Titel)

Asad Ur R. wrote:

Simply put that signal in sensitivity of Always block and when posedge will come always block will run

You have a very software oriented view of HDL. In reality you won't get a "block" of something in hardware. And of course you won't get something that "runs" somehow. Instead in your FGPA you only have logic blocks (LUT) and D-flipflops to generate your own functions.

And when you look in the synthesizers user manual you will find that this code

1
always @ (posedge clk)
2
begin
3
...
4
end

is the "Verilog-Way" to describe a D-flipflop.

And no, it is not a good idea to write

1
always @ (posedge d)
2
begin
3
...
4
end

because then you will get the d flipflop also, but you will get the d on the clock input. So as desired the flipflop will be set with a rising edge of the d signal. But you will not find a reliable way to reset it properly.

Reply

A question of your own? This thread is over 2 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.