AE6TY on Software Defined Radio

July 21, 2011 | Amateur Radio | By: Mark VandeWettering

This morning I realized that somehow I had failed to listen to the latest SolderSmoke episode (#135), so during my somewhat longer than usual commute (traffic) I set it going and had a listen. And wow, some really great stuff, especially the report by Bob Crane, W8SX on the Four Days in May (FDIM) QRP conference last month. One thing that caught my attention was a presentation by Ward Harriman, AE6TY, on “Software Defined Radio Without the Math”. Since that is a topic I’ve always been interested in, when I got to work, I looked up his website, and found that it’s a great treasure trove of information. Like Jeri Ellsworth’s recent project, Ward has designed an SDR which doesn’t require a PC to work, but instead of using an FPGA like Jeri, he chose to use a dsPIC processor. He’s also got the schematic and PCB files online, and the whole build is documented in a series of articles for QRP Quarterly that you can download from his website. Awesome stuff! Check it out.

AE6TY on Software Defined Radio!.

Parents can trump mentors…

July 18, 2011 | My Diary, Rants and Raves | By: Mark VandeWettering

Back on July 8th, I wrote a brief post about mentoring. Hopefully, some of you read it. In case you didn’t, I made the completely unsupported claim that mentors don’t normally create interest, they merely nurture the interests that are already there. They also serve to help remove the obstacles that frustrate the enthusiasm of newcomers, providing material, advise, or inspiration.

Gee, that sounds like a parent, doesn’t it?

Last week, I had the opportunity to think about this topic a lot. On Wednesday, I got to tell this
story, which I’ll go ahead and tell you now.

When I was sixteen or so, I can remember being in my grandmother’s dining room, excitedly explaining something about my (then new) Atari computer to her. Remember: this was 1981 or so, and I think it was moderately safe to say that grandmothers as a demographic were fairly ignorant of microprocessors. But my enthusiasm was bubbling over, and she patiently listened to me until I was forced to take a breath and wandered away.

She wandered back into the kitchen, and had the following conversation with my Mom:

Grandma: “Boy, Mark sure seems to know a lot about computers, huh?”
Mom: “Yeah, he’s pretty smart.”
Grandma: “I haven’t the faintest idea what he’s talking about.”
Mom: “Yeah, me neither.”
Grandma: “He doesn’t seem to mind though.”
Mom: “Nope, just keep nodding and smiling. He doesn’t care if you understand, he just wants you to listen.

I used to believe that this story was about my grandmother. She was, after all, a remarkable woman. She taught me a lot: how to cook, how to crochet. Most of the money I spent on that first computer came from mowing her lawns. She made me lemonade on hot days. She would make pies and cobblers from the blackberries and huckleberries I’d pick. When I got my driver’s license, I would drive her on errands. Sadly, when college came, I saw quite a bit less of her. Her breast cancer reasserted itself, and she passed away about 26 years ago. I still miss her, and think of her when I make pickles, potato salad, or pork shoulder.

But I didn’t realize until last week that this story was also about my mom. She too, was a remarkable woman. After all, in 1980, she was willing to support the insane desire of a sixteen year old boy to learn about computers. She didn’t have any expertise, but she patiently accepted that what I wanted to learn about good for me, and she did all she could to help remove the barriers that might have stymied my initial interest. That early interest blossomed into a rewarding career and remains the core of the intellectual joys that you get a glimpse of through my blog. And of course, she was my mom, and loved me (and the rest of her children) with the kind of love that only a mother can.

On Friday July 8th, I received a phone call that my Mom had passed away. I got to tell the story I just related to you at her funeral to her friends and family.

In the grand scheme of things, expertise isn’t that important. Knowledge isn’t that important. My mother and grandmother didn’t have any expertise or special insight into what I was doing. What they did have was love, and that love gave them faith that the path that I saw for myself (even at age 16) was worth supporting and aiding. They removed obstacles. They loved me for who I was and what I wanted to do, unconditionally.

I cannot begin to express the degree to which she will be missed.

Addendum: You might have asked where Dad was in all of this. Dad was awesome too. At age ten or so, I got it into my head that I wanted to build a telescope. I had read some book that said you could do it. Without any real expertise, he supported the project. We sent off to Edmund Scientific and got a mirror grinding kit to make a 6” mirror. We dutifully ground and polished it. But in the midst of that project, he developed Hodgkin’s lymphoma, which eventually claimed his life in 1978, and I never got to finishing the mirror or putting it into a telescope. Years later, I moved to California, and discovered the Telescope Maker’s Workshop at the Chabot Science Center in Oakland. I got it into my head that I would like to finish the telescope I had started all those years ago. My mom still had it tucked away in her closet. With help from the workshop, I finished that mirror (and went on to help many others do the same as a volunteer instructor) and finished the scope (mostly, it could still use some paint) with the help of my brother. I still have the scope, and will never sell it.

This week, I do feel sad for my loss, but there is no need for pity. All three of the people I’ve lost have left my life full of joy. If I could do the same, I’d consider my own life “well lived”.

Using the Arduino to send audio via pulse width modulation

July 17, 2011 | electronics | By: Mark VandeWettering

I’m still interested in doing light based communication, but I haven’t made a lot of progress. I did build an LTSpice model of the circuit I used yesterday, but other than verifying that it probably would work as built (which it did) I didn’t feel like I had enough brain cells working to optimize the circuit. So, instead, I decided to try to see if I could use an Arduino to send reasonably high quality audio over light using pulse width modulation.

It doesn’t really seem all that hard in principle: the Arduino libraries include an analogWrite() command which can be used to generate a PWM signal on an output pin. But the problem is the frequency of operation is quite low: around 500Hz or so. Since I was interested in sending voice bandwidth signals (say sampled at 8000Hz or so) the PWM “carrier” frequency simply wasn’t high enough.

So, I did a bit of digging. It turns out that you can configure the timers on the ATMEGA328 on board the Arduino pretty easily, and if you dig through the datasheet, scratch your head a bit, and then type carefully, you can come up with the right incantation. Which I did: in fact, it worked the very first time I downloaded it to the board.

I recorded a second or so of audio using Audacity, dumped it as an 8 bit raw audio file, and then converted it to bytes. I then created a very simple program which simply copies each byte to the PWM overflow register, and then delays for 125 microseconds (1/8000 of a second). Other than that, just some simple bit twiddling to change the PWM prescaler to operate at the full 16Mhz clockrate, and… voila.

Witness the video:


Here’s the core of the code (the actual audio data has been stripped for brevity):

[sourcecode lang=”c”]
#include <avr/pgmspace.h>

prog_uchar bwdat[] PROGMEM = {
0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x80, 0x80, 0x80, 0x80,
// … lots of lines deleted for brevity…
0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x80, 0x7f, 0x7f, 0x80, 0x80, 0x80,
0x80, 0x81, 0x81, 0x80, 0x80, 0x81
} ;

void
setup()
{
pinMode(11, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS20) ;
OCR2A = 180;
}

void
loop()
{
int i ;
char ch ;

for (i=0; i<sizeof(bwdat); i++) {
ch = pgm_read_byte_near(bwdat+i) ;
OCR2A = ch ;
delayMicroseconds(125) ;
}
}
[/sourcecode]

Laser audio transmitter…

July 16, 2011 | electronics | By: Mark VandeWettering

Okay, so last night, after just testing one of the laser modules I had, I decided to try to make a transmitter to send audio over laser light to my “solar cell + Radio Shack amplified speaker” receiver that I was experimenting with earlier. I suppose I could have used my linear current LED modulator, but there were reasons to believe that it wouldn’t work all that well. Lasers are inherently nonlinear: they are meant to operate under reasonably narrow ranges of drive current, whereas LEDs are fairly linear over a wide range of drive currents. Thus, linear current drive isn’t appropriate for lasers. It would be much better to use pulse-width modulation to simulate AM modulation on a higher frequency carrier.

So, that’s what I did.

I took the quickest way out: I built one using a 555 timer. I had previously built a simple AM radio transmitter using a 555 timer, and somewhat unsurprisingly, the exact same circuit can be used to drive a laser. You simply hook a current limiting resistor (150 ohms in my case) and the laser diode to the output at pin 3 of the 555 astable multivibrator, aim it at your solar cell receiver, and.. voila! It works!

Well, it sort of works. The sound quality, like the sound quality of the AM transmitter that I liked to above, leaves something to be desired. It’s not unintelligible or anything, it’s just not particularly high fidelity. So, rather than shoot a video that demonstrates it, I thought I’d spend some time trying to figure out how to design a system that would work better. Here are some of my basic thoughts:

My input biasing and scaling for the prototype was completely adhoc. I merely injected the voltage directly onto pin 5, without any impedance matching, scaling or biasing. That’s mostly because I was pretty sure that even without those things, I’d get some modulation that would be detectable. I was right, but I really should go back and figure out what the right answer is to ensure that I have deep modulation with a typical -1v to 1v, low impedance audio signal (which is what I’m feeding into it).

The AM carrier frequency I picked was selected by just using two resistors (I think 1K) from my junkbox, and then selecting caps to get the frequency of oscillation above the audio frequencies people can hear. I think I ended up with a 0.01 uF cap, which results in a frequency of oscillation of around 46Khz). That seems okay, but on the receive side, we could benefit by some bandpass filters centered around that frequency (this would hopefully decrease the 60 hz buzz I get from flourescent lighting).

I got a few more ideas, but they will have to wait until after breakfast. Oh, and baseball. A double header, A’s versus Angels.

Addendum: Okay, before I left, I recorded a quick demonstration to show how it works. It’s not bad actually:

Just playing with laser diodes…

July 15, 2011 | electronics | By: Mark VandeWettering

A while ago, I got some laser diodes from from dealextreme.com. They were dirt cheap, but I haven’t had any chance to hook them up. I didn’t have a datasheet for them either, so wasn’t sure exactly what I should do to current limit them. So, I hooked it in series with a 150 ohm resistor and a 9v battery, and measured both the current and the voltage drop across the laser module. The resulting beam seemed bright and steady.

The current through the circuit was approximately 37ma, and showed a voltage drop of almost exactly 2.5 volts. That means the total power consumed is about 92 mw. These laser modules seem to be good quality: the beam is bright and quite round. While I don’t have a specific model number on these diodes, staring at datasheets for similar diodes make me believe I’m probably not too far off in terms of picking a good current.

Yes, yes, I should use a better constant current circuit. This was just a first test.

Designing a full adder with logisim

July 12, 2011 | Homebrew CPU | By: Mark VandeWettering

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?

July 11, 2011 | Programming Languages, Rants and Raves | By: Mark VandeWettering

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…

July 10, 2011 | General | By: Mark VandeWettering

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

July 10, 2011 | Homebrew CPU | By: Mark VandeWettering

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…

July 8, 2011 | Rants and Raves | By: Mark VandeWettering

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?

July 8, 2011 | Rants and Raves | By: Mark VandeWettering

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…

July 7, 2011 | Homebrew CPU | By: Mark VandeWettering

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

July 7, 2011 | Homebrew CPU | By: Mark VandeWettering

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…

July 7, 2011 | Blogging | By: Mark VandeWettering

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

July 5, 2011 | Arduino, Gameduino, My Projects | By: Mark VandeWettering

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.