2012年10月12日 星期五

8-Bit Ring Counter, 8-Bit Adder


源自http://asic-soc.blogspot.tw/2012/06/verilog-hdl-behavioural-modeling-8-bit.html

Verilog HDL: Behavioural Modeling: 8-Bit Ring Counter, 8-Bit Adder

8-Bit Ring Counter

Use concatenation operator:
xn={x[2:0],x[0]}
for n bit, xn={x[n-1:0],1’b0}
always @ (posedge reset or posedge clk)
if (reset == 1’b1)
count = 8’b0000_0001;
else if (enable==1’b1)
count={count[6:0],count[7]};     //shift using concatenation operator

module clockgen;
reg clk;
initial clk=1’b0;
forever
#20 clk= ~clk;
initial #500 $stop;
endmodule
//$stop à stops and puts execution o interactive mode; Either you can ‘halt’ or ‘procedd’
//$finish à terminates the simulation itself
//time unit can be changed by setting in simulator or you can change using compiler directive called ‘timescale’
Behavioural 8-Bit Adder:
module adder8bit (sum, carry, a, b, cin)
input [7:0] a,b;
output [7:0] sum; reg [7:0] sum;
output carryout ; reg carryout;
reg [8:0] c;
always
begin
c[1]=cin;
for (i=0; i<7; i=i+1)
{c[i+1],s[i]=a[i]+b[i]+c[1];
endloop
cr=c[8];
end
endmodule

沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...