0
\$\begingroup\$
always @(posedge clk)
begin
 clk_counter <= clk_counter + 1;
 if(clk_counter == divider)
 clk_counter <= 0;
end

Will the clk_counter <= clk_counter + 1; and if statement be executed concurrently so the clk_counter evaulation at if statement will be the old one ?

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Sep 23, 2023 at 21:08
\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

The statements within a begin/end block execute sequentially. However, a nonblocking assignment statement evaluates the RHS as it executes and schedules an update to the LHS in a later event region.

If there are multiple updates scheduled to the same variable, last update wins. So this code executes effectively the same as

always @(posedge clk)
begin
 if(clk_counter == divider)
 clk_counter <= 0;
 else 
 clk_counter <= clk_counter + 1;
end
answered Sep 23, 2023 at 21:31
\$\endgroup\$
0
\$\begingroup\$

The if will be evaluated before any change is made to the clk_counter signal because the assignments are non-blocking.

The assignment of 0 to the clk_counter signal should take priority over the increment assignment because it happens afterwards.

Putting the increment into an else would have equivalent behaviour, whilst being clearer code.

answered Sep 23, 2023 at 21:33
\$\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.