2012年12月5日 星期三

ASIC Digital Design (Verilog Examples)


BCD up/down counter


// ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ // ~ -- // ~ Published by: www.asic-digital-design.com // ~ -- // ~ Description: This is synchronous 4-bit BCD counter // ~ with possibility to count UP or DOWN. // ~ UP: dir='1' // ~ DOWN: dir='0' // ~ -- // ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ module cnt_bcddir ( dout4, dir, clk, arst, srst, en ); output [3:0] dout4; input dir; input clk, arst, srst, en; // declaration of signals inside this block reg [3:0] reg_cnt; reg [3:0] nxt_cnt; always @ ( posedge arst or posedge clk ) // dff_cnt begin if ((arst == 1'b1)) reg_cnt <= 1'h0; else if ((srst == 1'b1)) reg_cnt <= 1'h0; else if ((en == 1'b1)) reg_cnt <= nxt_cnt; end // end dff_cnt always @ ( reg_cnt or dir ) // cmb_cnt begin if ((dir == 1'b0)) if ((reg_cnt == 9)) nxt_cnt <= 1'h0; else nxt_cnt <= (reg_cnt + 1); else if ((reg_cnt == 0)) nxt_cnt <= 4'b1001; else nxt_cnt <= (reg_cnt - 1); end // end cmb_cnt // outputs -- assign {dout4}=reg_cnt; //-- endmodule

註解
您沒有加入註解的權限。

沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

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