fennecJ
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 說明同步 / 非同步 /propagation delay 的概念 ## 同步 在數位電路中,同步指的是不同硬體的 output 會跟著同一個參考源(通常是 clk )同時更新,即確保不同的硬體 **以相同的速度處理資料** 為何需要同步主要見於兩個目的:硬體間的溝通 以及 消除電子元件本身的非理想特性。 先談談硬體間的溝通。我們需要有一個方法確保不同硬體間能協調的交換資料,假設現在有兩個硬體 A, B 。 A 每秒可以生產 3 筆資料,而 B 每秒只能處理一筆資料,若直接將 A 和 B 接在一起,顯然會造成硬體無法順利運作。 我們必須想一個方法同步兩個硬體處理的速度,讓他們依據某個訊號同步更新資料。我們可以設一個週期為 1 秒的 clk ,讓 A, B 都根據 clk 的 posedge 更新資料,使兩硬體能順利運作。 :::info posedge 指的是訊號從 0 -> 1 的瞬間,如下圖中 clock 的上升箭號。 ![image](https://hackmd.io/_uploads/SyM0zpAlC.png) ::: 透過 clk 更新資料還有一個好處,就是電子元件本身並非理想的。若我們希望 A 能順利將資料寫到 B 這個硬體中, A 的 output 訊號必須要滿足兩個條件: * A 的 output 需要在 clk posedge 到來的一段時間之前達到穩定,這段時間又叫做 setup time, 通常表示為 $t_{setup}$ * A 的 output 需要在 clk posedge 過後維持穩定一段時間,這段時間又叫做 hold time, 常表示為 $t_{hold}$ A 的 output 必須同時滿足 $t_{setup}$/$t_{hold}$ 的條件才能順利將值寫到 B 這個硬體中。 為什麼需要有這兩個時間?這是因為電子元件在充電/放電都是需要時間的,換句話說,要讓電子元件的狀態改變是需要時間的,詳情可見後面關於 Propagation Delay 的敘述。 另外,我們可以透過調整 clk 達成 $t_{setup}$ 的要求,換句話說,若 clk 的週期足夠長,則 A 在第一個 posedge 更新值之後,有更充裕的時間可以達到穩定。 而適當的 clk 還有一個重要的作用:在資料準備好後才更新值,也因此即便電子元件本身具有不理想的特性(需要時間更新狀態),它仍能看起來像是理想的,這也是為何我們可以在示波器上看到近乎垂直的方波。 ## 非同步 非同步電路 Asynchronous circuit 又稱 (clockless or self-timed circuit) 。指的是不使用 clk 設計的序向電路。序向電路的嚴格定義是電路任何時刻的穩態輸出不僅取決於當前的輸入,還與前一時刻輸入形成的狀態有關,也就是具有記憶功能的電路設計。 前面提到要同步 A, B 兩種硬體。需要讓運作比較快的 A 去等較慢的 B ,顯然這種作法會犧牲 A 本身的運作速度。而非同步電路的好處就是有機會可以讓電路彼此都以自己最好的速度運作。非同步電路通常會藉由設計 handshake 訊號來和不同硬體溝通,透過 handshake 訊號表達電路以完成運作。 但是非同步電路設計上遠比同步電路困難且容易出錯,且同步電路中快的硬體要等慢的硬體這件事可以透過適當的切 pipeline 的方式解決,因此現在主流的數位電路都是設計為同步電路。 ## Propagation Delay (by millaker) > 引述 Sedra Smith 電子學 Digital Design: Power, Speed, and Area : > The speed of operation of a digital system (e.g. a computer) is determined by the propagation delay of the logic gates used to construct the system. Since the inverter is the basic logic gate of any digital IC technology, the propagation delay of the inverter is a fundamental parameter in characterizing the speed of a given technology. > ... > The propagation delay is the time the inverter takes to respond to a change at its input. 電子系統的電路中有大大小小的電容,而真實世界電容充電與放電都需要時間,可以從電容公式得知: $$Q = CV$$ $$\Delta Q=C \Delta V$$ 電容值 $C$ 由材料、形狀決定,電量改變量 $\Delta Q$ 可以由固定電流得到 $$ I\Delta t = \Delta Q = C \Delta V$$ Propagation Delay 就是為了達到我們需要的電壓所需的 $\Delta t$。下面這張圖上方是一個輸入訊號,下方是非理想 Inverter 的響應圖,可以看到訊號不再是完美的脈衝,而是平滑圓角且需要花費一定時間才能到達 $\frac{V_{DD}}{2}$ ![image](https://hackmd.io/_uploads/SJjXoZxbR.png) 所有的基礎邏輯閘像是 NOR, XOR, NAND ... 都有自己的延遲,若今天設計的電路很小,像是半加器、4位元加法器, ![image](https://hackmd.io/_uploads/S1ozWGx-0.png) 可能還可以用手算出整個電路的延遲,但是電路如果複雜到例如 CPU、DSP,我們很難推算何時可以在輸出端取樣到想要的結果,因此才會需要時鐘訊號來同步各電路的運行,保證在時鐘訊號改變時能夠取樣到正確結果。 #### Backup 例如,一個 4bit 的加法器,我們想對他加上一個訊號 valid 用來表示該加法器已完成運算,我們可以另外增加一個 4bit 加法器計算 2'b1111 + 2'b1111 ,之後 assign valid == 該加法器的結果為 2'b1110 。 如下: ```verilog! module adder4( input[3:0] A, input[3:0] B, output Cout, output[3:0] S, ) assign {Cout, S} = A + B; endmodule; module adder4_async( input set_AB, input rst, input[3:0] A, input[3:0] B, output Cout, output[3:0] S, output reg valid ) reg [3:0] latched_A; reg [3:0] latched_B; reg valid_Cout; always_latch begin if(set_AB) begin latched_A <= A; latched_B <= B; end end always_latch begin if(rst) valid <= 0; else if(valid_Cout == 1) valid <= 1; end adder4 adder(latched_A, latched_B, Cout, S); adder4 valid_add(4'b1111 ,{3'b000, set_AB}, valid_Cout, 0); endmodule; ``` 以上是一個簡單的例子說明如何不用到 clk 透過 handshake 訊號表達電路以完成運作 。 #### 以下由 chatGPT 產生 ```verilog! module async_handshake_sender( input data, output ready_to_send, input ack ); // 状态定义 typedef enum logic [1:0] { IDLE, WAIT_ACK } state_t; state_t state; always @* begin case(state) IDLE: ready_to_send = 1'b1; // 处于空闲状态时,准备发送数据 WAIT_ACK: ready_to_send = 1'b0; // 等待确认信号时,暂停发送 default: ready_to_send = 1'b1; endcase end always @(posedge ack) begin if (state == WAIT_ACK) begin state <= IDLE; // 收到确认信号后返回空闲状态 end end always @(posedge data) begin state <= WAIT_ACK; // 发送数据后进入等待确认信号状态 end endmodule module async_handshake_receiver( input ready_to_receive, output data, input ack ); // 状态定义 typedef enum logic [1:0] { IDLE, DATA_RECEIVED } state_t; state_t state; always @* begin case(state) IDLE: data = 1'b0; // 处于空闲状态时,数据输出为0 DATA_RECEIVED: data = 1'b1; // 接收到数据后输出1 default: data = 1'b0; endcase end always @(posedge ready_to_receive) begin if (state == IDLE && ready_to_receive) begin state <= DATA_RECEIVED; // 准备接收时进入数据接收状态 end end always @(posedge ack) begin if (state == DATA_RECEIVED) begin state <= IDLE; // 收到确认信号后返回空闲状态 end end endmodule ``` # 我是易騰

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully