A Feersum orchestra

A Feersum orchestra

If you've read Line out for NanoBeast you'll have seen my successful attempt to build a line out interface for my Feersum NanoBeast. The same circuit can be used on the MicroBeast, although it requires some delicate surgery to get it connected up as the MicroBeast lacks a dedicated port for the purpose.

The reason I'm doing this is to compare audio from the NanoBeast with audio from the MicroBeast. I'm in the middle of porting a cache of old ZX Spectrum 1-bit beeper engines, and the MicroBeast and NanoBeast require separate ports of the code due to their slightly different audio output arrangements, so whenever I port a beeper I'm A/B-ing the Speccy original against the MicroBeast and NanoBeast (or maybe that's A/B/C-ing? Did I just invent a new test methodology?)

I bought a cheap-as-chips two channel mixer, because my homebrew hardware probably doesn't have too many plug/unplug cycles in it. This way I can use the mixer controls to switch either the MicroBeast or the NanoBeast to the speakers.

And then it occurred to me...what if we played both at the same time ?

Time is an illusion

My first attempt was by triggering both systems manually, and it was an epic failure. Closest I could get was about half a bar, thanks to serial port delays, human reflexes, trying to hold a camera at the same time etc.

Both the MicroBeast and the NanoBeast run a z80 at 8 MHz, and they probably have the same crystal (haven't actually checked), so if we synchronise the start times, we should have a winner on our hands.

They both have a "User Port" (showing my BBC Micro roots there), so it should be a simple matter to sync them by hardware.

The simplest approach is to have one side change the level of a pin and have the other side read it, but this can be prone to false triggering. I elaborated on this slightly, and had the sender send 8 "pilot" pulses. If it counts 8 echoes coming back, it sends a long start pulse, and the falling edge of that pulse is the signal for both sides to begin whatever program we're trying to synchronize.

The circuit looks like this:

And the board I made looks like this:

Three DuPont wires on this end go to the MicroBeast's PA0 and PA1 pins, and the same deal at the other end going to the NanoBeast.

Got the time

Here's what it looks like in action from the MicroBeast end:

sync is the SynchroBeast program. The m flag means "MicroBeast" and the l flag means "leader". This is the end that actively controls the timing. ulasyn is the program we're going to run: a port of utz's UlasSyn engine (MicroBeast version).

The NanoBeast end is very similar with a couple of crucial differences:

Here the flags are n for "NanoBeast" and f for "follower". The follower just echoes back every pulse it receives. It monitors pulse lengths, and if it ever sees a nice long START pulse it knows that the falling edge is the synchronisation point. We're running ulasyn here too, but this time it's the NanoBeast version.

It's a bit like the Spectrum's tape loading routine: the red and cyan bit before the yellow and blue bit, if you see what I mean.

Time inversion

As I discovered during testing, an unconnected input lead on the MicroBeast will easily pick up its own transmission, causing the MicroBeast to trigger at inopportune moments. I fixed this by having the "follower" invert the polarity of the pulses it sees, and that made it a whole lot more reliable.

The code is available in the SynchroBeast GitHub repo.

The actual synchronisation part is trivial, most of the code is to do with wrapping a second program and aping the CCP.

Time for Trumpton

How does it sound? Judge for yourself!

I'd imagined a gradually building lush chorus as they drifted out of sync before degenerating into cacaphony, but after a couple of hours the effect is barely discernible!

Long time no see

Why does it take so long to sync? I'm not really sure: the first time it did this was when I was recording the video, of course. I suspect it's the RTC interrupt handling on the MicroBeast/NanoBeast getting in the way. I've left interrupts on so I can use the BDOS keyboard routines as I generally use these devices from an attached serial terminal, not the physical keyboard - the NanoBeast doesn't even have a physical keyboard. So I'll probably leave it as it is. Besides, it adds an unexpected element of mystery and surprise to proceedings.

Comments