genuinequality

Download free music MP3s on genuine quality, the world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, The world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, stats, charts, biographies and concerts. stats, charts, biographies and concerts.

Saturday, July 5, 2025

Arduino and AY-3-8910

I've had some AY-3-8910 programmable sound generators for a while and planned to do something with them, but they've sat in the "to think about" box for a while. But recently getting hold of the WhyEm sound card for the RC2014 has re-awakened my intere…
Read on blog or Reader
Site logo image Simple DIY Electronic Music Projects Read on blog or Reader

Arduino and AY‑3‑8910

By Kevin on July 5, 2025

I've had some AY-3-8910 programmable sound generators for a while and planned to do something with them, but they've sat in the "to think about" box for a while. But recently getting hold of the WhyEm sound card for the RC2014 has re-awakened my interest.

This is some "first looks" experiments with the AY-3-8910 and an Arduino.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

  • Arduino AY3891x Library: https://github.com/Andy4495/AY3891x
  • Arduino Nano AY-3-8910 PCB: https://github.com/GadgetReboot/AY-3-8910

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Arduino Uno
  • AY-3-8910 chip
  • Either GadgetReboot's PCB or patch using solderless breadboard or prototyping boards.

The AY-3-8910 PSG

The AY-3-8910 programmable sound generator is quite an iconic chip of its time. Not as popular maybe as the SID used in the Commodore 64, but still pretty widespread use in 8-bit computers of the time and apparently a number of arcade machines too.

There are a number of "compatible" chips, including the Yamaha YM2149. There is also the AY-3-8912 which is the same as the 8910 but without one of the general purpose IO ports, which take no part in the sound generation.

I'm not going to go into the details of the device itself, for that I'll refer to the following resources:

  • https://en.wikipedia.org/wiki/General_Instrument_AY-3-8910
  • https://www.vgmpf.com/Wiki/index.php/AY-3-8910
  • https://rc2014.co.uk/modules/why-em-ulator-sound-module/
  • http://blog.tynemouthsoftware.co.uk/2023/01/driving-ay-3-8910-ym2149-from-8-bit.html

The summary of the specification though is as follows:

  • Three square wave output channels.
  • Global AD envelope generator, with a selection of fixed envelopes.
  • Noise generator an option on the channels.
  • Mixer.

There is an 8-bit data register interface to the chip along with three control signals (BDIR, BC1 and BC2).

I should point out that it isn't possible to buy new AY-3-8910 or YM2419 chips these days, so any that can be found online are almost certainly reclaimed from older hardware. These may or may not work reliably, but it will be a bit of a lottery.

There is a lot of discussion about the issue here: http://blog.tynemouthsoftware.co.uk/2023/01/testing-ay-3-8910-ym2149-sound-card-for-rc2014-and-minstrel-4D.html

This is why RC2014 eventually went with the "Why Emulator" approach: https://rc2014.co.uk/modules/why-em-ulator-sound-module/

Hardware

For once, I'm using someone else's design for my initial messing about. There is a schematic and some hardware built on a protoboard shown in the Arduino YM3891x library here: https://github.com/Andy4495/AY3891x/tree/main/extras/hardware

But there is a PCB that was designed by GadgetReboot here: https://github.com/GadgetReboot/AY-3-8910. This can be ordered directly from PCBWay and so that is what I've used.

The only thing to watch out for, is that D2/D3 are reversed compared to the protoboard hardware. So whilst all other pin definitions in the library examples are fine, D2 and D3 need to be swapped to use them with the PCB.

I also didn't bother to add the power LED (and R5), the toggle switch or the additional header pins.

The full pinout interface for the Arduino is as follows:

AY-3-8910 Arduino
DA0-DA7 D2-D8, A3
BC1 A0
BC2 A1
BDIR A2
CLOCK D9

The most critical one from a re-use point of view is the clock as the code uses the ATmega328P hardware Timer 1 to output a 50% duty cycle PWM signal on output OC1A (D9) to generate the 1MHz clock required by the AY-3-8910.

Using a different microcontroller will mean re-writing this part of the code for a suitable replacement timer.

The Code

Taking the "AY3891x_EX3_Simple_Tone" example as a starting point, the following line needs updating as shown below:

// Original line
AY3891x psg( 17, 8, 7, 6, 5, 4, 2, 3, 16, 15, 14);

// Required for use with the PCB
AY3891x psg( 17, 8, 7, 6, 5, 4, 3, 2, 16, 15, 14);

I also switch any Serial.begin() statements to use 9600 baud for preference too.

With these changes, the simple tone example just works, as does the "AY3891x_EX8_Check_Orig_or_Clone", which tells me I have an AY-3-8910 rather than a YM2149.

But what I really wanted was to play one of the tunes from a game I remembered. My first introduction to AY-3-8910 music was the 128K Spectrum version of The Neverending Story. This was one of the two games that came bundled with the original machine, and for someone used to the 48K beeps and boops it was an amazing upgrade.

Unfortunately I don't seem able at present to find a "YM" file version of that tune to play, so instead I turned to a David Whittaker classic - "Glider Rider". The "YM Jukebox" GitHub repository has a whole pile of YM files ready to use here: https://github.com/nguillaumin/ym-jukebox/tree/master/data/David%20Whittaker

There are (I believe) two key ways to get "chiptunes" for the AY-3-8910. A YM file is a stream of the register values sent to the chip to direct the sound generation. With one of these files, it is simply a case of turning these values into a C array and it can be included in an Arduino sketch (there are several steps required, see below, but it is all doable).

Another common way to get tunes is an "AY" file. As I understand things these are the actual Z80 assembler instructions required to drive the AY-3-8910 chip, so extracting the required data for use on another system is not so easy. These are really designed to be used on the original systems or via emulation.

To produce an Arduino source code file from a YM file requires the following steps (described here: https://github.com/Andy4495/AY3891x/tree/main/extras/tools):

  • Find and download the desired YM file.
  • Decode it using: https://github.com/eqy/ymduino/blob/master/decoder.py - the force_interlacing parameter is required to correctly unpick everything.
python decoder.py GliderRider.ym force_interleaved
  • Turn the resulting binary outputfile (it is always called that after using the decoder.py script) into a C structure using: https://github.com/Andy4495/AY3891x/blob/main/extras/tools/bin2c14.py
python bin2c14.py outputfile > chiptunes.h
  • Take the resulting const PROGMEM structure into the "chiptunes.h" file of the "AY3891x_EX6_Chiptunes_Flash" example sketch.

Note that due to the memory limitations of the Arduino Nano, the resulting C structure for the tune will have to be cut-off at around 2000 lines, but be sure to leave the termnating part of the structure:

const byte PROGMEM psg_data[] = {
0x6C,0x07,0x7C,0x07,0x7C,0x07,0x17,0x31,0x0F,0x00,0x00,0x00,0x00,0x20,
....
....
0x7C,0x07,0xBE,0x03,0x58,0x02,0x01,0x31,0x09,0x0E,0x00,0x00,0x00,0x00,
};

If there are build errors, then it might be because the structure is still too long. 2000 lines fits for me using around 97% of the programme memory of the Arduino Nano.

If full (longer) tunes are required, then the PCB has the option to hook up to an SD card and longer files can be stored there.

Closing Thoughts

I've really not done very much myself this time. The PCB was from GadgetReboot. The library from Andy4495. The tune data provided by the YM jukebox and all other scripts and bits of the process were available online.

Now I need to decide what I'd like to do with all this.

Kevin

Comment
Like
You can also reply to this email to leave a comment.

Simple DIY Electronic Music Projects © 2025.
Unsubscribe or manage your email subscriptions.

WordPress.com and Jetpack Logos

Get the Jetpack app

Subscribe, bookmark, and get real‑time notifications - all from one app!

Download Jetpack on Google Play Download Jetpack from the App Store
WordPress.com Logo and Wordmark title=

Automattic, Inc.
60 29th St. #343, San Francisco, CA 94110

Posted by BigPalaceNews at 9:31 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

About Me

BigPalaceNews
View my complete profile

Blog Archive

  • September (105)
  • August (116)
  • July (96)
  • June (100)
  • May (105)
  • April (95)
  • March (131)
  • February (111)
  • January (104)
  • December (98)
  • November (87)
  • October (126)
  • September (104)
  • August (97)
  • July (112)
  • June (113)
  • May (132)
  • April (162)
  • March (150)
  • February (342)
  • January (232)
  • December (260)
  • November (149)
  • October (179)
  • September (371)
  • August (379)
  • July (360)
  • June (385)
  • May (391)
  • April (395)
  • March (419)
  • February (356)
  • January (437)
  • December (438)
  • November (400)
  • October (472)
  • September (460)
  • August (461)
  • July (469)
  • June (451)
  • May (464)
  • April (506)
  • March (483)
  • February (420)
  • January (258)
  • December (197)
  • November (145)
  • October (117)
  • September (150)
  • August (132)
  • July (133)
  • June (117)
  • May (190)
  • January (48)
Powered by Blogger.