{"id":15069,"date":"2024-10-06T15:17:34","date_gmt":"2024-10-06T15:17:34","guid":{"rendered":"https:\/\/www.qec.tw\/?p=15069"},"modified":"2024-10-06T15:17:35","modified_gmt":"2024-10-06T15:17:35","slug":"configencodermode","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/ethercat\/api\/dmp\/stepper-dmp\/configencodermode\/","title":{"rendered":"EthercatDevice_DmpStepper.configEncoderMode()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[EthercatDevice_DmpStepper_Generic]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Configure the encoder mode of the specified encoder on the EtherCAT slave device. This parameter is written to the EEPROM of the EtherCAT slave device and loaded during startup, so users do not need to configure this parameter each time before running the program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This EtherCAT slave device supports a total of six encoder modes, as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pulse\/DIR (<em>1-Pulse<\/em> mode)<br>This mode is also known as <em>1-Pulse<\/em> mode and has two input pins for accepting signals from the encoder: the <em>Pulse<\/em> input and the <em>DIR<\/em> input. The <em>Pulse<\/em> input is used to count the number of pulses from the encoder, and the <em>DIR<\/em> input is used to indicate the current counting direction of the encoder counter. In this mode, the counter only counts on the rising edge of the <em>Pulse<\/em> input.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1004\" height=\"472\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5.png\" alt=\"configEncoderMode-1\" class=\"wp-image-15075\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5-768x361.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-5-600x282.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CW\/CCW (<em>2-Pulse<\/em> mode)<br>This mode is also known as <em>2-Pulse<\/em> mode. It has two input pins for accepting signals from the encoder: the <em>CW<\/em> input and the <em>CCW<\/em> input. The pulses from the <em>CW<\/em> input represent the number of pulses counted in the forward direction by the encoder counter, while the pulses from the <em>CCW<\/em> input represent the number of pulses counted in the reverse direction by the encoder counter. In this mode, the counter only counts on the rising edge of the <em>CW<\/em> and <em>CCW<\/em> inputs.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"943\" height=\"443\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4.png\" alt=\"configEncoderMode-2\" class=\"wp-image-15074\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4.png 943w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4-768x361.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-4-600x282.png 600w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pulse A\/B (<em>QEI<\/em> mode)<br>This mode is also known as <em>QEI (Quadrature Encoder Interface)<\/em> mode. It has two input pins for accepting signals from the encoder: the <em>Pulse A<\/em> input and the <em>Pulse B<\/em> input. The <em>Pulse A<\/em> and <em>Pulse B<\/em> inputs have a unique relationship. If <em>Pulse A<\/em> leads <em>Pulse B<\/em>, the counting direction is deemed forward. If <em>Pulse A<\/em> lags <em>Pulse B<\/em>, the counting direction is deemed reverse. In this mode, the counter only counts on the rising and falling edges of the <em>Pulse A<\/em> input.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"941\" height=\"443\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3.png\" alt=\"configEncoderMode-3\" class=\"wp-image-15073\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3.png 941w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3-768x362.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-3-600x282.png 600w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pulse\/DIR x2<br>This mode is similar to <strong>Pulse\/DIR<\/strong> mode, with the only difference being that the counter in this mode counts on both the rising and falling edges of the <em>Pulse<\/em> input.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"473\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2.png\" alt=\"configEncoderMode-4\" class=\"wp-image-15072\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2-768x362.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-2-600x283.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CW\/CCW x2<br>This mode is similar to <strong>CW\/CCW<\/strong> mode, with the only difference being that the counter in this mode counts on both the rising and falling edges of the <em>CW<\/em> and <em>CCW<\/em> inputs.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"471\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1.png\" alt=\"configEncoderMode-5\" class=\"wp-image-15071\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1-768x360.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-1-600x281.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pulse A\/B x2<br>This mode is similar to <strong>Pulse A\/B<\/strong> mode, with the only difference being that the counter in this mode counts on both the rising and falling edges of the <em>Pulse A<\/em> and <em>Pulse B<\/em> inputs.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"471\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image.png\" alt=\"configEncoderMode-6\" class=\"wp-image-15070\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-300x141.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-768x360.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-18x8.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2024\/10\/image-600x281.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Derived Class:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td>Class Name<\/td><td>Vendor ID<\/td><td>Product Code<\/td><\/tr><tr><td>EthercatDevice_QECR11MP3S<\/td><td>0x00000bc3<\/td><td>0x0086d0d6<\/td><\/tr><tr><td>EthercatDevice_QECR00MP3S<\/td><td>0x00000bc3<\/td><td>0x0086d0d9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int configEncoderMode(int encoder, uint8_t mode);<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parameters<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>[in] int encoder<\/code><br>The specified encoder number:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Definition<\/strong><\/td><td><strong>Value<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>ECAT_ENCODER_1<\/td><td>0x01<\/td><td>Encoder 1 on the EtherCAT slave device.<\/td><\/tr><tr><td>ECAT_ENCODER_2<\/td><td>0x02<\/td><td>Encoder 2 on the EtherCAT slave device.<\/td><\/tr><tr><td>ECAT_ENCODER_3<\/td><td>0x03<\/td><td>Encoder 3 on the EtherCAT slave device.<\/td><\/tr><tr><td>ECAT_ENCODER_X<\/td><td>0x11<\/td><td>Encoder X, which mapping is determined by the <code>configMachineAxisMapping()<\/code>.<\/td><\/tr><tr><td>ECAT_ENCODER_Y<\/td><td>0x12<\/td><td>Encoder Y, which mapping is determined by the <code>configMachineAxisMapping()<\/code>.<\/td><\/tr><tr><td>ECAT_ENCODER_Z<\/td><td>0x13<\/td><td>Encoder Z, which mapping is determined by the <code>configMachineAxisMapping()<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>[in] uint8_t mode<\/code><br>The encoder mode to be configured. Users can select from six encoder modes, as detailed in the table below. For input values not listed in the table, the default configuration will be ECAT_ENCODER_MODE_AB_PHASE_x2.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Definition<\/strong><\/td><td><strong>Value<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>ECAT_ENCODER_MODE_STEP_DIR<\/td><td>0<\/td><td>Please see Pulse\/DIR mode.<\/td><\/tr><tr><td>ECAT_ENCODER_MODE_CWCCW<\/td><td>1<\/td><td>Please see CW\/CCW mode.<\/td><\/tr><tr><td>ECAT_ENCODER_MODE_AB_PHASE<\/td><td>2<\/td><td>Please see Pulse A\/B mode.<\/td><\/tr><tr><td>ECAT_ENCODER_MODE_STEP_DIR_x2<\/td><td>5<\/td><td>Please see Pulse\/DIR x2 mode.<\/td><\/tr><tr><td>ECAT_ENCODER_MODE_CWCCW_x2<\/td><td>6<\/td><td>Please see CW\/CCW x2 mode.<\/td><\/tr><tr><td>ECAT_ENCODER_MODE_AB_PHASE_x2<\/td><td>7<\/td><td>Please see Pulse A\/B x2 mode.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Return Value<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Return an <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/error-code\/\">error code<\/a>. If the returned value is zero, it indicates a successful execution of this function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This function must be called after a successful execution of <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/master\/ethercatmaster-begin\/\"><code>EthercatMaster::begin()<\/code><\/a>. This function is blocking and cannot be called within the callback functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &quot;Ethercat.h&quot;\n\nEthercatMaster master;\nEthercatDevice_QECR11MP3S slave;\n\nvoid setup() {\n  master.begin();\n  slave.attach(0, master);\n\n  slave.configEncoderMode(ECAT_ENCODER_1, ECAT_ENCODER_MODE_AB_PHASE_x2);\n  slave.configEncoderMode(ECAT_ENCODER_2, ECAT_ENCODER_MODE_AB_PHASE_x2);\n  slave.configEncoderMode(ECAT_ENCODER_3, ECAT_ENCODER_MODE_AB_PHASE_x2);\n  \/\/ ...\n}\n\nvoid loop() {\n  \/\/ ...\n}<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Please see\u00a0<a href=\"https:\/\/www.qec.tw\/ethercat\/api\/dmp\/stepper-dmp\/\">EthercatDevice_DmpStepper_Generic Class<\/a>\u00a0for more QEC Stepper Drivers instructions and API usage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[EthercatDevice_DmpStepper_Generic] Description Configure the encoder mode of the specified encoder on the EtherCAT slave device. This parameter is written to the EEPROM of the EtherCAT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":15076,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[277],"tags":[162,54,191],"class_list":["post-15069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stepper-dmp","tag-86duino","tag-ethercat","tag-qec"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/15069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/comments?post=15069"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/15069\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/15076"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=15069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=15069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=15069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}