Wishful Coding

Didn't you ever wish your computer understood you?

The Church of Science

This, ladies and gentleman, is the University of Twente. To the left you see a church of god, submerged in water, that I see as a representation of the opinion of science towards the religions of god. To the right you see a bell tower that I affectionately call the church of science, representing the beliefs of scientists.

This desire to drown a religion should sound familiar to you. It is a common trait to most religions to make a claim to the truth and declare all other religions false.

To call science a religion might raise some eyebrows, so let me explain. There are three concepts that I will talk about:

The first is god. God by itself is not true or false. It is simply the concept of an omnipotent being. This concept is internally consistent and valid as a concept.

The second is math. Like god, math is simply a concept. It is a set of rules and symbols that are internally consistent.

The final one is observations. It is not until you apply these concepts to observations that they become meaningful. It is when you say there are two birds and god created them, that you apply these concepts to observations.

All of math, god and observations are true in themselves. It is when you say that your observations are explained by your concepts that they become models that can be correct and accurate or not.

You could say that a bird is so perfect it could only have been designed by an omnipotent being. You could say that because the field of a point charge decays with one over the radius squared exactly to one part in a billion, the electric field must be explained by math.

But they are still just concepts applied to observations. Models that help us think about our universe. But the map is not the territory, which for me means that a model should not be judged by its accuracy, but by how useful it is to think about a problem.

Ancient Greek medicine, which centered about balancing the four bodily humours, often lead to treatments that would do the right thing for what we currently consider the wrong reason. It must have been a very useful model that saved countless lives up until after the middle ages despite its inaccuracy.

Maxwell’s equations might describe the whole domain of electromagnetism very accurately, but using it to design an electric circuit is impractical. The equations of Ohm and Kirchhoff will serve you better.

One day science might make a map that is the territory (they seem to be trying very hard at least), but it will not help you think about ethical and moral dilemma or the meaning of life. The stories told in your spiritual book of choice are much more practical for those kinds of problems.

Power Supply Riddle

Problem

In a hall, two rows of 5 10W 12V lamps are connected in parallel over a distance of 10m, powered by two different 12V power supplies. The setup is like below.

The one is a big good old transformer that outputs 12VAC at 50Hz. The other is a switching mode power supply with a switching frequency of 100KHz.

The string of lamps powered by the transformer have an equal brightness, while the string powered by the switching mode power supply diminishes, with the 5th lamp only glowing dimly.

What is going on here? Answers below, but think about it for a minute.

Investigation

The first thing I did when I saw these lamps is connect an oscilloscope to the output of the supplies.

The transformer outputs a 50HZ 12VAC sine wave as expected. The other supply appears to be a switching supply. It outputs a 100KHz square wave with some high-frequency ringing. If you zoom out, it has a 50Hz envelope.

Solution

Since the only difference between the two setups is the frequency, the resistance of the wires is apparently negligible and the only thing that could have influence is the inductance of the wire.

Using an online calculator, I found that the inductance of 4m (10m back and forth divided by 5) copper wire is 3μH, and the resistance of the lamps follows from their rated voltage and wattage.

So a more accurate representation of the situation is below.

From this the AC voltage for any of the lamps can be calculated. For a single lamp at the end of a 10m wire, it would mean

For all 5 lamps it gets a bit hairy.

But simulation gives the following result, only 4V on the lamp at the end.

TIS-AVR

Last week I played some TIS-100, an assembly puzzle game where you are left to debug a fantasy computer with only the manual to guide you.

The TIS-100 is composed of many small nodes running a very limited assembly language with only one addressable register. Every node can however read and write data to its 4 neighbors.

After finishing the game, I remembered this talk by Chuck Moore on programming a grid of tiny Forth computers, not entirely unlike TIS-100, except more practical.

What if you could make an actual TIS-100? Not just an emulator, but an actual thing that sits on your desk. I set out to try.

I went to the electronics store and asked for a hand full of Attiny chips, which cost about one Euro each. They gave me some Attiny25, with 2Kb of flash, 128 bytes of ram, and 6 output pins.

I figured that with 4 neighbors and a clock line, I’d have exactly enough pins. But I’d have to do bi-directional communication over a single wire. So I decided on a pull-up design.

For now I’ll use the Raspberry Pi for input and output of the grid, but there is no reason this task can’t be delegated to another AVR chip and some buttons and 7-segment displays.

After a day of hacking, I can program 2 Attinies to double a number and pass it on. To run the more advanced puzzles, I’ll need a better way to upload code and more Attinies. I have yet to implement the stack memory node as well.

This is the code the two node currently run. (hardcoded)

When you send a number, this is what happens.

The source code is on Github