Monthly Archives: July 2011

Designing a full adder with logisim

An anonymous commenter suggested that I look at logisim, a circuit simulator written in Java. It has many nice features. For instance, you can specify a combinatorial circuit either as a truth table or as equations, and it will convert to the other representation (in minimized forms) and will also build a circuit to implement those equations. You can tell it to use only 2 input gates, or even to use only NAND gates, and it will layout a little circuit to implement it.

For instance, I entered the truth table for a full adder, and told it just to use 2 input NAND gates. The resulting (29 gates? I didn’t count carefully) 1 bit full adder emerged as a circuit:

Pretty neat. I am not sure that logisim is quite good enough to design an actual, physical CPU (it doesn’t model propagation delays, as far as I can tell) but it’s a very good tool to exercise your nascent digital design skills. Check it out.

Shouldn’t we use programming languages with fewer bad parts?

I was reading that Stanford has begun teaching their introductory computer science course CS101 with Javascript. Despite a lot of the propaganda surrounding the web and a pretty good book on the good parts of Javascript, I can help but think that Javascript has some really tragic flaws. Dijkstra famously referred to PL/1 as “the fatal disease, belonging more in the problem set than in the solution set”, and I kind of feel the same way about Javascript. Yes, it is in every browser now, so it is perhaps the most widely deployed programming language you can find, but it’s got quite a few absolutely horrific features in it. The == operator has some astoundingly obtuse behavior. Automatic semi-colon insertion is simply idiotic. Crockford documents several more features he finds questionable, most of which I think are questionable, because they mirror features in other common languages.

Crockford advises that we use tools which check our use of these questionable features, but wouldn’t it simply be better if the language didn’t contain these features in the first place? We know that some features are bad, so why are they retained in the language? Are we forever to be saddled with error prone and silly features?

Maintenance on twitter/facebook posts for my blog…

I apologize. My blog has been remarkably unsociable. Whenever I post to it, I’d like it to also post a short notice to facebook and to twitter. But recently some hiccup happened, and two posts would end up on twitter, and an annoying three would appear on facebook. I think I’ve got that sorted out. Hopefully I haven’t irked too many of you, and this will work as expected from now on.

DIY Computer Project

Continuing my obsession with reading up on homebrew CPU projects, I found this incredible blog. Instead of just presenting the completed design, Dawid has presented intermediate posts about his project in progress, detailing some of the choices and techniques he had to make along the way. As is true of most projects like this, it’s hard to know how to get started and gain enough traction to make progress, and details like this can be really helpful and really inspiring.

DIY Computer Project

Addendum: For instance, I’ve been considering writing a gate level simulator (writing code is something I feel comfortable doing) rather than spending huge amounts of time learning Verilog or VHDL. It is somewhat reassuring that Dawid apparently did the same thing. Very interesting.

Some thoughts on the last Space Shuttle launch…

This morning, I was a bit late coming into work. I decided to sit until 8:26AM Pacific to see if Atlantis would be launched on the final mission of the Space Shuttle program. Low cumulus clouds threatened, but in the end the shuttle rose on its pillar of fire for the last time, and in eight and half minutes, discarded its main fuel tank and was safely in orbit.

Reporters have been trying hard to find some perspective on the event, and in my experience, mostly failing. They put microphones in front of kids and ask them if they want to travel to space someday. They talk to astronauts and former astronauts and ask what it was like to be in space.

I think all that is slightly off the mark.

I was born in 1964, and was a child of the Apollo space program. I remember watching the first tentative steps of Neil Armstrong on the moon on our old Zenith black and white set. Even at that young age, I was interested in space and astronomy. It was a few years later that computers entered my consciousness and come to dominate my time, but I continued to be interested in space and astronomy.

For kids my age, the usual default answer to “what do you want to be when you grow up?” was “an astronaut.” But more than just being an astronaut, there was sense of optimism: that if the moon was reachable, what other achievements could we reach if we applied our energy and our industry. We dared imagine a world without hunger, and without poverty. Diseases? Cured. Poverty? Eliminated! Ignorance? Educated.

Perhaps it was just a dream, but it was a healthy one. It was a dream that challenged us to greatness.

This morning, Atlantis launched for the last time. Vying for attention on CNN was President Obama, who held a press conference to discuss the meager 18,000 jobs that were created in the last month, the weakest performance since September of last year. When coverage returned to the launch, reporters interviewed a number of people, and the question of the expense of the launch was mentioned. After the launch, the economic news reasserted itself. One reporter said that the growth industries for the next year are likely to be in retail sales and in food service.

I was lucky. As a kid, I dreamed of being an astronaut. Today? Kids dream of being to make just a little more than minimum wage. It’s a pity that I didn’t see my wish fulfilled, but it’s a tragedy that a generation of young Americans won’t experience their dream, even as limited as they are.

Here’s the reality: the space program is little more than a jobs program. Certain industries and certain states (CA, FL, MD, TX) benefit from our dreams of slipping the surly bonds of earth, but the vast majority of Americans don’t get nearly as much benefit. In purely economic terms, the Space Shuttle is a disaster: it never delivered the cost savings that optimistic forecasters suggested were possible in boosting satellites to orbit. So, people argue that the money would be better spent elsewhere, that our dreams are simply too expensive.

The U.S. military spent more on air-conditioning temporary structures in Iraq and Afghanistan than NASA spends in a year. While I appreciate and laud the efforts of our troops, I can’t help but think that cutting our dreams so we have enough money to air condition tents isn’t the kind of society that we should be dreaming about.

For a generation, the space program provided us with inspiration and optimism. As the shuttle program winds down, for all its faults it still seems like the end of a dream. I can’t help but wonder what dream will unite the next generation of Americans in their quest for greatness.

Are you a mentor, or are you just getting in the way?

It’s Friday, and Fridays are good days for thinking. It’s unclear that it is a good day to write about what you’ve been thinking, but here goes anyway.

I’m involved in a couple of different communities (hacking and amateur radio) which might be characterized as “ageing”. As a young adult, I was influenced by Steven Levy’s Hackers: Heroes of the Computer Revolution. It gave a name to the kind of computer exploration that I was interested in, and the description of the early MIT hacker community showed that there were other people in the world who were interested in understanding and programming these amazing machines. Despite the fact that I was coming onto the scene as part of the microcomputer revolution of the 1980s, I felt that the spirit of these hackers was akin to my own. They seemed to experience the same odd pleasure that I got when exploring a machine, and making it do something unusual or unexpected. Many people in this community who are my age are interested in trying to instill some of these ideals into a younger generation of hackers, and have asked what we can do to mentor them along.

In amateur radio, there is a long history of “Elmers”: hams who help younger and more inexperienced hams by giving them the benefit of their experience. There is little doubt that the ham radio community is aging: while attending Pacificon last year, I suspect I was in the youngest two percent of attendees, and I’m in my late forties. It’s a very common thing for hams to actively seek ways to bring new blood into the ranks of the licensees. For some, it’s just a way to help ensure the continued use of the frequencies that they enjoy, but I would suspect that the majority of hams merely want to pass on some of the experiences and joy that they have derived from their favorite hobby.

But here is my somewhat skeptical observation: neither community does a very good job. And frankly, that’s been a source of some puzzlement on my part. For all the effort that we expend trying to extol the virtues of computer exploration or the construction and use of radios, we aren’t attracting huge numbers to the hobby. In fact, I suspect that this kind of advocacy hasn’t resulted in any measurable increase in either community. Why is that?

I suspect it is because mentors don’t actually create interest in subjects. No amount of extolling the virtue learning about antennas or building radios or learning CW ever convinces anyone that they should become a radio amateur. No promoting of the virtues of programming, learning the internals of machines or security will ever make it interesting to someone who isn’t already curious and interested. Either you find such things interesting, or you do not. No amount of advocacy can turn your apathy into interest.

Consider it this way: I’m deeply uninterested in fashion. There are people who nonetheless view it as their passion, as a source of considerable joy in their lives. That’s actually okay. I’m just not one of them, and no amount of cajoling on their part is likely to change my mind.

I’m also relatively (and somewhat oddly) unmoved by music. For me, piano lessons was always mostly a chore. I simply don’t experience the joy and emotions that people get from listening to most music. Intellectually, I can appreciate it, but I don’t feel passionate about it.

If I can’t be mentored into a passion for music and fashion, why am I puzzled when my own efforts to mentor people into things I do enjoy fall mostly on deaf ears?

That’s not to say that mentors can’t be helpful: they absolutely can. The experience of people is incredibly useful, and can help the inexperienced see farther and better than they could stumbling on their own. And, if you happen to find a mentor who has gone along a path you are already interested in, they can serve as inspiration. But they do not themselves create the passion and drive that makes a person try to master a new subject. TThat comes from individuals themselves, and it is inappropriate for “mentors” to imagine that it is through their own virtue that their passions are perpetuated.

A couple of illustrative examples of how things can go wrong:

To become a ham radio operator, you need to become licensed, which means passing a relatively straightforward exam. The entry level license is for a “Technician” class license, which basically requires getting 70% correct on a multiple choice test drawn from a published question pool. It’s not very hard, and in fact a great many ham radio clubs hold “ham cram” events, where they meet for a day to try to cram enough stuff into your head so that you can pass the exam the same day.

One particular ham I know hates these events. His claim is that these events are “cheating” and that they deny the new licensees the opportunity to learn the material “properly”. He usually follows this with a story about how he learned this stuff. How he had to be licensed as a novice, and had to upgrade. How he had to master Morse code, work his way up through the license classes. How he learned to do everything at the foot of his mentors, and how he was glad they were around. He’ll then usually lapse into a diatribe about how kids today “play too many video games” or “don’t work hard like we used to” or “feel they are entitled”.

It makes me groan inside.

A ham radio license isn’t a diploma. It’s a license, just like a fishing license. It grants limited, uses of a shared public resource. Without it, you can’t transmit on amateur frequencies. Hence, it’s really just a road block: it gets in the way of you experiencing the thing that you might be passionate about. From my perspective, you should figure out a way to get licensed so you can get on with your passion. From my friends perspective, that road block should be as high as possible, so you really deserve the privileges you enjoy.

He’s not a bad sort, really. He thinks he’s helping novices, but in reality he’s just trying to shore up the road blocks that keep people from entering the hobby. His “mentoring” is significantly blunted by his desire to make people “pay their dues”.

I’ve heard a number of people speak on “how do we encourage the next generation of hackers”. I similarly find these kinds of talks misplaced. When I reread Levy’s Hackers, I experienced some nostalgia, but I also thought there was a lesson to be learned. Levy highlighted three different groups of hackers: the original MIT hacker community which grew up around the PDP-1, the Hardware Hackers who brought about the Altair computer, and the game hackers who surrounded Sierra Online. What I think is amazing is that none of these stories gave any hint of the revolution in computing that was to come. The rise of the Internet, search and social media simply isn’t visible in this book. Richard Stallman is mentioned as the “last real hacker”, with a sort of wistful nostalgia, with the near certainty that he will simply fade into obscurity, totally missing the revolution of free and open source software that he helped inspire. There is no sense that some of the early work of (say) the Xerox Alto would eventually fuel the second phase of Apple’s existance, and ultimately change pretty much everything about computers.

In other words, much of the “hacker” revolution that some of us (myself included) like to refer to with a sense of wistful nostalgia wasn’t as closely linked to the revolutions that were to come as we would like to imagine. When we draw on our own early experiences to try to find ways to educate or inspire newcomers, we often do so through this overly narrow view of history. We might think that “really” understanding machine code or architectures are important, and that the only way to do that is to go through the same sort of exercises that we did. But consider this: if we would have had access to the machines and information back then, we wouldn’t have tolerated this kind of spoon feeding either. We would have simply grabbed all that we could in pursuit of our passions.

Young people today are no different.

Here’s my recipe for success: don’t bother trying to recruit people to your passions. The best you can do is find those already interested, and make it easy for them to find you. Use social media. Publish your passions on your blog. Do what you love, and do it visibly. And when you find others who enjoy the same thing, try to engage. Do stuff. Collaborate. Gather. Exchange.

And most importantly: don’t try to convince someone that the way you enjoy something is the only proper way. Don’t dismiss their approach to their passions, simply because they aren’t the same as your own. Seek to help remove the roadblocks that keep them from progressing, don’t introduce new ones yourself to justify your own approach.

And most of all, have fun, and keep doing what you are doing!

What do you all think?

A basic simulator for Caxton Foster’s “Blue” Architecture…

Yep, been spending some time thinking about homebrew computer architectures. I’ve also been reading Gordon Bell’s Computer Engineering, pondering some of the older and earlier computing architectures. Caxton Foster’s Computer Architecture describes a simple computer architecture called “Blue”, which has only 16 instructions, and uses only direct addressing. It’s a pretty primitive machine (more like a PDP-8’s out of work cousin), but in 30 pages, Foster describes pretty much the complete circuitry needed to implement the machine. I thought I’d write a simple behavoral simulator just to play with, and to see how much of a pain it is to program (answer: pretty big). For now, here’s the code. More later.

[sourcecode lang=”C”]#include <stdio.h>
#include <stdlib.h>

/* _ _
* | |__| |___ ___
* | ‘_ \ / _ \/ _ \
* |_.__/_\___/\___/
*
* An implementation of the simplest version of Caxton Foster’s "Blue"
* machine as described in his book _Computer Architecture_, Third
* Edition, Copyright 1985. Just meant to stimulate some experimentation.
*
* The architecture described is _very_ simple, consisting of just sixteen
* instructions, a single accumulator, no CPU flags like carry or overflow,
* and only direct addressing. This makes programming pretty annoying,
* virtually requiring self-modifying code to do anything non-trivial.
* But in 30 pages, Foster presents pretty much the entire architecture,
* which made me spend 15 minutes to code up a simple behavioral simulator
* and play around with it.
*/

typedef unsigned short Word ;

#define MEMSIZE 4096

Word M[MEMSIZE] = {
0x600C,
0x100B,
0x9004,
0x0000,
0x700C,
0x6008,
0x100B,
0x7008,
0x600C,
0xC000,
0xA000,
1,
-13,
‘H’,
‘e’,
‘l’,
‘l’,
‘o’,
‘ ‘,
‘W’,
‘o’,
‘r’,
‘l’,
‘d’,
‘!’,
‘\n’
} ;

Word A ;
Word Z ;
Word MAR ;
Word MBR ;
Word PC ;
Word IR ;
Word CS ;

void
fetch()
{
Word t ;

/* fprintf(stderr, "… 0x%04x ", PC) ; */
IR = M[PC] ;
PC ++ ;
PC &= (MEMSIZE-1) ;
}

void
execute()
{
int op = IR >> 12 ;
int addr = IR & 0xfff ;

/* fprintf(stderr, "%0x %03x\n", op, addr) ; */

switch (op) {
case 0: /* HLT */
fprintf(stderr, "\n… bloo executed HLT.\n") ;
exit(0) ;
case 1: /* ADD */
A += M[addr] ;
break ;
case 2: /* XOR */
A ^= M[addr] ;
break ;
case 3: /* AND */
A &= M[addr] ;
break ;
case 4: /* OR */
A |= M[addr] ;
break ;
case 5: /* NOT */
A ^= 0xFFFF ;
break ;
case 6: /* LDA */
A = M[addr] ;
break ;
case 7: /* STA */
M[addr] = A ;
break ;
case 8: /* SRJ */
A = PC & 0xFFF ;
PC = addr ;
break ;
case 9: /* JMA */
if (A&0x8000)
PC = addr ;
break ;
case 0xA: /* JMP */
PC = addr ;
break ;
case 0xB: /* INP */
A = getchar() ;
break ;
case 0xC: /* OUT */
putchar(A) ;
fflush(stdout) ;
break ;
case 0xD: /* RAL */
if (A & 0x8000)
A = (A << 1) | 1 ;
else
A = (A << 1) ;
break ;
case 0xE: /* CSA */
A = CS ;
break ;
case 0xF: /* NOP */
break ;
}
}

int
main(int argc, char *argv[])
{
for (;;) {
fetch() ;
execute() ;
}
return 0 ;
}

[/sourcecode]

John Doran’s D16 Homebrew Computer

Just another link to inspire me in my glacial moves toward designing a CPU of my own:

The D16/M is a general-purpose, stored-program, single-address, 16-bit digital computer using two’s complement arithmetic. It manages subroutine calls and interrupts using a memory stack. The processor may directly address 64K words of memory or I/O. Its timing and control unit is microprogrammed (fully horizontal, with a 72-bit control word).

John Doran’s D16

Time for some blog maintenance…

My blog may be unavailable for a short time today as I perform some needed upgrades. If all goes well, any down time should last only a few minutes. Don’t despair! I’ll be back shortly.

Addendum: Upgrade seemed to go smoothly and without any problems. If you are experiencing any strangeness, try refreshing this page. If you still have difficulty, try sending me an email and letting me know of what your issue is.

A Gameduino Button Box, made from parts from Ikea and Surplus Gizmos

I haven’t had all that much time to work on the Gameduino between holidays, visiting family and a business trip, but I have been meaning to put together a simple “button box” for the Gameduino, basically consisting of just four buttons (L/R/thrust/fire). I suppose I could have included hyperspace too, but 4 buttons was sufficient for Space Invaders, so…

Here’s the thing: I’m not really a wood worker, so the basic idea was to find a prefab wooden box, and then just bore some holes for some switches, and then make a small wiring block below that I could use to plug into the Gameduino. I got the switches from Surplus Gizmos last time I was in Hillsboro, OR visiting family. Seemed simple enough: the AVR in the Arduino has built-pull up switches, so all you really have to do is wire the switches up to ground and the digital inputs, and you are good to go.

So, that’s what I did!

Addendum: If you’ve no idea on how to wire switches up to an Arduino, you might find this page to be helpful. In particular, you need to make sure you enable the pullup resistors on the Atmel by writing a HIGH value to the INPUT port. That enables the pull ups, and makes button interfacing as simple as possible.

Michael Bay and Basic Astronomy

I’ve seen lots of bashing of Michael Bay and his movies this weekend. Amongst the blogging world, there seems to be almost universal contempt the flashy, soul-less combination of flashy cars and collagen injected supermodels. And yet his latest release Transformers: Dark of the Moon just claimed the all time Independence Day record, amassing 156 million dollars in its first five day weekend, including (yes) $25 or so for me and my wife.

I’m not going to argue that Michael Bay deserves more respect (while his movies are popular, they do pander to teen-boy sensibilities) or less respect (that being said, his movies are enormously popular, and do have a visual style which I can appreciate). Instead, I’m merely going to nit-pick a single annoying set of mistakes that he perpetuates in Transformers: Dark of the Moon.

There is no “dark side of the moon”, any more than there is a dark side of the Earth.

(I might reveal minor plot points in the following discussion. You’ve been warned.)

Part of the premise of TDOTM is that the Apollo 11 landing was merely done to retrieve a crashed Autobot ship. Repeated reference is made to landing on the “dark side” of the moon, or loosing radio contact because Apollo 11 is now on the “dark side”.

Argh.

I’m going to blame Pink Floyd for this, although perhaps our own penchant for viewing things like the moon without really attempting to understand what we see is at least as likely to blame.

The moon revolves around the earth in about 27.3 days (a sidereal month). The moon’s rotation is synchronized to its orbital period, so that it presents the same side toward the earth (mostly, more below). Hence, we see the same side of the moon from our vantage point on earth all the time. Hence, it makes sense to speak of the “lunar near side” (the side we can see) and the “lunar far side”, the side we cannot. The first pictures of the lunar far side were taken by the Soviet Luna 3 probe back in 1959: prior to that, we knew essentially nothing about this far side.

But note: the far side isn’t “dark”, anymore than the near side is.

If you watch the face of the moon throughout a sidereal month, you can see the phases change. During a full moon, the visible, near side of the moon is fully illuminated, and the invisible, far side is fully dark. But one half a sidereal month later, we have a so-called “new moon”. Here, the near side is in shadow, and the far side is fully illuminated. And halfway between these two times, the near and far sides are both half lit and half in shadow.

During the Apollo missions, the Command Module would periodically go into “radio darkness” as it was hidden behind the moon, but this was merely because the moon would block radio signals aimed at the craft in lunar orbit. But this had nothing to do with whether the Command Module was in sunlight or not.

Of course, someone more illustrious than me has been through all this before.

It’s a minor nit to pick. And Michael Bay has done much, much worse. But this kind of basic illiteracy annoys me just as much as the obvious car and electronic product placements we see scattered throughout the film.

And yes, I can accept talking robots from outer space, the existence of something called Energon, and that hot chicks would like Shia Labeouf, but choose instead to pick this one nit. Sue me.

Addendum: We don’t see precisely the same side all the time. The moon’s orbit is elliptical, which means that it varies in distance between us. Because its angular velocity changes, but it’s rotational velocity does not, the moon is only on average in synchronous rotation. We can see about 9% more of the moon’s surface than we would if it was perfectly synchronous.

Addendum2: If you really want to nit pick, consider the effect of the Roche Limit and what it means when Cybertron is brought into earth orbit.

Addendum3: Also, for being the “Einstein of the Autobots”, Sentinel Prime was really, really stupid.

Addendum4: Yes, I get all the jokes on Big Bang Theory.

The sights and sounds of RTTY

Over at the tymkrs blog, they’ve been learning a bit about RTTY as a digital mode, but I found their description a bit theoretical. I’d describe radio teletype (RTTY) as a popular digital mode, particularly among contesters. It encodes text as a stream of five bit code words using a system known as Baudot, and then sends these codes as two tones using frequency shift keying. On the amateur frequencies, these tones are typically 170 Hz apart, and sent at 45.45 baud.

Is that too esoteric for you? Well, here’s some sights and sounds.

First of all, here’s the sound. I recorded the following minute of audio using my SDR-IQ this morning around 14.090 Mhz, on the 20m band. There is apparently some contest going on, as I observed people exchanging sequence numbers and signal reports. I’ve left this uncompressed, so in theory, if you have any software that can decode RTTY, you can play it back and see what it says (I use fldigi).

RTTY on 20m, recorded on July 2, 2011 (WAV)

If you are using a radio which has a “waterfall” display like are common for software defined radio, you might expect to see the following: RTTY looks like two discrete tones, separated by around 170 Hz. This is the view using my SDR-IQ running Spectravue.

Spectravue doesn’t have an RTTY decoder built in, but fldigi does. If you configure it to use the stereo mixer output of your PC as input, you can use both programs together to decode the RTTY. Here’s what fldigi looks like:

You can see that fldigi has some problems with putting out garbage letters, mostly at the end of transmissions. The squelch control that it has is slow to stop the decoder, and often at the end of a transmission you’ll see a bunch of garbage characters. I’ve wondered how to tune fldigi to minimize that effect, but I haven’t figured it out yet (I’m not much of an RTTYer).

While RTTY has a long history in amateur communications (refer to (refer to Wikipedia for details) it is hardly ever done with vintage equipment anymore, with software replacing vintage teletype terminals. I see it mostly used during contesting, and hardly ever for long “rag chewing” contacts. In recent years, digital modes like PSK31 and Olivia seem to be increasing in popularity at RTTY’s expense: even W1AW has begun to shift their bulletins to PSK31.

If you are a ham, you probably know all this already: this is mostly to help inform the short wave listener or prospective ham. If you are an avid RTTYer, feel free to post your views on the mode as a comment: as I said, I’m no expert, but we’d all love to hear from anyone who is.

Magnetic Loop Antenna Theory

I was digging around trying to find some software to help me design a magnetic loop antenna for use on VLF frequencies. I stumbled across this page, which provided a lot of interesting insights, as well as a Spice model to help you understand how they work.

Magnetic Loop Antenna Theory

The article clarified something to me which I only vaguely understood before. If you desire narrow band performance, the best way to do it is to make the antenna resonant by paralleling it with a capacitor, and using it in combination with a high impedance load to measure the voltage from the antenna. But if you desire wide band performance, then you want to use it combination with a very low impedance, which basically means that you feed it into a transimpedance amplifier which effectively shorts the antenna to ground and converts the current to a voltage.

Interesting.

I might have missed it, but while the page presents an Spice model for the antenna, it doesn’t seem to have it available for download. I’m working on putting it into LTSpice, and should have it available for download sometime in the next couple of days.