Electronic – arduino – How to sync clock frequency to a microcontroller

arduinosynthesizer

I'm building a project which uses old FM synthesis chips – the Yamaha YM2612, which was the sound-generation chip used in the Sega Genesis, and also the TI SN76489, which was also in the Sega.

YM2612 has 8 data pins (D0 to D7) which are used to write to the internal registers of the chip. In order to latch a write instruction (a byte, as it were), then values are assigned to D0 through D7, and then one of the pins is flashed low, and then high on the YM2612 IC. Data can be written to specify the sound type, attack, decay, release, sustain, timbre, frequency, note duration, etc., but it's all transferred this way. The SN76489 is very similar here and also uses 8 input pins which work the same way.

I want to build a project which uses the Arduino, PIC, or another microcontroller to control one of these chips and to use it as a synthesizer, so I can preprogram sound patches and play notes through them. This, of course requires writing data to the registers as described above. The problem I'm having is this:

The Sega chip is controlled with a clock frequency of 8 MHz. If I were to use an Arduino, for example, which has a 16Mhz clock, how can I possibly provide the 8 MHz clock for the sound chip while also synchronizing my Arduino's write instructions to happen at the right times?

Optimally, I would load an 8 bit shift register like the 74HC595 with the eight data bits, and then pull the /WR pin low on the chip, and then put it back high again, so 8 bits have been written. But wouldn't this require the Arduino to operate at the same frequency as the sound chip? Also, if the Arduino executes 16 million instructions per second (nominally, or for this example) then some of the write commands will actually take several cycles, because I will have to write 8 bits in a shift register, which might require 16 instructions or something like that, PER BYTE written to the shift register. This seems to mess up all the considerations of frequency and I have no idea how to go about solving it.

Best Answer

The YM2612 data port will work asynchronously to the sound generation clock. The write timing is such that the data is written only on the rising edge of *WR.

The sequence is this.

a) The YM2612 is busy doing some sounds generation, according to the control bits in its internal registers. Hundreds or millions of clock cycles pass.

b) A key on your keyboard is pressed. The player's measurement of latency starts now. The Arduino sees it, via interrupt or polling, and then figures out what to send to the sound chip. If you're programming this in C, this could take thousands of Arduino cycles.

c) The Arduino takes 10s or hundreds of its clock cycles loading a 595, using its SPI mechanism would be faster and easier than bit-banging. If you are bit banging in C via the digitalWrite() calls, they can take 10s of clocks each to execute, very slow.

d) Eventually, the Arduino pulls the *WR pin low, and must now wait a minimum time with it low. See the 2612 data sheet for how long it must stay low. It's probably one or two cycles of its clock.

e) After that minimum delay, (writing it low and immediately high again by digitalWrite() in C will mean that it's low for 10s of Arduino clocks) it pulls it high again, and the 8 bit data finally gets to the YM2612 internal registers. After any internal delay in the 2612, the sound finally changes. The user hears the sound change.

f) Rinse and repeat

You could drive the Arduino from 8MHz if that's more convenient, though don't forget to set what clock frequency the Arduino uses in the loader program.