2022-02-13
Part of my journey through Shenzhen I/O
Problem: time
is a simple input connected to a clock that provides the current time. on-time
and off-time
are XBus inputs that specify the time at which the alarm should be enabled and disabled, respectively. sensor
is a simple input that indicates the level of infrared detected. alarm
is a simple output that enables the alarm when 100
is sent to it. If the alarm is enabled and the sensor detects a value of 20 or higher, the alarm should be enabled.
This one was tricky because of the number of inputs. My strategy was to to use a MC6000 to determine whether the system is armed or not.
p1
is connected totime
to provide the current time.x1
is connected toon-time
x2
is connected tooff-time
x3
is connected to the downstream chip that looks at the sensor and triggers the alarm.
To detect whether the system is armed, it stores 100
in acc
when the current time matches on-time
, and stores 0
in acc
when the current time matches the off-time
. It then moves the value of acc
to x3
for consumption downstream.
teq p1 x1
+ mov 100 acc
teq p1 x2
+ mov 0 acc
mov acc x3
slp 1
The logic to trip the alarm reads this value from x0
, and looks at p0
for the value of sensor
, and outputs the alarm state to p1
, which is connected to alarm
.
loop:
teq x0 100
- mov 0 p1
- slp 1
- jmp loop
+ tgt p0 19
+ mov 100 p1
- mov 0 p1
slp 1
Cost is ¥8, power usage is 481, and 14 lines of code are necessary.