有限状态机HDL模板
生活随笔
收集整理的這篇文章主要介紹了
有限状态机HDL模板
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?邏輯設(shè)計(jì), 顧名思義, 只要理清了 邏輯 和 時(shí)序, 剩下的設(shè)計(jì)只是做填空題而已。
?下面給出了有限狀態(tài)機(jī)的標(biāo)準(zhǔn)設(shè)計(jì),分別為 VHDL 和 Verilog 代碼
1? 有限狀態(tài)機(jī)
2? VHDL模板一
library IEEE; use ieee.std_logic_1164.all;--! 1) 端口定義 entity <entity_name> is port (DIN : in <data_type>;RST : in std_logic;CLK : in std_logic; DOUT : out <data_type> ); end <entity_name>;--! 2) 狀態(tài)定義 architecture <arch_name> of <entity_name> istype state is (IDLE, ST1, ST2, ...); signal c_state, n_state : state;begin--! 3) 時(shí)序邏輯 pfsmsyn: process (rst, clk) beginif (rst = '1') thenc_state <= IDLE;elsif (clk'event and clk='1') thenc_state <= n_state;endif; end process;--! 4) 組合邏輯 pfsmlogic: process (din, c_state) begincase c_state iswhen IDLE =>if (din = ...) thendout <= <value>; -- 輸出c_state <= state1; -- 狀態(tài)else ...end if;when ST1 =>... ...... ...... ...when others =>... ...end case; end process;end <arch_name>;?
3? Verilog模板一
// 1) 端口聲明 module fsm(clk, rst, ctrl, dout);input clk, rst, ctrl;output [n-1:0] dout; // n 取決于輸出值的位數(shù)reg [n-1:0] dout;// 2) 狀態(tài)定義parameter IDLE = 0, ST1 = 1, ST2 = 2, ST3 = 3, ....;reg [m-1:0] c_state, n_state; // m 取決于‘“狀態(tài)”數(shù)量的位數(shù)// 3) 時(shí)序邏輯 always @ (posedge clk or posedge rst) begin: SEQif (rst)c_state = IDLE;elsec_state = n_state; end// 4) 組合邏輯 module @ (ctrl or c_state) begin: COMBcase (c_state)IDLE: begindout = <value0>;n_state = ST1;endST1: begindout = <value1>;n_state = ST2;endST2: . . . . . .. . . . . .. . . . . .endcase endendmodule?
參考資料:
?<Circuit Design with VHDL>? chapter 8? State Machines
?<HDL Chip Design>
轉(zhuǎn)載于:https://www.cnblogs.com/xinxue/p/5223810.html
總結(jié)
以上是生活随笔為你收集整理的有限状态机HDL模板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言 printf格式化输出,参数详解
- 下一篇: 使用cocoapods时,import