0

So, I'm working on a simple register that takes a synchronized input and, as soon as input is asserted, holds that state until reset is enabled.

My code should be pretty self explanatory. Is this checking-of-reg-output going to cause any problems?

    module walk_reg(
        input Walk_Sync,    //pedestrian set walk-request
        input WR_Reset,     //FSM reset, for during the walk service
        input clk,      //clock
        output reg WR   //output
        );


    always @(posedge (clk)) 
    begin
        if(WR_Reset)    //if reset enables, output goes to 0
            WR <= 1'b0;
        else if (WR)    //if WR is already on, keep it on
            WR <= WR;
        else 
            WR <= Walk_Sync;    //if reset is not enabled and WR isn't already one, assign output to Walk_Sync
    end

    endmodule // walk_reg

EDIT Changed name of variable, forgot to change it in code

0

2 Answers 2

2

Not answer but too much for a comment.

always @(posedge (clk)) 
    begin
        if(WR_Reset)    //if reset enables, output goes to 0
            WR <= 1'b0;
        else if (WR)    //if WR is already on, keep it on
            WR <= WR;
        else 
            WR <= Walk_Sync;    //if reset is not enabled and WR isn't already one, assign output to Walk_Sync
    end

Is the same as:

always @(posedge clk) 
begin
  if (WR_Reset)    //if reset enables, output goes to 0
    WR <= 1'b0;
  else if (!WR)    
    WR <= Walk_Sync;
end

Flip-flops will hold their value if no condition is met.

Even better suggestion from duskwuff:

always @(posedge clk) 
begin
  if (WR_Reset)    //if reset enables, output goes to 0
    WR <= 1'b0;
  else if (Walk_Sync)    
    WR <= 1'b1;
end
Sign up to request clarification or add additional context in comments.

1 Comment

Or alternatively, possibly a bit clearer: … else if (Walk_Sync) WR <= 1'b1.
0

on a side note, the WR_Reset will only reset the flop only when the clock is working. In most of the Flop designs, we use ASYNC reset edge detection then the reset detection based on clock.

always @(posedge (clk)) vs always @(posedge (clk) or posedge(WR_Reset))

Otherwise, no problem in using WR for conditional assignment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.