I need to perform an addition inside an always block (with clock) but one of the operands depends on the previous value, hence I cannot use non-blocking statements as all variables/registers/wires will have same values.
The expression is basically of the form: a = a[i-1] + constant;
So, I code it like this and it works fine.
always @(posedge clk or negedge rst)
begin
if (~rst)
// initialize all to 0
else
for (i=1;i<8;i++)
begin
a[i] = a[i-1] + constant; // want non-blocking here
end
temp = a[7] + constant; // want non-blocking here
end
But it creates a lot of combinational logic as there is one more always block which is performing the similar operation and thus limiting the maximum frequency of operation. Is there any way I can use non-blocking statements.
Actual code:
integer i;
always @(posedge clk or negedge rst)
begin
if (~rst | (sample_count == SAMPLE_COUNT))
begin
temp <= PHASE_WORD;
for (i = 0; i < 8; i = i + 1)
begin
phase_word[i] <= 0;
end
end
else if (adc_data_in_vld_dly0)
begin
phase_word[0] = temp;
for (i = 1; i < 8; i = i + 1)
begin
phase_word[i] = phase_word[i-1] + PHASE_WORD;
end
temp = phase_word[7] + PHASE_WORD;
end
end
So basically adding phase word and storing the last value in temp register. For example, if PHASE_WORD is 3 then, in the same clock cycle, phase_word should be [3,6,9,12,15,18,21,24] and next clock cycle it begins with 24+3=27, so 27,30,33......
Now all this works fine using "=" blocking statement at the expense of huge combinational blocks.
I was wondering if this can be done using non-blocking statements as it would greatly enhance frequency of operation. Thanks.