Triggering signal on both edges of the clock

Anonymous picture Anonymous · Oct 26, 2013 · Viewed 22.8k times · Source

Design requires a signal to be activated at specific circumstance on rising edge of the clock, and deactivated at another circumstance on falling edge of clock. Here's what I think:

always@(posedge CLK) begin
  signal1 <= 1'b0; // reset flag
  if(circumstance1) signal1 <=1'b1; // raise flag if circumstance occurs
end

always@(negedge CLK) begin
  signal2 <= 1'b1; // reset flag (actually set alternate to signal1)
  if(circumstance2) signal2 <=1'b0; // raise flag if circumstance occurs
end

always@(posedge signal1 or negedge signal2) begin
  if(signal1) outsignal <= 1'b0;   // activate outsignal
  else outsignal <= 1'n1;   // deactivate outsignal
end

Will that work? Are there better alternatives (doubling clock and catching single edge is not an option here).

Edit after Russell's reply. Russell, I think you propose the following:

wire nCLK = ~CLK;

always@(posedge CLK or posedge nCLK or negedge nRESET) begin
    if(!nRESET) outsignal <= 1'b0;
    else if(nCLK) outsignal <= 1'b1;
         else outsignal <= 1'b0;
end

did I understand you properly?

Answer

Russell picture Russell · Oct 26, 2013

Is this an off-chip signal? If so, Xilinx and other chip vendors offer primitives that can help you with this. If you wire up an ODDR2 primitive you might have better luck. Invert the clock. Drive the normal clock into C0 and they inverted clock into C1. Then use your logic to set the D0 and D1 inputs.

The way you wrote above is not a very robust solution.

Try using fabric primitives to accomplish this task.