Indistinguishable From Off

When diagnosing a problem, remember to check the basics.

I was working with the prototype of the latest (take-home breadboardable) version of the DrACo/Z80 computer, making sure it still worked, when it seemed to develop a problem right at the end of programming before I was going to switch it to Run mode.

The latest iteration of the DrACo/Z80 computer, hastily redesigned
to be as breadboardable as possible on a couple weeks’ notice.

I had gone through and cleared out the first few memory addresses, since in this configuration, it’s easier to load a single number into the data latch and then program those locations all at once so you don’t have to reload the data. So addresses 00, 01, and 02 were all set containing 0x00.

I then switched back to address 00, moved the switches to 11000011 to represent the C3 (jump) opcode, and hit Latch Data to latch it in to memory. Nothing happened, which was as expected. I then hit Write to load it into memory, and the display stayed blank. That was not according to plan.

I pulled the schematic out and got about two or three logic gates into debugging it when I noticed that all the logic was at zero. After a brief search, I found a plausible explanation.

If all the logic signals are low, that’s usually a power problem — and it seemed to be, in this case. We may be building a 40-year-old computer, but the chips we’re using are modern CMOS variants — faster, cheaper, and often much more power-efficient. These are not the power-hungry 7400 series TTL chips of yesteryear. They do the same thing, but draw far less current.

In short, a good chunk of the power budget for this computer goes to run the twenty or so LEDs. The chips themselves draw very little current, in comparison. Maybe a few tens of milliamps or so, compared to 10-20mA per LED, depending on a bunch of things.

When switching back to address 00 which had data of 0x00 in it, all of the LEDs were out at the same time while I fiddled with the switches to enter the C3 opcode. This left the whole circuit drawing next to no power for maybe five or ten seconds (and little power for the previous short while, too.) The USB battery running the show had apparently sensed what it thought was no appreciable load, decided that nothing else was connected that needed charging, and gone to sleep, cutting off power to the whole computer.

Or, maybe it hadn’t…?

After powering it back up, re-entering (all three bytes of) the test program, and setting it back to address zero with all LEDs off, the battery isn’t powering off. Maybe the power wire jiggled the other time — but it was connected when I looked, and an interruption in power usually means the memory contents are randomized. It’s noticeable.

Well, we are kind of pushing how complex breadboard projects should get before switching to circuit boards. Sometimes they’re a little wonky.

Note to self: Include a power LED in the next version just in case — as well as an explanation that it may actually be essential if running from a battery.

Posted in Digital, DrACo/Z80, Drexel, Electronics, Fundamentals, Power, Troubleshooting | Leave a comment

“Free Energy!”

There’s a reason this post title is in quotes: one of the most unbreakable, solid scientific laws we know of — one of the ones that we’ve never known to be wrong — says that energy cannot be created or destroyed, other than conversions between mass and energy (as in nuclear reactions.)

In simpler words, this means that “free energy” cannot exist, unless you mean harvesting already-existing energy sources such as wind or solar power. Science is, after all, simply the process of figuring out what explanations make correct predictions about actual events, and which do not.

And we figured out a long time ago that energy cannot be created from nothing. Even the one minor exception that Einstein found unlocked all of atomic power for humankind — from nuclear power plants to hydrogen bombs, as well as much of modern medicine.

So we know the laws of thermodynamics quite well. Energy (if you include matter as energy, as Einstein showed) cannot be created or destroyed. This is right up there with “two things cannot be in the same place at the same time” and universal gravitation. It’s right, every time. We’ve never come across any macro-scale exceptions.

This doesn’t stop the thousands of YouTube videos purporting to show how to build “free energy” gizmos that can power your whole house by connecting up some spark plugs and magnets to a battery-powered fan or something. It’s understandable: it costs almost nothing to make a quick video and post it online. People are gullible and bored, and they’ll watch just about anything.

And views are views, whether you’re a scam artist or one of the good ones promoting solid science, engineering, or math. Unfortunately, really bad science is sometimes passed off as good entertainment and the distinction isn’t always clearly labeled.

Now, as Ross Perot would have said, here’s the deal. Let’s suppose for a minute that the scientists and engineers have overlooked some clever way of tricking the Universe into providing truly limitless, free energy. It could happen, you might think. Similar stuff has happened before, and the electric motor was pretty magical when it was first invented. Suppose some garage inventor, working in his or her lab just like Faraday, came up with just the right combination of wires and magnets to go over-unity and produce a net energy gain.

This wouldn’t be a world-changing invention. This would be THE world-changing invention — probably beating out more mundane ones like the invention of fire and the wheel, over time. We would, as a species, suddenly have the ability to travel, for cheap. We could desalinate as much water as we need from the world’s oceans. It would benefit everybody even the billionaires would become quadrillionaires!

This would be Minecraft on creative mode. There would be no reason on Earth to suppress such an invention, and absolutely no way to do so, once anybody else learned about it. We wouldn’t just be able to power our homes for free. We’d have our own spaceships!

So if you believe in true “free energy” devices, you are required to also believe that:

  • The vast majority of the world’s scientists and engineers are complicit in covering up the biggest secret in history,

    or
  • Some obscure inventor has come up with this idea, but Big Oil or the Illuminati or whomever has suppressed it, and is sitting on it or is trying to destroy it. (Hint: they would patent it and put it into production as fast as possible and sell energy 5% cheaper than the next guy, while they paid nothing) — and nobody else has managed to figure out how it was done. If a set of plans or an Internet video exists of it, this is not the case. If people have bought these plans and they worked, at some point an engineer will see one, they’ll call the news, and then everybody will know. And the media would cover it. Some reporter would be getting a Pulitzer to go with the inventor’s Nobel.

TL;DR: These so-called “free energy” devices are almost certainly not possible, despite the fact that they would benefit absolutely everybody. If they did exist, they would be civilization-changing in a way we’ve never seen before, and there would be no keeping it secret.

So if you didn’t know better, that’s why these videos are invariably clickbait and complete nonsense. Please don’t encourage their makers (except to make legitimate claims about what they create.)

If you do know better, please don’t make these videos! The last thing we need right now is more people doubting good science and thinking the world is run by some shadowy Deep State.

And if you’re Mehdi, thank you. Good to see a fellow Jedi. Maybe don’t lick the science next time, though?

Posted in Current Events, Digital Citizenship, Science | Leave a comment

The Sound Of Music

FreeBASIC is a great language for informal messing around. In two lines of code, you can be drawing graphics in full-color 1080p. Now that FBC supports compiling for x64, you can allocate ridiculous size arrays using as much memory as you have available.

It’s the ideal modern back-of-the-envelope prototype language for those of us who grew up on BASICA, Tandy BASIC, and QBasic/QuickBasic. But as with most reboots of beloved childhood franchises, a few things seem to be missing.

Playing music, for one, was very easy back in the days of BASIC. Most languages included a “play” keyword that could be called to play various notes. Type something like “play cdefg” and you could make the speaker produce a simple scale.

FreeBasic, unfortunately, doesn’t have the “play” keyword (though, oddly, WinFBE still flags it as a keyword.) FreeBasic is cross-platform, being available for Windows, DOS, and Linux — and so hardware-specific things like speaker support weren’t included.

Fortunately, however, there’s a workaround that ends up being a significant upgrade. Windows provides various APIs that can be used by programs to request functionality from the OS. One of these is the ability to emulate General MIDI instruments, and to accept commands for these from programs. With a little setup, FreeBasic can have access to all of Windows’ General MIDI capabilities.

So now, instead of commanding simple beep melodies, we can produce almost-performance-quality music. The API is even relatively easy to set up once you know the right commands — and this is where Google helps immensely. After a brief search, I found an example by FreeBasic.net user “Mihail_B” that shows how to get Windows to play a couple of percussion samples via MIDI.

A quick look at the MIDI specification helped decode what was happening. For each note played, a MIDI “note on” command is sent. One of the relevant lines of code is:

midiOutShortMsg1(midihandle,&h403f90)

This calls the “midiOutShortMsg1” wrapper to the midiOutShortMsg() function provided by Windows. (See the code example above for the supporting API calls — there’s some setup needed.) The information as to what to play is contained in the three hex bytes at the end: 40, 3f, and 90.

Breaking these down, the “90” is the status byte, the “3f” is the note number, and “40” is the velocity. The first four bits of the status byte (the “9”) tell us that this is a Note On command, and the second four bits (the “0”) tell us that this command is being sent to MIDI channel zero.

The “3f” is the note number — decimal 63, where the notes are numbered from 0 to 127 with 60 being middle c. So note 63 (3f in hex) is three half-steps above Middle C, or D#4.

Finally, the “40” is the note-on velocity. This translates to 64 in decimal, which is halfway up the velocity scale (and the default velocity sent by keyboards and other instruments which don’t record velocity information.) A good electronic piano would send varying velocity information with the note commands; a harpsichord, which doesn’t have key-velocity dynamics, would probably just send 64 with each note.

With this understanding, a wrapper function can be written to play notes more easily. The FreeBasic code linked below (a spinoff using key pieces of the code linked above) implements the “playNote()” and “stopNote()” functions. Both take (note, velocity, channel) as arguments.

So, once MIDI is initialized and the instrument patch is selected (the default is grand piano), playing middle C is as simple as:

playNote(60, 64, 0)

It’s good MIDI practice to turn the notes off, as well. With patches like the grand piano, it may not matter much, since most instruments will automatically silence the oldest notes as needed if given more to play. But with other patches (pipe organ, violin, etc) which can play continuously, it becomes very important. Sending a Note Off command or a Note On with velocity zero will silence the selected note.

Here is a quick chord demo, easily modified to play whatever notes you like once you know the MIDI note numbers. Share and enjoy!

Posted in BASIC, Coding, HOW-TO, Music | Tagged , , , , , , , , | Leave a comment

A Change In The Weather

The original Weather Prognosticator worked well for several years, but the downside to relying on an external API is that it can get changed out from under you. Or removed entirely.

Last Fall, Weather Underground turned off the API that the Prognosticator had been using. I’d be tempted to ask for my money back, except that it was a free API. Oh, well.

Fortunately, other solutions exist, and OpenWeather’s API is still more or less what is needed. Their hourly data requires a subscription, but three-hour temperature forecasts are still free (within reason.) This means that, instead of displaying hourly temperature forecasts, data is available in three-hour increments — but is available several days out. So instead of displaying hourly data for the next ten hours, the display now shows three-hour temperatures for the next thirty.

The updated code is available here; you will need a free OpenWeatherMap API to be able to use the API.

Enjoy — and stay safe out there!

Posted in Internet, Networking, Projects | Tagged , , , , | Leave a comment