Shenzhen I/O – Virtual Reality Buzzer

VR is the next big thing, everyone agrees to that. And so does the employees in Shenzhen Longteng Electronics Company Ltd.. But once you are emerged you don’t notice if someone sneaks up on you. Therefore David really wants us to make a small buzzer for him that he can strap to his VR goggles to notify him if there is someone approaching him – aptly named the virtual reality buzzer.

We get readings from a non-blocking xbus port on a radio. If that is one then we should start the buzzer generating pulses of 1 width. If it is zero we should stop the buzzer again. And so on. If the reading is -999 we should just continue what we are doing. This results in the following verification signals.

Shenzhen IO - Virtual Reality Buzzer - signals

First attempt at a virtual reality buzzer

We only need one xbus input and one simple output, so if we are able to put it all into 9 lines of code and 1 register, we should be able to fit it into an MC4000.

I’m thinking the design would be something like, store whether we should buzz or not in the acc. So start by checking the radio if we should change mode, update the acc, and then execute the command. The first thing to note is that the radio output can be either -999, 0 or 1. Which means that we could probably use a construct that I haven’t used before. the tcp command.

The tcp command takes two inputs a and b – and comes with the following execution model

Condition Effect on ‘+’ Instructions Effect on ‘-’ Instructions
 A is greater than B  Enabled Disabled
 A is equal to B  Disabled  Disabled
 A is less than B  Disabled   Enabled

So we test if the radio signal is equal to 0. Then we have three cases: -999 we execute all the commands marked with -. 0 we only execute unmarked lines, and 1 we execute the +-marked lines. So that means we can create a solution that looks like this.

Shenzhen IO - Virtual Reality Buzzer - Solution 1

Where the code is

  tcp x0 0
- jmp send
  mov 0 acc
+ mov 1 acc
send: teq acc 1
+ mov 100 p1
+ slp 1
  mov 0 p1
  slp 1

The first part jumps to the buzzing if x0 is -999, otherwise it changes the state to either 0 or 1 depending on what came in on the x0. Then it executes the buzzing. I considered to move 100 to acc and then skip line 5 and just mov acc p1, sleep and so on. But that won’t work, as we will sleep two cycles every time also when not buzzing. That will prove to be fatal is the buzzing starts on an odd time step. The solution has the stats

Cost: 3
Energy: 198
Lines of code: 9

Updating the solution

There are a few tricks we can use to make the code a little more efficient. The first one is of course that we can shorten the execution of buzzing with the help of the gen command. Which we at this point still haven’t learned about.

The second trick is that we never get a request for buzzing if we already are buzzing. Which in practice means that we can check if x0 equals -999 if not then we should flip the acc – which can be done with the not command. Which gives us the following solution

Shenzhen IO - Virtual Reality Buzzer - Solution 2

with the code

  teq x0 -999
- not
  teq acc 100
+ gen p1 1 1
- slp 1

It gives us a solution with
Cost: 3
Energy: 146
Lines of code: 5

So slightly improved. I don’t think it is actually harder to read though.

Posted by Kristian

Leave a Reply