하드웨어 및 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
에 random
의 30 교대 만 데이터를 갖기를 원합니다. 이 방법으로 구현하면 래치가 경고되며 제대로 작동하지 않습니다.
마찬가지로 아래 코드 :
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
래치 같이 I이 경고하고 실행 중에 검출 . 나는 멈춤 비트가 눌려 졌을 때 LED가 낮아지기를 원한다.
어떻게 이러한 래치를 피할 수 있습니까?
해답을 가져 주셔서 감사합니다. "각 레지스터에 대한 논리가 항상 차단"이라는 의미에 대해 조금 자세히 설명해 주시겠습니까? 디자인이 너무 바쁘고 지저분 해지지 않을까? – ipunished
부시? 무슨 말이에요? HW 입장에서 보면 중요하지 않습니다. 그것은 똑같을 것이다. 내 말은 만약 당신이 카운터를 가지고 있다면 당신은 자신의 블록을 가지고있는 상태 레지스터를 가지고 있다면 그것을 항상 하나의 블록에 두는 것입니다. 읽기 또는 쓰기 할 상태 레지스터가있는 경우에는 항상 블록이 있습니다. 예제에서 본 코드를보십시오. 카운터를위한 블록 하나와 random_done의 블록입니다. – AxelOmega