0
\$\begingroup\$

Assume I have the follow assignment

wire COND;
assign COND = A & B;

The values of A and B are changing between true and false, however, once they both hit 1 at the same time and COND = 1; I wish to keep this COND as a true value (sort of like a trigger) instead of it reverting to 0 when A and B changes.

Does anyone know a neat way to accomplish this?
Thank you!

JRE
75k10 gold badges115 silver badges197 bronze badges
asked Mar 1, 2017 at 16:14
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Unless your output is synchronous to a clock, what you are describing is a latch. \$\endgroup\$ Commented Mar 1, 2017 at 16:30
  • \$\begingroup\$ One option is assign COND = COND | (A&B);. I'll leave it up to you to work out how to make it possible to reset the value to 0 when you want to. \$\endgroup\$ Commented Mar 1, 2017 at 16:40

1 Answer 1

0
\$\begingroup\$

I've experienced simulators, synthesizers, linters, etc. that balk when they see an assign statement that directly assigns back to itself. They flag it because it is usually indicates an unintended latch.

Most design practices disarrange using (level sensitive) latches because prorogation delay could cause glitching leading to undesirable behavior. There are a few cases when a latch is necessary. In this situations the most common recommendations are:

  • use an always @* block (always_latch if SystemVerilog) separate from other combinational logic.
  • minimize the logic on the enable pin(s); complex logic have higher changes of causing glitches
  • Assign with non-blocking assignment (preferred)
  • Be aware the synthesizers may need directives to map to a specific latch type (eg SR-latch, D-latch, D-latch w/ async reset/preset, etc)

Your latch should look something like this:

reg COND;
always @* begin
 if(A && B) begin
 COND <= 1'b1;
 end
end

You will probably want an additional condition to reset the latch and you will need to design if set or reset should have higher priority.

answered Mar 1, 2017 at 22:42
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.