Verilog 파이프라인 덧셈 기

3569 단어 FPGA
다음으로 이동:http://www.cnblogs.com/haigege/archive/2011/09/28/2194687.html
'디지털 시스템 디자인 과 Verilog HDL' 에는 8 비트 4 급 파이프라인 덧셈 기 를 실현 하 는 데 사용 되 는 코드 가 있다.
module adder8pip(cout,sum,cin,ina,inb,clk
    );
input cin,clk;
input [7:0] ina,inb;
output cout;
output [7:0] sum;
reg cout,tempcin;
reg [7:0] sum,tempa,tempb;
reg firstco,secondco,thirdco; //          
reg [1:0] firstsum,thirdina,thirdinb;
reg [3:0] secondsum,secondina,secondinb;
reg [5:0] thirdsum,firstina,firstinb;

always @ (posedge clk)
begin
 tempcin=cin;tempa=ina;tempb=inb;//      
end

always @ (posedge clk)
begin
 {firstco,firstsum}=tempa[1:0]+tempb[1:0]+tempcin;//    2   
 firstina=tempa[7:2];firstinb=tempb[7:2];//          
end

always @ (posedge clk)
begin
 {secondco,secondsum}={firstina[1:0]+firstinb[1:0]+firstco,firstsum};//   2   ,         
 secondina=firstina[5:2];secondinb=firstinb[5:2];//          
end

always @ (posedge clk)
begin
 {thirdco,thirdsum}={secondina[1:0]+secondinb[1:0]+secondco,secondsum};//   2   ,         
 thirdina=secondina[3:2];thirdinb=secondinb[3:2];//          
end

always @ (posedge clk)
begin
 {cout,sum}={thirdina[1:0]+thirdinb[1:0]+thirdco,thirdsum};//     2   ,         
end

endmodule

 
종합 한 결과 다음 과 같은 경고 가 발견 되 었 습 니 다.
FF/Latch (without init value) has a constant value of 0 in block . This FF/Latch will be trimmed during the optimization process.
RTL 회로 도 를 다시 보 니 cout 가 과연 접지 되 었 다.
 
인터넷 에서 원인 을 찾 는 것 은 원래 뒤의 3 급 덧셈 연산 에서 예 를 들 어 2 급:
 {secondco,secondsum}={firstina[1:0]+firstinb[1:0]+firstco,firstsum};
"{}" 은 이미 등호 오른쪽 을 4 자리 로 한정 하 였 으 며, 등호 왼쪽 이 5 자리 이기 때문에 secondco 는 소 용이 없 으 며, 종합 할 때 secondco 를 종합 합 니 다.
  따라서 기호 수의 덧셈 에 대해 상기 코드 를 다음 과 같이 바 꿉 니 다.
 {secondco,secondsum}={ {firstina[1],firstina[1:0]}+{firstinb[1],firstinb[1:0]}+firstco,firstsum};(인증 되 지 않 음)
즉, 기호 위 치 를 확장 하고 모든 등급 의 덧셈 연산 은 확대 해 야 하 며 첫 번 째 덧셈 에 대해 서도 기호 위 치 를 확대 해 야 한다.
다음은 부호 없 는 유수 선 덧셈 기의 전체 코드 입 니 다.
module adder8pip(cout,sum,cin,ina,inb,clk
    );
input cin,clk;
input [7:0] ina,inb;
output cout;
output [7:0] sum;
reg cout,tempcin;
reg [7:0] sum,tempa,tempb;
reg firstco,secondco,thirdco; //          
reg [1:0] firstsum,thirdina,thirdinb;
reg [3:0] secondsum,secondina,secondinb;
reg [5:0] thirdsum,firstina,firstinb;

always @ (posedge clk)
begin
 tempcin=cin;tempa=ina;tempb=inb;//      
end

always @ (posedge clk)
begin
 {firstco,firstsum}=tempa[1:0]+tempb[1:0]+tempcin;//    2   ,    {}  ,        
 firstina=tempa[7:2];firstinb=tempb[7:2];//          
end

always @ (posedge clk)
begin
 {secondco,secondsum}={{1'b0,firstina[1:0]}+{1'b0,firstinb[1:0]}+firstco,firstsum};//   2   ,         
 secondina=firstina[5:2];secondinb=firstinb[5:2];//          
end

always @ (posedge clk)
begin
 {thirdco,thirdsum}={{1'b0,secondina[1:0]}+{1'b0,secondinb[1:0]}+secondco,secondsum};//   2   ,         
 thirdina=secondina[3:2];thirdinb=secondinb[3:2];//          
end

always @ (posedge clk)
begin
 {cout,sum}={{1'b0,thirdina[1:0]}+{1'b0,thirdinb[1:0]}+thirdco,thirdsum};//     2   ,         
end

endmodule

 이 코드 는 ISE 통합 으로 잘못 보고 되 지 않 았 으 나 RTL 회로 가 여전히 요구 에 부합 되 지 않 는 것 으로 밝 혀 져 통합 기 에 문제 가 있 는 것 아니 냐 는 의심 이 들 었 다.그래서 Synplify 를 설치 하고 종합 하면 정말 문제 가 없 을 뿐만 아니 라 인터페이스 도 매우 보기 좋다.
      그리고 모델 심 으로 앞 시 뮬 레이 션 을 했 는데 결과 가 안 맞 네요...왜, 왜...
      그래, 맵 을 만 들 고 시 뮬 레이 션 을 했 더 니 결과 가 맞았어...이게 왜 이래?

좋은 웹페이지 즐겨찾기