YU-SHIH-PENG
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    6
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `EtherCAT` # EtherCAT從零開始了解 ## EtherCAT簡介 EtherCAT是透過Ethernet來做控制傳輸來達到多設備自動化控制的乙太網控制技術。控制為常見的Master(控制中心)Slave(設備)架構(如圖一),但不需要高價專用硬體介面卡,只需要一張乙太網卡即可實現,因此成本很低。 連線方式部份符合IEEE802.3標準乙太網資料封包格式,Master會發送一長串資料電訊報文,在資料電訊報文經過終端設備(Slave)時會判定其對應位置將對應資料給予終端設備,資料插入終端設備後同時終端設備會將其自身資料插入這一長串電訊報文,完成資料交換後,接著往下一個Slave移動。而下一個Slave也會針對其對應資料做資料交換。在這過程([YT影片參考](https://www.youtube.com/watch?v=ZPDM71l47dE)),終端設備無須接收整個乙太網資料封包,故不需要針對封包做做解碼程序,整個讀取作業只需要us等級的時間延遲,進而達到精確同步低延遲的控制。 因EeherCAT具低成本、優越的同步性能與簡易操作配置的特點。目前已廣泛運用於機械設計、運動控制等各式自動化還有工業領域用途場合。 ![](https://i.imgur.com/nF4GW4M.png) <center>圖一、EtherCAT主從架構</center> ## EtherCAT與傳統Ethernet不同 EtherCAT傳輸與傳統Ethernet傳輸方式不同,在傳統Ethernet傳輸,Master將資料傳送至Slave後,Slave CPU須對資料做解析,接著做一部份的分解看那些資料是屬於自己要的Command命令,哪些是控制IO命令。接著再針對IO命令做控制。整個延遲時間較長,且不可控(Master純給指令,但解析對應還需要透過Slave協助)。另外多Slave要做連結、轉發或擴增網絡,則需透過交換機實現,但交換機基本上都是使用存儲轉發架構,延時時間較長且有一定的負載程度,超過負載有資料掉包的問題。 EtherCAT雖說是另一種協定,但OSI物理層基本上與Ethernet是雷同的,差在EtherType不同,Ethernet根據Ethernet Type IPV4與IPV6設置分別為0x8000與0x86DD。而EtherCAT則為0x88A4。除了不須透過交換機串聯不同Slave設備外,傳輸資料的方式以on the fly原理,將乙太網資料封包像一台快速移動的火車不停站的方式通過每個Slave站點去做資料交換,接著回到Master(如下圖二)。這過程訊息會不停循環發送。過程中因為協定統一,Slave不需要再做額外的解析工作,且也不須透過交換機,因此可大大減少延遲時間。 ![](https://i.imgur.com/DGn2hsi.png) <center>圖二、EtherCAT資料傳輸</center> 上述簡易描述完後,下述稍微整理三個差異性 ### Bandwidth使用效率 Ethernet的Bandwidth使用效率較低,我們可以看下圖三乙太網Frame結構如下圖三,如果每發一個Ethernet Data Frame資料,最少82 byte。但通常工業現場控制領域,在大多時候IO控制或是命令控制不需要這麼多byte,如果控制數據只需要4bytes,那Bandwidth使用率只有 4/82 約4.87%。 ![](https://i.imgur.com/0LxLZUc.png) <center>圖三、Ethernet Data Frame Format</center> EtherCAT Format,相比起來Ethernet,在Data段可以塞多個Slave設備資料bytes,在Bandwidth就有較好的使用率。 ### Stack大小和延遲 下圖四為Protocol Stack,左圖可看到網口物理層進去後通過乙太網卡的MAC到TCP/IP協議層,接著將Data Frame進一步封裝後到CIP(Control & Information Protocol)層繼續做封裝成CIP報文(顯示報文:配置、隱式報文:IO),接著在網上到CIP Module與實際設備的配置。可以看到一個數據進來後,要經過很多層的處理才可以到I/O接口。 但普通I/O傳輸與純工業領域設備控制大多其實不太需要這樣處理IP封包,EtherCAT針對這點將這些不需要的協議處理去除,在網口資料進來後,不須做這些步驟,即可直接對應I/O接口端直接做控制。相對起來較少的Stack層的處理大大減少整體的延遲時間。 ![](https://i.imgur.com/aFXWkwZ.png) <center>圖四、Protocol Stack</center> ### 交換機延 在乙太網中,會常使用交換機去擴展網絡,讓不同設備可以透過網絡去互相溝通。但交換機通常會是存儲轉發架構,會將收到的封包先做存取,再去查找地址表,查到後再找相應的接口去轉發,有一定的緩衝區延遲時間與抖動。另外交換機有一定的負載,負載過大就會有資料丟包的問題。 ![](https://i.imgur.com/3iV6QSR.png) <center>圖五、交換機架構</center> EtherCAT不須透過交換機即可跟不同Slave設備直接溝通。如下圖六右,故沒有交換機性能上的問題。 ![](https://i.imgur.com/MT5XkAL.png) <center>圖六、Ethernet與EtherCAT主從架構</center> ## EtherCAT Data Format 上述簡述完後,應該可以對EtherCAT傳送方式與一般傳統的Ethernet控制差異性有所了解。接著我們可以開始探討他的封包格式,如下圖七EthterCAT最底層會與原始Ethernet物理層格式相同(1),差在Ethernet Header的EtherType為0x88a4 (2)。接著放大Data段(3),可以看到EtherCAT格式在Data段由一個Header與Datagrams組成,而Datagrams可包含n個Slave Datagram封包(4),此協定格式因此可提高Bandwidth使用率。 在解析(4)完後針對Datagram在放到進到解析(5)步驟,可看到每個Slave的Format格式由Header、Data與WKC組成,放大Header(6)可看到他是由Cmd、Index與Address組成,在EhterCAT設置命令上會根據Slave設備設定有不同的Command命令,每個Command命令都有他的Object Index數值,對應他要給的實際數值(Data)。Address則是Slave的位址,這部分通常處理會由EtherCAT晶片模組幫你處理好,不用特別去設置。一般設置上大多只需要針對Cmd、Index與Data去設置即可。WKC為Working Counter,保證讀寫成功的一個紀錄器,當Slave讀取成功後WKC會加一,寫入成功則是加二,當經過多個Slave做讀寫後回到Master,Master會根據WKC的Counter去判定是否有讀寫成功。 ![](https://i.imgur.com/XXfMk4p.png) <center>圖七、EtherCAT封包格式</center> ## EtherCAT 軟體架構Over View 基本上使用上不太需要去了解EtherCAT的軟體內部架構,但這邊還是稍微提一下。基本上Master與Slave都有Process Data與Mailbox設置,下圖八為Master軟體架構示意。Process Data Service是週期性的資料傳輸,會根據週期時間定期發送資料到Slave,而Mailbox資料則是非週期性資料,要觸發才會做資料的寫入與讀取。基本上我們可以透過SDO(Service Data Object)去設定Mailbox與Process Data的Object資料設定。在設定好後,在Operational模式下(下章節會提到狀態機),PDO則會週期的透過Ap層發送與接收資料,同時也可以透過SDO去讀且Slave資料。 ![](https://i.imgur.com/hXDJ87m.png) <center>圖八、EtherCAT Master軟體架構示意</center> 下圖九為Slave的軟體架構示意,我們一樣可以專注在Mailbox與Process Data上探討。當Master傳送給Slave後,會有一個Mapping功能對應表(Data Object與PDO Mapping)透過轉換後再經過Ap層到設備上做實際控制。 ![](https://i.imgur.com/WjDaFeE.png) <center>圖九、EtherCAT Slave軟體架構示意</center> ## EtherCAT Slave地址搜尋與FMMU ### 搜尋地址方法 此章節講Master與Slave位址搜尋匹配方法,分類上基本上有下圖十幾項,基本上透過網路搜尋(網段尋址)部門上比較少用,大部分使用狀況設備都會在同一個網段操作。而如果用現成的EtherCAT Module,大部分都會是設備搜尋(設備尋址)分類下的順序搜尋(順序尋址),Master在Ethernet線連上設備後,會自動匹配所連設備,每個站點地址會自動加1去設置,整個過程不需要透過手動設置位置。而設置搜尋(設置尋址)則是透過手動刻意去指定,因此順序跟連結順序就沒有關係,但須注意設備重開關後,原本設置的位址就會消失(如下圖十一順序比較)。邏輯尋址部分,基本上EtherCAT晶片都會幫你處理掉,做的是OP中透過FMMU來交換資料,邏輯尋址晶片做掉了,所以user不用去解析這邊, 只要知道PDO傳了什麼資料就好了。 ![](https://i.imgur.com/7D4Ba7S.png) <center>圖十、EtherCAT Master Slave位址搜尋方法</center> ![](https://i.imgur.com/ASnd09W.png) <center>圖十一、順序位址搜尋與設置為只搜尋比較</center> ### FMMU (Fieldbus Memory Management Unit) FMMU在搜尋Slave地址中是很重要的一環,負責做邏輯地址與實體地址的轉換對應,如果是用現成EtherCAT模組或IC,大部分狀況這一塊會幫你處理好,使用者大多只需要專注在PDO與Mailbox設置,這裡就不多提。 ## EtherCAT SyncManager資料同步處理、Object分類、PDO與SDO ### SyncManager SyncManager負責Master與Slave資料同步的機制,一般有兩種方式,一個是使用Mailbox另一個方式是使用緩存。對User來說較常見直接使用前者,後者大多則是現有晶片也會幫你處理掉,對使用者來說只需純粹去做設定即可。 同步分類通常會有四種SyncManager服務物件,Sync Manager0與Manager1負責Mailbox的輸出與輸入。在User操作上不用直接對於這兩者物件操作,大多會操作Sync Manager2與Manager3。 - Sync Manager2(1C12):負責同步Master給予Slave資料,管理多組RxPDO - Sync Manager3(1C13):負責同步Slave給予Master資料,管理多組TxPDO 這Sync2與Sync3管理,都有其對應的Object Index數值,大多設定上述值為1C12與1C13。。在EtherCAT裡面會有許多不同的Object分類,每種分類Object都有一個Index數值,例如剛提到的RxPDO與PxPDO,也有其對應的Object Index數值。我們在設置上與設定資料過程中,會根據Object Index值去設置實際資料。 以Sync Manager 2 為例子,有些設備是允許在Sync Manager 2設置多組RxPDO(PDO是什麼下章節回提到)的。例如單Slave馬達的多軸控制器,他會是一個多組PDO架構。第一軸對應第一個PDO設定,第二軸對應第二個PDO設定。如果要設置2組PDO,可以針對1C12這個位置,給予2這個數值。Sync Manager 2就能同時管理2組PDO Master給予Slave的同步資料。 ### Object分類、PDO、SDO Sync Manager後接著就要了解在文件常見的PDO與SDO。分別為程序資料物件與服務資料物件。前者放置週期性要發送的資料,後者用於組態設定,如節點位置、ID、通訊速度之類的,或是透過Mailbox讀寫資料。 PDO這邊又分成三種Object設定,分別是Assignment Object、Mapping Object與Application Object。 Assignment Object為上一章節提到的Sync Manager,PDO設置上使用的為1C12的Sync2與1C13的Sync3。而一個Assignment可以放置多個Mapping Object,RxPDO放置在1C12而TxPDO放置在1C13。Mapping Object用於放置多個設備實際功能的Application Object設置。Slave設備會根據不同的功能有不同的Application Object Index,例如常見的馬達位置為0x607A與馬達速度0x60FF。其對應關係如下圖十二,紅框部分為Assignment Object,藍框部分為Mapping Object而綠框部分則為Application Object。 ![](https://i.imgur.com/N8VIu7i.png) <center>圖十二、Object關係圖</center> 基本上設置格式如下圖十三,由Object Index、Sub-Index與Length組成。設置方法。 ![](https://i.imgur.com/tZQMgt9.png) <center>圖十三、Object Format</center> 而每個Object都有其Sub-Index定義,我們以Sync2 1C12為例,定義如下圖十四,Sub-Index 0這個位置是設置要幾個Mapping PDO,上限會有5個。故如果我們要設置2個Mapping PDO(1600與1610)。根據上述格式給予資料步驟為 Step1(W):Object Index:1C12,Sub-Index:0,Length:1byte,Value:0 (歸0) Step2(W):Object Index:1C12,Sub-Index:1,Length:2byte,Value:1600(放置Mapping Object) Step3(W):Object Index:1C12,Sub-Index:2,Length:2byte,Value:1610(放置Mapping Object) Step4(W):Object Index:1C12,Sub-Index:0,Length:1byte,Value:2 (2組RxPDO) ![](https://i.imgur.com/bjzXRXQ.png) <center>圖十四、Sync 2 Definition Sample</center> 接著我們以Mapping Object為例,例如東方馬達HM系列1600定義如下圖十五,東方馬達的1600 Mapping Object最多可以容納8個Application Object,而他初始使用會有6040、607A與6060三個Application Object,功能上分別為功能設置、馬達位置、運行模式三種功能。當設好這三個Mapping Object數值後,進入安全運行或是運行模式,就會不停發送這三個Application Object定義與數值給馬達設備端。 ![](https://i.imgur.com/icLghhy.png) <center>圖十五、Mapping Object Sample</center> 透過上述描述,大致可以理解EtherCAT資料同步物件設定上的彼此關係及大概地設置方式。詳細還需要根據不同的Slave操作定義去實作。 ## EtherCAT 狀態機 EtherCAT有狀態機操作切換,為EtherCAT非常重要的環節,如下圖八,一般要在Operational模式下才可正常傳送資料。如果無法進入Operational,代表目前EtherCAT目前有問題。 ![](https://i.imgur.com/tmK4CHx.png) <center>圖十六、EtherCAT狀態機</center> - Init: Application、Mailbox與Process Data皆無通訊資料 - Pre-Operational: Application層開始與Mailbox通訊,但還沒對外做數據通訊,此狀態只能配置系統參數,不然發送與接受資料。 - Safe-Operational: 不對外輸出,但可以接受Slave的數據。 - Operational: 可正常做讀寫通訊。 - Bootstrap: 一般情況下用不太到,只有更新時會使用。 下圖為東方馬達整理在不同狀態下PDO與SDO是否能使用的整理表格。狀態是很重要的一個設定環節,會關係,在運行做成中是否能正確在對的狀態做對的事情。 ![](https://i.imgur.com/US4rFby.png) <center>圖十七、EtherCAT狀態機SDO與PDO可使用時機</center> ## EtherCAT 故障與Redundancy設置 當Slave故障斷點時,後面的站點會自動進入安全模式,而Master會自動判定從沒斷的Slave回流資料。 ![](https://i.imgur.com/4GOutmX.png) <center>圖十八、EtherCAT串接中斷</center> 大部分控制都會串接模式,若在串接下要設置Redundancy機制,需透過兩張網卡,架構如下,當中間斷掉後,所有Slave功能皆可正常繼續使用。但如果斷兩節,就如上述連不到,斷掉的Slave會自行進入Safe-Operational模式,此模式下只能接收資料不會再主動發送資料。 ![](https://i.imgur.com/Xbnzo3I.png)

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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