Я знаю, что защелки не одобряются в оборудовании и в кодировании Verilog. Но, я иногда сталкиваюсь со случаями, когда я не могу избежать защелки. Например, в этих двух случаях:
always @ (*)
begin
random_next = random; //default state stays the same
count_next_r = count_r;
random_next = {random[28:0], feedback}; //**shift left the xor'd every posedge clock
if (count_r == 30) //if all 30 bits are shifted into register
begin
count_next_r = 0;
random_done = random; //assign the random number to output after 13 shifts
end
else
count_next_r = count_r + 1;
Здесь random_done
— защелка. Я не вижу другого способа написать это. Я хочу, чтобы random_done
имел данные только после 30 смен random
. Если я реализую это таким образом, меня предупредят о защелке, и она не будет работать должным образом.
Аналогично, в приведенном ниже коде:
always @ (*)
begin
state_next = state_reg; //default state stays the same
count_next = count_reg;
sel_next = sel;
case(state_reg)
idle:
begin
//DISPLAY HI HERE
sel_next = 2'b00;
if(start)
begin
count_next = random_done; //get the random number from LFSR module
state_next = starting;
end
end
starting:
begin
if(count_next == 750000000) // **750M equals a delay of 15 seconds. 8191 for simulation
begin //and starting from 'rand' ensures a random delay
outled = 1'b1; //turn on the led
state_next = time_it; //go to next state
end
else
begin
count_next = count_reg + 1;
outled = 1'b0;
end
end
time_it:
begin
sel_next = 2'b01; //start the timer
state_next = done;
end
done:
begin
if(stop)
begin
sel_next = 2'b10; //stop the timer
outled = 1'b0;
end
end
endcase
Из приведенного выше кода проблемный раздел таков:
done:
begin
if(stop)
begin
sel_next = 2'b10; //stop the timer
outled = 1'b0;
end
Здесь outled
определяется как защёлка и при реализации меня об этом предупреждают. Я просто хочу, чтобы светодиод становился низким при нажатии стопового бита.
Как избежать этих защелок?