MA-E3xx シリーズでは CPLD により実装していた、チャタリング除去フィルター、カウンター の機能をマイコンで実装しています。
機能は I2C 経由(Bus No.1, I2C-Address 0x4f)で利用します。
DI 機能は I2C の下記アドレスにマップされています。
Name | Address | Bit | Reset Value | Description |
---|---|---|---|---|
Filtered DI(R/O) | 0x06 | [7:5] Reserved | ||
[4] OPT-Switch | OPT-Switch | |||
[3:0] DI3..0 | DI Status1) | |||
DI Polarity(R/W) | 0x0b | [7:5] Reserved | xxx | |
[4] OPT-Switch | x | OPT-Switch2) | ||
[3:0] DI3..0 Polarity | 0000 | 0: Rising / 1: Falling | ||
Counter Control (R/W) | 0x10 | [7:5] Reserved | xxx | |
[4] Counter4 Start (OPT-Switch) | 0 | 1: Enable | ||
[3] Counter3 Start | 0 | |||
[2] Counter2 Start | 0 | |||
[1] Counter1 Start | 0 | |||
[0] Counter0 Start | 0 | |||
Counter Match Enable (R/W) | 0x11 | [7:5] Reserved | xxx | |
[4] Counter4 Match Event Enable | 0 | 1: Enable | ||
[3] Counter3 Match Event Enable | 0 | |||
[2] Counter2 Match Event Enable | 0 | |||
[1] Counter1 Match Event Enable | 0 | |||
[0] Counter0 Match Event Enable | 0 | |||
Counter Match Status (R/W1c) | 0x12 | [7:5] Reserved | xxx | |
[4] Counter4 Match | 0 | 1: Match / Write 1 to clear | ||
[3] Counter3 Match | 0 | |||
[2] Counter2 Match | 0 | |||
[1] Counter1 Match | 0 | |||
[0] Counter0 Match | 0 | |||
Counter Compare0 (R/W) | 0x13 | [7:0] | 00000000 | |
Counter Compare1 (R/W) | 0x14 | [7:0] | 00000000 | |
Counter Compare2 (R/W) | 0x15 | [7:0] | 00000000 | |
Counter Compare3 (R/W) | 0x16 | [7:0] | 00000000 | |
Counter Compare4 (R/W) | 0x17 | [7:0] | 00000000 | |
Counter Value0 (R/W) | 0x18 | [7:0] | 00000000 | |
Counter Value1 (R/W) | 0x19 | [7:0] | 00000000 | |
Counter Value2 (R/W) | 0x1a | [7:0] | 00000000 | |
Counter Value3 (R/W) | 0x1b | [7:0] | 00000000 | |
Counter Value4 (R/W) | 0x1c | [7:0] | 00000000 |
File | Stat | SHA1SUM | Info |
---|---|---|---|
libdi.tar.gz | 2021/11/15 13:31 3.1 KB | c23c8d6bffaac9249ea8d2f0be51c049a307c46a | DI サンプル |
import std/options
import std/strformat
import lib/msp430
proc main() =
# ライブラリ初期化
let di = newMsp430(1, 0x4f)
# Read DI Status
let di_stat_opt = di.get_di_status()
if di_stat_opt.isSome:
echo &"* DI Value: {di_stat_opt.get()}"
# Read DI Polarity
let di_pol_opt = di.get_di_polarity()
if di_pol_opt.isSome:
echo &"* DI Polarity: {di_pol_opt.get()}"
for idx in countUp(0, 4):
# Read DI Counter Enable
let enable_opt = di.get_counter_onoff(idx)
if not enable_opt.isSome:
continue
let enable = enable_opt.get()
if enable:
echo &"* DI[{idx}] Counter is enable."
else:
# Enable DI Counter
let res = di.onoff_counter(idx, true)
echo &"* DI[{idx}] Counter: set enable -> result: {res}"
# Read DI Counter Value
let val_opt = di.get_counter_val(idx)
if val_opt.isSome:
let val = val_opt.get()
echo &"* DI[{idx}] Counter Value: 0x{val:02x}"
when isMainModule:
main()
root@gemini:~# /tmp/di_sample * DI Value: @[0, 0, 0, 0, 0] * DI Polarity: @[Rising, Rising, Rising, Rising, Rising] * DI[0] Counter: set enable -> result: true * DI[0] Counter Value: 0x00 * DI[1] Counter: set enable -> result: true * DI[1] Counter Value: 0x00 * DI[2] Counter: set enable -> result: true * DI[2] Counter Value: 0x00 * DI[3] Counter: set enable -> result: true * DI[3] Counter Value: 0x00 * DI[4] Counter: set enable -> result: true * DI[4] Counter Value: 0x00 root@gemini:~# /tmp/di_sample * DI Value: @[0, 0, 0, 0, 0] * DI Polarity: @[Rising, Rising, Rising, Rising, Rising] * DI[0] Counter is enable. * DI[0] Counter Value: 0x00 * DI[1] Counter is enable. * DI[1] Counter Value: 0x00 * DI[2] Counter is enable. * DI[2] Counter Value: 0x00 * DI[3] Counter is enable. * DI[3] Counter Value: 0x00 * DI[4] Counter is enable. * DI[4] Counter Value: 0x04 <----- OPT-Switch をポチポチ押した