LoginSignup
0
0

More than 3 years have passed since last update.

XMC4800 Relax EtherCATキット ③EtherCATサンプルプログラムを動かす(スレーブー側事前準備)

Posted at

サンプルプログラムダウンロードとインポート

Infeneon社のDownload of Example Projects for DAVE™ AppsからサンプルプログラムETHCAT_SSC_XMC48.zipをダウンロードできます。
image.png

次にDaveを起動してサンプルプログラムをインポートします。サンプルプログラムのzipを展開したフォルダ内にある Getting Started - XMC4800_Relax_EtherCat_APP_Slave_SSC Example_V3.2.pdfを参照しながら進めます。
image.png
image.png
サンプルプログラムをzipのまま指定します。
image.png
インポート完了
image.png

EtherCAT SSC(Slave Stack Code)ツール入手

  • SSCツールはEtherCATのスレーブスタックのソースコードサンプルを自動で生成してくれるツールです(参照)。前記のサンプルプログラムはこれを使用することを前提として作られているため入手が必要となります。

  • ETG(EtherCAT Technology Group)のメンバーページにログインすることでダウンロード出来ます。※ETGメンバーには無料で加盟することができるそうですが、残念ながら法人しか加入できないみたいです。

スタックコードとESIファイル生成

サンプルプログラムはEtherCATのSSC¥Srcフォルダは空になっていますので、SSCツールを利用してソースコードとESIファイル(マスタに読み込ませるためのスレーブ情報を記載したXMLファイル)を生成します。
image.png
サンプルプログラムのzipを展開したフォルダ内にある Getting Started - XMC4800_Relax_EtherCat_APP_Slave_SSC Example_V3.2.pdfを参照しながら進めます。
新規プロジェクトを作成し、Daveで開いているサンプルプログラムのSSCフォルダ下にあるコンフィグファイルをインポートします。
image.png
image.png
次にSSCフォルダ下にあるにあるExcelファイルをインポートします。※この時PCにExcelがインストールされていないとインポートエラーが発生します。OpenOfficeやLibreOfficeなどの互換フリーツールでもエラーが出てインポートできません。
image.png
ソースコードとESIファイルを生成します。
image.png
成功すると、SSC\Srcフォルダ下にEtherCATスタックスレーブのソースコード(.h,.c)が生成され、SSCフォルダ下にESIファイルXMC_ESC.xmlが生成されています。Daveでリビルドしてエラーが出ないことを確認します。ESIファイルはマスター側でスレーブ情報を探せるようにするためC:\TwinCAT\3.1\Config\Io\EtherCATにコピーして置きます。
image.png
coeappl.cの下記の個所をエディタで修正します。
image.png

ソースコードの修正とビルド

サンプルプログラム動作のために生成されたコードの下記の個所を修正します。

入力

XMC_ESC.c
/////////////////////////////////////////////////////////////////////////////////////////
/**
\param      pData  pointer to input process data

\brief      This function will copies the inputs from the local memory to the ESC memory
            to the hardware
*////////////////////////////////////////////////////////////////////////////////////////
void APPL_InputMapping(UINT16* pData)
{
//#if _WIN32
//   #pragma message ("Warning: Implement input (Slave -> Master) mapping")
//#else
//    #warning "Implement input (Slave -> Master) mapping"
//#endif
    memcpy(pData, &(((UINT16 *)&IN_GENERIC0x6000)[1]), SIZEOF(IN_GENERIC0x6000)-2);
}

出力

XMC_ESC.c
/////////////////////////////////////////////////////////////////////////////////////////
/**
\param      pData  pointer to output process data

\brief    This function will copies the outputs from the ESC memory to the local memory
            to the hardware
*////////////////////////////////////////////////////////////////////////////////////////
void APPL_OutputMapping(UINT16* pData)
{
//#if _WIN32
//   #pragma message ("Warning: Implement output (Master -> Slave) mapping")
//#else
//    #warning "Implement output (Master -> Slave) mapping"
//#endif
    memcpy(&(((UINT16 *)&OUT_GENERIC0x7000)[1]), pData, SIZEOF(OUT_GENERIC0x7000)-2);
}

ユーザアプリ呼び出し

XMC_ESC.c
/////////////////////////////////////////////////////////////////////////////////////////
/**
\brief    This function will called from the synchronisation ISR 
            or from the mainloop if no synchronisation is supported
*////////////////////////////////////////////////////////////////////////////////////////
void process_app(TOBJ7000 *OUT_GENERIC, TOBJ6000 *IN_GENERIC);
void APPL_Application(void)
{
//#if _WIN32
//   #pragma message ("Warning: Implement the slave application")
//#else
//    #warning "Implement the slave application"
//#endif
    process_app(&OUT_GENERIC0x7000, &IN_GENERIC0x6000);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0