简体   繁体   中英

for loop inside always posedge clock

Sir, I have some doubts regarding for loop inside the always block. Please clarify me. All iterations have done in single clock cycle?. what will occur when for loop inside another for loop which is inside always block? Please help me to find mistakes in the following program.Thank You

reg [5:0] c;
reg [2:0] m;
reg G[5:0][2:0] = {{1'b1,1'b0,1'b0},{1'b0,1'b1,1'b0},{1'b0,1'b0,1'b1},   {1'b1,1'b1,1'b0},{1'b0,1'b1,1'b1},{1'b1,1'b0,1'b1}};   
integer i;
integer j;
always @(posedge clk1)
begin
   for(i=0;i<6;i=i+1)
        begin
            c[i]=0;
            for(j=2;j>=0;j=j-1)
               begin
                  c[i] <= c[i]^( m[j]&G[2-j][i]);
               end
        end  
end

Think of an always block as a little bit of software that models a little bit of hardware. The sensitivity list is a list of triggers that, when any of them change, the software executes to calculate what the new outputs should be.

For a combinational always block all the inputs are in the sensitivity list (using the @(*) construct), so if any input changes, the outputs of that little bit of hardware may change (pretty much the definition of combinational logic). So, should any of the inputs change, the software executes to calculate what the new outputs from that little bit of combinational logic will be.

For a sequential always block, only the clock and (if present) asynchronous reset are in the sensitivity list, because no other input directly causes the outputs to change. Therefore, for a sequential block, should the clock (or asynchronous reset) change, then the software executes to calculate what the new outputs of that little bit of sequential logic will be.

So, in your case, you have a sequential always block without an asynchronous reset. It is a little bit of software which models a little bit of sequential logic. The outputs of this sequential logic will only change if the clock changes (if there is a rising edge on clk1 ). So, if there is a rising edge on clk1 , the code inside the always block starts executing in order to calculate what the new values of the array c will be (the outputs of your sequential logic, because that is the variable assigned in this particular always block). The fact that there happen to be loops in this particular code doesn't matter. If there is a rising edge on clk1 then the loops will execute completely (without waiting for any more rising edges on clk1 ) in order to calculate what the new values of c will be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM