SNUG論文巡禮系列二:State Machine Coding styles for Synthesis

2021-03-02 數字晶片實驗室

本文詳細介紹了可綜合有限狀態機的Verilog coding styles,以及one-always FSMs和two-always FSMs的優缺點。

 

State Machine Classification

 

根據狀態機輸出生成的方式有兩種類型狀態機,

 

Moore State Machine,輸出僅是當前狀態(present state)的函數。

Mealy State Machine, 輸出是當前狀態和輸入的函數。可以看到下圖中的虛線標註了Mealy State Machine Only

      

 

除了根據狀態輸出的生成方式分類,還可以根據狀態編碼的方式進行分類, binary-encode,gray-encode, Johnson-encode, one-hot-encode

 

FSM Verilog Modules


Guideline:使用一個單獨的模塊(module)編碼狀態機,方便狀態機定義(definition)、修改(modification)和調試(debug)。

 

State Assignments


Guideline:使用symbolic parameters進行狀態賦值,增加可讀性簡化狀態的修改

下面是相應的binary encodingone-hot encoding

 

Parameter definitions for binary encoding

parameter [2:0] // synopsys enum codeIDLE = 3'd0,S1 = 3'd1,S2 = 3'd2,S3 = 3'd3,ERROR = 3'd4;

Parameter definitions for verbose one-hotencoding

parameter [4:0] IDLE = 5'b00001,S1 = 5'b00010,S2 = 5'b00100,S3 = 5'b01000,ERROR = 5'b10000;

Theone-hot encoding can yield very efficient FSMs for state machines that have many interconnections with complex equations, including a large number of connections to one particular state. State Machine Coding styles for Synthesis

(後面會實例分析這個問題)

 

也可以使用宏定義(`define)定義狀態名稱, `define會創建一個全局定義(global definition)parameters會創建一個局部定義(local definition),從而parameters定義允許設計在不同的模塊具有多個同名的之間狀態定義,例如IDLE。

 

Two-Always Block State Machine

 

Two-Always狀態機包含生成下一狀態的組合邏輯(next state combinational logic)、生成輸出的組合邏輯(output combinational logic)和更新當前狀態的時序邏輯(clocked present state logic)。

 

Sequential Always Block

Guideline:在建模時序邏輯時,僅使用Verilog非阻塞賦值。(當然,這也不全對,參考使用阻塞賦值和非阻塞賦值建模的分頻時鐘

 

always @(posedge clk or posedge rst)if (rst) state <= IDLE;else state <= next;

Combinational Always Block

 

Guideline:在建模組合邏輯always語句塊中僅使用阻塞賦值。

 

該always語句塊用於獲得需要被更新的下一個狀態值,其被一個敏感列表(當前狀態和輸入)。

應該在always語句塊之後編碼一個默認的下一個狀態賦值語句。默認賦值可以是X(綜合工具don't cares)、IDLE和任意狀態。因為存在組合邏輯綜合出鎖存器問題,這在實例解析Verilog綜合出鎖存器的問題中曾經探討過。

 

always @(state or i1 or i2 or i3 or i4) beginnext = IDLE;case (state)IDLE: begin  next = ERROR;  if (!i1) next = IDLE;  if (i1 & i2) next = S1;  if (i1 & !i2 & i3) next = S2;endS1: ...

 

FSM Output Generation

 

輸出邏輯可在編碼在連續賦值assign中

assign rd_out = (state == READ) & !rd_strobe_n;

也可以編碼在組合邏輯always語句塊中。

case(state)  ...  READ: if (!rd_strobe_n) rd_out = 1'b1;

One-Always Block State Machine

 

one-always狀態機比two always的仿真效率更高,但是難以修改和調試。

 

往期精彩

Reference paper :

http://bbs.eetop.cn/thread-870738-1-1.html

相關焦點

  • state machine replication vs primary backup system
    然後zab, vr 經常提到他們的一個primary backup system, 與replicate state machine 還是有不同的. 雖然他們都有state machine, consensus  module, log.
  • Spring Statemachine 1.0.0 正式發布
    此版本更新內容如下:Easy to use flat one level state machine for simple use cases.Hierarchical state machine structure to ease complex state configuration.
  • Android狀態機StateMachine
    PersonStateMachine("Person");    person.start();    return person;}1.4、案例源碼下載Android_StateMachine案例地址https://github.com/AndroidHighQualityCodeStudy/Android_-StateMachine二、
  • coding是啥工作 coding的含義介紹
    coding是啥工作?近幾年,隨著科技的不斷創新和網絡的不斷普及和換代,越來越多的人學習並樂意去學習創程序語言,在努力中脫穎而出成為有血程式設計師的人也不在少數,小編身邊就又很多這樣的人。那麼電腦程式員經常說起和討論的coding是什麼意思呢?下面小編就為大家科普一下coding的含義吧!
  • Deep state
    My comments:Deep state refers to, in short, people who run a country (state) from behind the scenes – in contrast to the regular state, or government machine that runs the
  • 獨家秘訣:用YAKINDU StatechartTools進行Java開發的圖形狀態機
    Initialize the state machineIPlayerStatemachine statemachine = new PlayerStatemachine();statemachine.init();// 2.
  • 石墨二炔@Janus磁鐵礦用於光催化固氮
    石墨二炔@Janus磁鐵礦用於光催化固氮 作者:小柯機器人 發布時間:2020/10/29 13:28:45 石墨二炔@Janus磁鐵礦用於光催化固氮,這一成果由中國科學院化學研究所Yuliang
  • 衡水文博系列職稱論文發表需要多長時間
    衡水文博系列職稱論文發表需要多長時間  3、 作品內容  3.1發表論文作品必須出自原創,並且在中國期刊採編聯盟快速論文發表網絡平臺首發,不得作假,一經發現,將取消作者的投稿資格,情節嚴重者,將在首頁進行公布。
  • 【預告】施汝為系列講座 | 武漢大學劉惠軍教授:Machine learning in the study of ...
    劉惠軍 教授單位:武漢大學主辦方:合肥微尺度物質科學國家研究中心、國際功能材料量子設計中心、中科院強耦合量子材料重點實驗室、中國科大物理系、科研部Benefited from recent advances in big-data analytics, the machine
  • Bloom Coding Boy Charlie
    Learning coding has changed my life.                                    Could you introduce how someone’s coding capability can be rated and certified?
  • React系列八 - 深入理解setState
    ); // 你好啊,李銀河  }, 0);}驗證二:原生DOM事件:componentDidMount() {  const btnEl = document.getElementById("btn");  btnEl.addEventListener
  • Combustion Synthesis: Novel Routes to Novel Materials
    蘭州化物所撰寫了其中的兩章,第8章燃燒合成熔化和鑄造(Combustion synthesis melt-casting),介紹了該技術的特點、研究現狀和發展水平。第11章燃燒合成合金(Combustion synthesis of alloys),闡述了蘭化所提出的燃燒合成製備合金的原理和合金納米結構形成機制,介紹了燃燒合成製備的幾種納米合金材料的納米結構特徵和性能。
  • US Washington state may approve corpse composting
    Residents of Washington state may soon be able to compost more than food scraps and leaves.Human remains could be added to that pile of mulch if the governor signs a bill recently passed by the state legislature.
  • awesome-adversarial-machine-learning資源列表
    發現一個不錯的awesome-adversarial-machine-learning的資源列表,有需要的同學可以查看訪問:
  • 有機合成大牛woodward,E.J.Corey,Baran的博士論文
    Baran,大名鼎鼎,無需贅言,只小小引一段網上廣泛傳播的一段話:TotalSyn歷史悠久,但是從不衰老。(2)資料:Corey doctoral thesis作者:Elias James Corey資料頁數159內容簡介:synthesis of N,N-diacylamino acids and analogs
  • 共建單位巡禮(十五)——中國科學院水生生物研究所
    本公眾號推出「國家長江生態環境保護修復聯合研究中心共建單位巡禮」專欄,系統展示共建單位的相關研究基礎與成就。本期介紹單位為:中國科學院水生生物研究所。期刊主要刊登與水生態的評價與治理;水生物的生化、遺傳、病理、毒理和分類區系;水生物的育種、培養、開發利用和病害防治;漁業生物學及有關湖沼學的綜合調查與研究等相關的中、英文研究論文及綜述。是中文核心期刊、中國科技核心期刊、中國科技論文統計源期刊。學報近年來連續被評為中國精品科技期刊、中國國際影響力優秀學術期刊、RCCSE中國權威學術期刊、湖北省優秀期刊、湖北省精品期刊。
  • 中文語言理解基準測評(CLUE)論文被COLING 2020高分錄用
    COLING 2020共計收到2180篇論文投稿,其中包括2021篇主會投稿、48篇Demo投稿、111篇工業論文投稿,最終有1900餘篇論文進入審稿流程。本屆大會暫未公布錄用率等信息。中文語言理解基準測評(CLUE)論文被COLING 2020錄用,為長文一篇標題:
  • 收錄 | 科愛期刊 Non-coding RNA Research 被 Scopus 收錄
    Non-coding RNA Research aims to publish high quality research and review articles on the mechanistic role of non-coding RNAs in all human diseases.
  • 為什麼一個基因可以既是lncRNA又是protein_coding
    有意思的是學生們給我反饋了有幾個基因居然既是lncRNA又是protein_coding。CCDC39-AS1 lncRNA ENSG00000243187 chr3 180680084 180700449MATR3 protein_coding ENSG00000280987 chr5 139273752 139331671MATR3 protein_coding ENSG00000015479 chr5 139293674 139331677SMIM40