Combo organ: Top octave emulation

Given the scarcity of combo organ top octave generator ICs, what’s a hack supposed to do? Emulate!

I posed a “bar bet” against myself — can I emulate a top octave generator chip with an Arduino? The Arduino is a bit slow and I wasn’t sure if it would be fast enough for the task. Good thing I didn’t best against it…

If you browse the Web, you’ll find other solutions. I chose Arduino UNO out of laziness — the IDE is already set-up on my PC and the hardware and software are easy to use. Plus, I have UNOs to spare. Ultimately, one can always cobble together a barebones solution consisting of an ATMEGA328P, a 16MHz crystal and a few discrete components, if small size is an issue.

A simple passive volume control

There’s not much ancilliary hardware required. A few jumper wires bring out ground and audio signals from the UNO. I passed the audio through a trim pot volume circuit in order to knock the 5 Volt signal down to something more acceptable for a line level input. The trim pot feeds a Sparkfun 3.5mm phone break-out board which is connected to the LINE IN of a powered speaker.

That’s it for the test rig. The rest is software.

I assigned a “root” pitch to Arduino digital pins D2 to D13:

#define CnatPin 13 
#define BnatPin 12
#define AshpPin 11
#define AnatPin 10
#define GshpPin 9
#define GnatPin 8
#define FshpPin 7
#define FnatPin 6
#define EnatPin 5
#define DshpPin 4
#define DnatPin 3
#define CshpPin 2

Thankfully, the Arduino has just enough available pins to do the job while avoiding pins D1 and D0. D1 (TX) and D0 (RX) carry the serial port signals and it’s best to let them do that job alone.

My basic thought algorithm-wise was to implement 12 divide-down counters (one per root pitch) that decrement during each trip through a non-terminating loop. Each counter is (pre-)loaded with the unique divisor which produces its assigned root pitch. Whenever a counter hits zero, the code flips the corresponding digital output pin. If the loop is fast enough, we should hear an audio frequency square wave at the corresponding digital output. This approach is (probably) similar to the actual guts of the Mostek MK50240 top octave generator chip, except that the MK50240 counters operate in parallel.

Each root pitch needs:

  • A digital output pin
  • A note count variable
  • A divisor
  • A state variable to remember if the output is currently 0 or 1

For the highest pitch, C natural, we need declarations:

    #define CnatPin 13 

byte CnatCount ;

#define CNAT (123)

byte CnatState ;

and count down code to be placed within the loop body:

    if (--CnatCount == 0) { 
digitalWrite(CnatPin, (CnatState ^= 0x01)) ;
CnatCount = CNAT ;
}

These are the basic elements of the solution. The rest of the pitches follow the same pattern.

Now, for the fun — making the loop fast enough to be practical. This was a bit of a journey!

First off, I tried the MK50240 divisor values which require at least 9 bits for representation. Using INT (16-bit) counter variables, everything worked, but the final note frequencies were too low — not much “top” in top octave. I cut the divisor values in two, switched to BYTE (8-bit) counter variables, and doubled the output frequencies. Yes, AVR (Arduino) BYTE arithmetic is roughly twice as fast as INT arithmetic. That was the first lesson learned.

The next lesson had to do with how the counters were stored (register vs. memory). If I were writing the code in assembler language, I would have stored all of the counters in AVR CPU registers. (AVR has 32 CPU registers, after all.) Register storage would provide the fastest counter access and arithmetic. However, this is where C language and the Arduino setup()/loop() structure fight us.

Ultimately, I put all code into setup() and ditched loop(). I declared all twelve counters as register BYTE variables in setup():

    register byte CnatCount ; 
register byte BnatCount ;
register byte AshpCount ;
register byte AnatCount ;
register byte GshpCount ;
register byte GnatCount ;
register byte FshpCount ;
register byte FnatCount ;
register byte EnatCount ;
register byte DshpCount ;
register byte DnatCount ;
register byte CshpCount ;

The compiler allocated the counter variables to AVR CPU registers. This enhancement doubled the output frequencies, again. Now we’re into top octave territory!

The third and final lesson was tuning. The Mostek MK50240 is driven by a crystal-controlled 2000.240 kHz master clock. The emulated “master clock” is determined by the speed of the non-terminating loop (cycling at the so-called “loop frequency”):

    for (;;) { 
if (--CnatCount == 0) {
digitalWrite(CnatPin, (CnatState ^= 0x01)) ;
CnatCount = CNAT ;
}

...

delaySum = delaySum + 1 ;
}

My original plan was to tune all twelve pitches by changing the speed of the non-terminating loop. I discovered that such timing was too sensitive to code generation to be controllable and reliable. The biggest delay that I could add to the non-terminating loop was “delaySum = delaySum + 1 ;“. In the end, I manually tuned the individual note divisors.

A fine point: I chose the divisors to achieve a wide resolution in 8 bits. Eight bits is “close enough for rock and roll,” but not really enough for accurate tuning.

As usual, the path to the solution was zig-zaggy and not straight. Here is a ZIP file with all of the code and my working notes. I included source code for the intermediate experiments so you can re-trace my steps. Have fun!

Copyright © 2021 Paul J. Drongowski

Combo organ: Top octave generator

So far, we’re taken a short trip through combo organ technology from early days in the 1960s to modern day workstation voices:

I hope you enjoyed those articles! This post fills in the middle bits — how large scale integration changed combo organ design.

Farfisa tone generation circuit

During the 60s, Vox, Farfisa and other manufacturers employed a similar approach to tone generation. Each organ contained twelve tone generation boards one for each semi-tone in the Western well-tempered scale. Each board implemented:

  • An oscillator to produce the a base root tone, and
  • Several (digital) dividers to derive the ancilliary tones one or more octaves below the root tone.

Vox, Farfisa, and so on used discrete components (transistors, resistors, capacitors, etc.) to implement the oscillator and dividers. These boards were dense and busy with many hand-soldered joints. The Farfisa board, for example, contained 12 transistors, 40 resistors, 25 capacitors and a tunable inductor coil. Assembling, testing and debugging a board like that is quite expensive and labor intensive.

Having lived through the transition from discrete semiconductor circuits to small scale integration (SSI) and then large scale integeration (LSI), I can attest to the revolution initiated in the LSI era. (Not to mention the transition to very large scale integration!) LSI and mixed signal components enabled sound generators like the Texas Instruments SN76477 Complex Sound Generator, General Instruments AY-3-8910/8912, and other ICs — and sounds — favored by chip-tune enthusiasts.

LSI revolutionized combo organ design, too. Mostek (and others) introduced top octave tone generator chips. The well-known Mostek MK50240 (PDF datasheet) has inputs for power, ground and master clock:

    Pin#  Name  Purpose 
---- ---- --------------
1 VSS Supply voltage 15V (typical) 11V (min) 16V (max)
2 Clock Clock 2000.240kHz (typical), 2500kHz (max)
3 VDD Ground

The MK50240 generates each of the high frequency root tones:

    Pin#  Note  Divisor 
---- ---- -------
16 CLow 478
4 C# 451
5 D 426
6 D# 402
7 E 379
8 F 358
9 F# 338
10 G 319
11 G# 301
12 A 284
13 A# 268
14 B 253
15 CHigh 239

The MK50240 has twelve dividers which divide the master clock frequency into the root tone frequencies.

Advantages of the MK50240 should be readily apparent! A single MK50240 replaces all twelve oscillators. Even better, the master clock can be generated from a 2000.240 kHz crystal resulting in superior temperature (pitch) stability. Old discrete circuits are notoriously temperature sensitive.

But, wait, there’s more. Thanks to digital LSI, each divider chain can be replaced by an MOS ripple counter. Consider the CMOS CD4024. (Please see the CD4024B functional diagram below.) The CD4024 is a 7-stage ripple counter that divides the incoming clock signal into seven auxilliary tones at each octave below the input frequency.

The nightmare of discrete oscillators and dividers can be replaced by a single MK50240 and 12 CD4024 ripple counters: 13 dual in-line packages (DIPs) and a handful of coupling capacitors for good measure.

Of course, one must still confront the rat’s nest of wires and signal diodes needed for key switching… To get a sense of wiring complexity, I suggest looking at the design of the vintage PAiA Stringz ‘n’ Thingz digital keyboard or PAiA Oz portable mini-organ. Yes, I assembled a Stringz ‘n’ Thingz — without too many bad solder joints, thank goodness. Organ wiring was a nightmare before microcomputer-based key switch scanning and digital control.

With LSI and micro-computers, organ builders collectively breathed a sigh of relief. Unfortunately, ease of design and manufacture came with a penalty — lack of sonic charm. Each of those old-tyme discrete oscillators were slightly out-of-tune with one another. Thus, there’s a subtle richness in the old discrete designs that is missing in full-on digital implementations.

Before leaving the MK50240 behind, I want to mention the PAiA EK-1 top octave experimenter’s kit.

PAiA EK-1 board (component side)
PAiA EK-1 board (trace side)

PAiA was (and is) a terrific resource for experimenters. I built several PAiA kits including the Stringz ‘n’ Thingz and the Gnome synthesizer. I also played with the PAiA EK-1 top octave experimenter’s kit. If you would like to learn more about the Mostek MK50240, check out the PAiA EK-1 instruction booklet. Shame you can’t find many MK50240s today…

Copyright © 2021 Paul J. Drongowski