1
\$\begingroup\$

Some articles say that if I want to achieve different functions / tasks, it's better to separate the sensitivity list into multiple blocks. So, I'm wondering if I can really do this?

For example, instead of writing

always_ff @(posedge clk) begin
 b <= c;
 a <= b;
end

Can I write the following one to achieve the same function?

always_ff @(posedge clk) begin
 b <= c;
end
always_ff @(posedge clk) begin
 a <= b;
end

I also found a similar question: In Verilog , if the always@ block is executed sequentially , how do non-blocking statements work since they are executed parallely?. But I don't know if it works for multiple always blocks.

asked Oct 17, 2024 at 7:48
\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Both codes result in the same two synchronous devices (non-blocking assignments). It is understandably confusing that the language used in the literature uses words similar to what we use in software. There is nothing being "executed" in parallel.

enter image description here

If you use blocking assignments for the single "always block" with two assignments, b would be ignored by the synthesis tool and a single FF (or register) will be inferred.

answered Oct 17, 2024 at 9:33
\$\endgroup\$
1
\$\begingroup\$

Both of your options create the same hardware. Which you use is a matter of taste.

If your intention is to create a shift register, then the first form is easier to read, especially if you are reading it from a while ago, or someone else is.

If the two blocks just happen to communicate via the signal b, then it's perhaps clearer to separate them, especially as the blocks become bigger. But then, it would be better to choose a more descriptive name than 'b'.

At this low level of complexity there's no need to strongly prefer either one.

answered Oct 17, 2024 at 10:04
\$\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.