Shenzhen IO - Passive Infrared Sensor - Solution

Shenzhen I/O – Passive Infrared Sensor

I think we are at problem number 7 in Shezhen I/O where we are asked to help a security company design a passive infrared sensor that will trigger an alarm between a given time interval, if there is too much activity. We are given a problem where were have the a simple sensor input and a simple alarm output. We also have a simple input giving us time. Further more we have 2 xbus inputs giving us the on and off times. The problem description is simple enough, if the timer is between the on and off time (loop) and the sensor reading is 20 or higher we should trigger the alarm. Just like the signals here tells us

Shenzhen IO - Passive Infrared Sensor - signals

Structure of the passive infrared sensor

I already used the trick of a DX300 last time to convert between an xbus signal and a simple output that only flips on and off. So if we use that again we have 2 simple pins and 3 xbus pins. Which means that a MC6000 can cover all of it, if there is enough room for the lines of codes needed.  But let us start coding based on the following structure of the design.Shenzhen IO - Passive Infrared Sensor - structure

Coding the thing

Since the timing if cyclical I haven’t found a way to just check if the time if between the two, since it varies in the different test cases. On the other hand the clock never skips a beat. So we can just flip a switch whenever the time equals the on or off time. I have used the acc register for it, and used the following code

# Check turn on
  teq p1 x0
+ mov 100 acc  
# Check turn off
  teq p1 x1
+ mov 0 acc

That means we know that if the acc is 100 then the sensor is active. Actually checking whether the alarm should be triggered is fairly trivial and uses the code.

  tgt acc 0
+ tgt p0 19
+ mov 10 x2
- mov 0 x2
  slp 1

We start by checking if we are activated. If that is the case we check if the signal is larger then 19, since we need to trigger if the signal is 20 or higher. If that is the case. We will move 10 to x2 as the connection gives us a 100 on the output side for that, and then sleep. If we shouldn’t trigger we will move 0 to x2.

In total that gives us 9 lines of code plus a few comments. Easily fittable withing the available 14 lines of code that we can put into the MC6000 unit.

All in all that means the solution will look like

Shenzhen IO - Passive Infrared Sensor - Solution

This gives us a solution in

Cost: 6
Energy: 358
Lines of code: 9

I know that some managed to find a solution in fewer lines of code, but I cannot figure out how to do that.

Posted by Kristian

1 comment

8 lines:

teq p1 x3
+ not

teq p1 x2
+ not

tlt p0 20
+ mov 0 x0
– mov acc x0

slp 1

Leave a Reply