====== DI/DO の利用(Use of DI/DO) ======
\\
MA-X3xx シリーズは、
- 標準版(standard)(拡張なし、メインボード側): DI 2ch / DO 1ch
- DI/DO/AI 拡張(extended)(/LAD, 拡張ボード側): 1. に加えて、DI 24ch / DO 8ch
を使用することができます。
=== 標準版(standard) ===
{{:use_di_do:max3xx_dido_00.png|}}
=== /AD(extended) ===
{{:use_di_do:max3xx_dido_01.png|}}
{{:use_di_do:24ピン着脱式スクリューレス端子台.png?200|}}
※ /AD(extended)には24ピン着脱式スクリューレス端子台が同梱されています。
(Phoenix contact製 DMC 0,5/12-G1-2,54 P20 THR R72 接続ケーブルAWG26~AWG20対応)
\\
===== DI の使用(Use of DI) =====
==== 仕様 ====
=== 等価回路 ===
== メインボード側(standard) ==
{{:use_di_do:max3xx_dido_02.png|MA-X3xx DI 等価回路}}
== 拡張ボード側(extended) ==
{{:use_di_do:max3xx_dido_03.png|MA-X3xx DI 等価回路}}
DI 部はフォトカプラ及び電流制限抵抗により構成されています。また、外部電源の接続方法によりマイナスコモン、及びプラスコモンの機器と接続が可能です。\\
グループ毎に共通コモンとなっています。\\
(The DI section consists of a photocoupler and a current limiting resistor. Depending on the external power supply connection method, it can be connected to devices with negative common or positive common.
The common is common for each group.)
\\
==== アクセス ====
従来使用していた sysfs GPIO が deprecated で廃止予定のため、[[https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/|libgpiod]] を利用してアクセスします。\\
(Since sysfs GPIO used in the past is deprecated and scheduled to be discontinued, libgpiod is used for access.)
* [参考] [[https://www.thegoodpenguin.co.uk/blog/stop-using-sys-class-gpio-its-deprecated/|Stop using /sys/class/gpio – it’s deprecated]]
=== メインボード側(standard) ===
|<15em 3em 10em>|
^ No. ^ Name ^ Note |
| 1| DIN_S0 | |
| 2| DIN_S1 | |
=== 拡張ボード側(extended) ===
|<30em 3em 10em 10em 5em>|
^ No. ^ Name(フィルタ無) ^ Name(フィルタ有) ^ Note |
| 1| EXT_DI0 | Filtered_DI0 | A0|
| 2| EXT_DI1 | Filtered_DI1 | A1|
| ...| ... | ... | ...|
| 11| EXT_DI10 | Filtered_DI10 | C2|
| 12| EXT_DI11 | Filtered_DI11 | C3|
| 13| EXT_DI12 | Filtered_DI12 | D0|
| 14| EXT_DI13 | Filtered_DI13 | D1|
| ...| ... | ... | ...|
| 23| EXT_DI22 | Filtered_DI22 | F2|
| 24| EXT_DI23 | Filtered_DI23 | F3|
※ フィルタについて: 64Hz 2bit シフトレジスタ を利用したステートマシンによるチャタリング除去フィルタが入っています。\\
(About the filter: A state machine chatter removal filter using 64Hz 2bit shift registers is included.)
root@metis:~# gpioinfo |egrep "DIN_S|DI[0-9]+"
line 60: "DIN_S0" unused input active-high
line 61: "DIN_S1" unused input active-high
line 0: "EXT_DI12" unused input active-high
line 1: "EXT_DI13" unused input active-high
line 2: "EXT_DI14" unused input active-high
line 3: "EXT_DI15" unused input active-high
line 4: "EXT_DI16" unused input active-high
line 5: "EXT_DI17" unused input active-high
line 6: "EXT_DI18" unused input active-high
line 7: "EXT_DI19" unused input active-high
line 8: "EXT_DI20" unused input active-high
line 9: "EXT_DI21" unused input active-high
line 10: "EXT_DI22" unused input active-high
line 11: "EXT_DI23" unused input active-high
line 16: "Filtered_DI12" unused input active-high
line 17: "Filtered_DI13" unused input active-high
line 18: "Filtered_DI14" unused input active-high
line 19: "Filtered_DI15" unused input active-high
line 20: "Filtered_DI16" unused input active-high
line 21: "Filtered_DI17" unused input active-high
line 22: "Filtered_DI18" unused input active-high
line 23: "Filtered_DI19" unused input active-high
line 24: "Filtered_DI20" unused input active-high
line 25: "Filtered_DI21" unused input active-high
line 26: "Filtered_DI22" unused input active-high
line 27: "Filtered_DI23" unused input active-high
line 0: "EXT_DI0" unused input active-high
line 1: "EXT_DI1" unused input active-high
line 2: "EXT_DI2" unused input active-high
line 3: "EXT_DI3" unused input active-high
line 4: "EXT_DI4" unused input active-high
line 5: "EXT_DI5" unused input active-high
line 6: "EXT_DI6" unused input active-high
line 7: "EXT_DI7" unused input active-high
line 8: "EXT_DI8" unused input active-high
line 9: "EXT_DI9" unused input active-high
line 10: "EXT_DI10" unused input active-high
line 11: "EXT_DI11" unused input active-high
line 16: "Filtered_DI0" unused input active-high
line 17: "Filtered_DI1" unused input active-high
line 18: "Filtered_DI2" unused input active-high
line 19: "Filtered_DI3" unused input active-high
line 20: "Filtered_DI4" unused input active-high
line 21: "Filtered_DI5" unused input active-high
line 22: "Filtered_DI6" unused input active-high
line 23: "Filtered_DI7" unused input active-high
line 24: "Filtered_DI8" unused input active-high
line 25: "Filtered_DI9" unused input active-high
line 26: "Filtered_DI10" unused input active-high
line 27: "Filtered_DI11" unused input active-high
root@metis:~#
\\
==== gpiod のアプリケーションによるアクセス(Access by gpiod applications) ====
gpiod パッケージのアプリケーションでアクセスします。
=== GPIO の検索(GPIO Search) ===
root@metis:~# gpiofind EXT_DI10
gpiochip3 10
=== GPIO 値の読取(Read GPIO values) ===
root@metis:~# gpioget `gpiofind EXT_DI11`
0
root@metis:~#
\\
==== プログラムによるアクセス(Programmatic Access) ====
libgpiod を使用してプログラムを作成します。
* [参考] [[https://qiita.com/wancom/items/b041ee7408a87fabf48e|libgpiodの使い方 - Qiita]]
[[https://github.com/centurysys/nim_gpiod|Nim 用の binding]] を作成したので、C 言語より簡単にプログラムをすることもできます。
import std/asyncdispatch
import std/times
import nim_gpiod
proc asyncMain() {.async.} =
let di0 = newGpio("DIN_S0", "NimGPIO")
if di0.isNil:
echo "newGpio failed."
quit(1)
while true:
echo "wait event..."
let event = await di0.wait_event(Edge.Both, 10)
let now = now().format("yyyy-MM-dd HH:mm:ss")
echo &"*** {now}: Event! (edge: {event.edge}, value: {event.value})"
waitFor asyncMain()
\\
===== DO の使用(Use of DO) =====
==== 仕様 ====
=== 等価回路 ===
== メインボード側(standard) ==
{{:use_di_do:max3xx_dido_05.png|DO 等価回路}}
== 拡張ボード側(extended) ==
{{:use_di_do:max3xx_dido_06.png|DO 等価回路}}
DO 部はフォトカプラ及び過電流保護素子により構成されています。グループ毎に共通コモンとなっています。\\
(The DO section consists of a photocoupler and an overcurrent protection element. Each group has a common common.)
\\
==== アクセス(Access) ===
LED class driver にバインドしています。(Bound to LED class driver.)
root@metis:/sys/class/leds# ls
ADC_Power EXT_DO0 EXT_DO6 MSP430_EXT2_TEST MobileLED_R0 PowerLED:G system-status1:g
ADC_RESET EXT_DO1 EXT_DO7 MSP430_RST MobileLED_R1 SHUTDOWN_REQ system-status1:r
ConsoleEnable EXT_DO2 LED_Drv_Enable MSP430_TEST MobileLED_R2 USBHub_Reset system-status2:g
DO_S0 EXT_DO3 MSP430_EXT1_RST MobileLED_G0 PCIe_Power mmc0:: system-status2:r
DO_T0 EXT_DO4 MSP430_EXT1_TEST MobileLED_G1 PHY0_Reset mmc1:: system-status3:g
EXT_24V_ON EXT_DO5 MSP430_EXT2_RST MobileLED_G2 PHY1_Reset power-stat:r system-status3:r
=== メインボード側(standard) ===
|<15em 3em 10em>|
^ No. ^ Name ^ Note |
| 1| DO_S0 | |
=== 拡張ボード側(extended) ===
|<15em 3em 10em>|
^ No. ^ Name ^ Note |
| 1| EXT_DO0 | |
| ...| ... | |
| 8| EXT_DO7 | |