• Home
  • Products
    • Papilio FPGA
    • Arcade MegaWing
    • RetroCade MegaWing
    • LogicStart MegaWing
    • Logic Sniffer
    • Papilio Wings
  • Store
    • Gadget Factory Store
    • India Store
    • Distributers
  • Wikis
    • Papilio Wiki
    • Arcade Wiki
    • RetroCade Wiki
    • Logic Sniffer Wiki
  • Forum
  • Showcase
  • Downloads
  • Source Code
  • Home
  • Products
    • Papilio FPGA
    • Arcade MegaWing
    • RetroCade MegaWing
    • LogicStart MegaWing
    • Logic Sniffer
    • Papilio Wings
  • Store
    • Gadget Factory Store
    • India Store
    • Distributers
  • Wikis
    • Papilio Wiki
    • Arcade Wiki
    • RetroCade Wiki
    • Logic Sniffer Wiki
  • Forum
  • Showcase
  • Downloads
  • Source Code
Previous Next

Papilio Schematic Library – Atari YM2149 Player

Posted by: Jack Gassett , December 9, 2013
This Tutorial was written before the first release of DesignLab IDE. The schematic portion and the sketch portion were treated separately, DesignLab brings the two projects together. This tutorial uses old, pre-DesignLab methodology but it is still applicable to DesignLab.
Listen to the vast library of Atari ST YM files on your Papilio! 

Follow along and see how easy it is to draw up a custom ZPUino Soft Processor that can playback YM2149 audio files using the Papilio Schematic Library. No special FPGA knowledge or VHDL skills are required! If you can work with the Arduino then you should feel very much at home with this tutorial.


Note
This tutorial is a variation of the Commodore 64 SID Audio Player Tutorial, since most of the topics of this tutorial were already covered in detail we are going to keep this short and to the point. If you have not already done so it is recommended to follow the SID tutorial to learn the concepts in greater detail.

Full Walkthrough Video

Prerequisites

Install Xilinx ISE Webpack

Install Papilio Loader

Install the Papilio Schematic Library

Install ZAP IDE

Hardware

Papilio One?

This project WILL work on the Papilio One 500K.

This tutorial is going to use the Papilio Pro with an Audio Wing connected to Wing Slot CH.

Hardware

Hardware Video

Press fullscreen button in Youtube video and select HD 720p  for best quality.

Create New Project

 To make a new project you are going to want to navigate to the “Papilio_Schematic_Library\Papilio_Schematic_Projects” directory. Once there make a copy of the “Papilio_Schematic_Library_Base_Template” folder and rename it to whatever you want you project to be called. If you want a pre-existing example of this project please take a look at the “Audio-YM2149-simple” folder.

Go into your new directory and open the xise file for the Papilio Pro, this will cause Xilinx ISE to open the project.

Open Project

 

Once the project is open double click on the Top Level Schematic file in the Design/Hierarchy pane.

Open Schematic

Missing SymbolsWarning – If you get a Symbol Library Error message that means that you do not have the Symbol Library setup in Xilinx ISE yet. Please follow the PSL Getting Started Guide to properly install the Symbol Library. You can also watch the walkthrough video for this tutorial, start at 4:40 to see how to fix the missing symbols.

 

 

If everything is setup correctly you should see a base project that looks like this:

Base Schematic

New Project Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

 

Add YM2149 Device to Schematic

Clear Wishbone Slot 5

You want to remove the Wishbone_Empty_Device symbol and the attached nets from Wishbone Slot 5. Select all items and press the delete key.

Delete Wishbone

 

Add YM2149 Symbol

1) Click Symbols tab

2) Choose “.Papilio Peripherals – Wishbone” in the Categories tab

3) Choose “AUDIO_zpuino_wb_YM2149” symbol

4) Drag the symbol onto your schematic page

5) Connect the YM2149 symbol to Wishbone slot 5

6) Drag down until it is lined up with Wing Slot CH

Add YM2149 Device Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Supporting Circuitry

Add DeltaSigma DAC

We will add the clocks a little bit later but for now we need to convert the digital audio data into something that we can output onto a single pin as an analog signal. The easiest way to do that is to push the digital audio data into a DeltaSigma DAC (Digital to Analog Converter).

1) Click Symbols tab

2) Choose “.Papilio Peripherals – Standalone” in the Categories tab

3) Choose “AUDIO_zpuino_sa_sigmadeltaDAC” symbol

4) Drag the symbol onto your schematic page and connect it to the output of the YM2149

DeltaSigma DAC

 

Tip – DeltaSigma DAC’s are useful for lots of applications, to learn more check out these helpful links.
Wikipedia
Introduction to Delta Sigma DACs
How DACs Work

 

Add Two Channels

As you can see our DAC only outputs one audio channel, but we are going to connect to an Audio Wing that has two channels. We will need to split the single audio channel into two channels using the splitter.

1) Click Symbols tab

2) Choose “.Papilio Peripherals – Standalone” in the Categories tab

3) Choose “AUDIO_zpuino_sa_splitter2” symbol

4) Drag the symbol onto your schematic page and connect it to the output of the DeltaSigma DAC.

Splitter

Delta Sigma DAC and Splitter Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Connect Audio Wing to Wingslot CH

Now that we have two audio channels we need something to connect them to. With the Papilio Schematic Library it is easy to interface with physical hardware connected to your Papilio board. In this tutorial we are connecting an Audio Wing to Wingslot CH as shown in this picture.

Hardware

 

In our schematic we can add our Audio Wing by removing the GPIO symbol from Wingslot CH and replacing it with the Audio Wing symbol. When we do that the features of the Audio Wing will be accessible to the rest of our schematic. In this case two audio channels will be available to connect to the splitter we just added.

Remove GPIO Wing from Wingslot CH

Highlight the GPIO Wing and nets connected to Wingslot CH and press the delete key to remove them which will free up that wingslot for our Audio Wing.

Remove CH

 

Add the Audio Wing

1) Click Symbols tab

2) Choose “.Papilio Hardware” in the Categories tab

3) Choose “Wing_Audio” symbol

4) Drag the symbol onto your schematic page and connect it to empty CH Wingslot.

Audio Wing Symbol

 

Draw Wires

The final step is to draw two wires connecting the splitter to the Audio Wing.

Connect Audio Wing

Audio Wing Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Connect the Clocks

The DeltaSigma DAC requires an input clock, we can see that it wants a 96Mhz clock.

DS DAC Clock

 

Connecting clocks is real easy in the Papilio Schematic Library, the Soft Processor will have clock outputs that you can use to drive the clock inputs you need. Remember inputs are on the left of a symbol and outputs are on the right of a symbol. Here are the clock outputs on the Soft Processor.

Soft Processor Clocks

 

So all we have to do to connect the clocks is draw a wire between the clock output on the Soft Processor to the clock inputs of our DeltaSigma DAC. You should be able to just click on each pin and let the auto router draw the connection for you.

96Mhz Clock

96Mhz Clock

Connect Clocks Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Finished Schematic

Your final schematic should look something like this.

Schematic - YM Audio

Synthesize Bit File

Now that our schematic is complete we are ready to synthesize our custom design into a bit file that can be loaded to the Papilio FPGA board.

1) Click Design Pane

2) Hightlight Top Level design in the Hierarchy Pane (Top Level is the one with three boxes in a tree formation with the top box green.)

3) Double Click on Generate Programming File to start synthesizing the design.

Synthesize-General

You will see messages start to fly by on the Console window. This will take a little while so its a great time to take a break!

When the process is complete you should see a message that says, “Process ‘Generate Programming File’ completed successfully”.

Synthesize Project Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Load the Design to your Papilio

If the synthesis worked correctly then you will see a message that says, “Process ‘Generate Programming File’ completed succesfully.”

You will be able to find a newly created bit file in your project directory. Switch to the directory that you created the project in and look for a *.bit file. If you have not renamed the project it should be named, “papilio_soc_base.bit”.

Select File

At this point you will want to connect your Papilio FPGA board to a USB port on your computer.

Right click on the bit file and select, “Write permanently to Papilio board”.

Write to SPI FLash

Warning – If you do not see any options when right clicking on the bit file then please ensure that you have installed the Papilio Loader software and drivers. Take a look at the Papilio Getting Started Guide for help.

SPI FLash

Important – You must write any ZPUino bit files to SPI Flash instead of directly to the FPGA. The ZPUino is designed to use a bootloader that transfers code from SPI Flash to internal memory at boot. The ZPUino will not function correctly if you just write it to the FPGA. Selecting the Write permanently to Papilio board causes the bit file to be written to SPI Flash. Alternately, you could load the bit file up in the Papilio Loader and choose the SPI Flash from the drop down box.

Load to Papilio Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Make Sketch in ZAP IDE

Next up is testing out our brand new electronics on a chip design! We are going to use a test sketch in the ZAP IDE to kick the tires and make sure everything works as expected.

Open up the latest version of the ZAP IDE, if you do not have it installed yet then please refer to the ZAP Getting Started Guide.

Open up a brand new sketch and paste the following code in:

/*
  Gadget Factory
  YM2149 Audio Player Example

 SID libraries
 http://www.papilio.cc/index.php?n=Papilio.YM2149
 http://www.papilio.cc/index.php?n=Papilio.YMVoice

 Hardware:
 Will work on Papilio Pro and Papilo One 500K
 This will work with any hardware with an audio jack: Audio Wing, LogicStart MegaWing, Arcade MegaWing, RetroCade MegaWing.

 ZPUino Variant:
 Use the Papilio Schematic Library to create a ZPUino that contains the YM2149 audio component.

 created 2013
 by Jack Gassett
 http://www.gadgetfactory.net

 This example code is in the public domain.
 */
 #define FREQ 17000          //Freq for ymplayer

#include <SD.h>
#include "YM2149.h"
#include "SmallFS.h"
#include "ymplayer.h"
#include "ramFS.h"
#include "cbuffer.h"

YMPLAYER ymplayer;
YM2149 ym2149;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

   //Start SmallFS
  if (SmallFS.begin()<0) {
	//Serial.println("No SmalLFS found.");
  }
  else{
     //Serial.println("SmallFS Started.");
  }  

  //Set what wishbone slot the ym2149 device is connected to.  
  ymplayer.setup(&ym2149,5); 

  ym2149.V1.setVolume(11);
  ym2149.V2.setVolume(11);
  ym2149.V3.setVolume(11);   

  ymplayer.loadFile("music.ymd");
  ymplayer.play(true);

 //Setup timer for YM and mod players, this generates an interrupt at 17Khz
  TMR0CTL = 0;
  TMR0CNT = 0;
  TMR0CMP = ((CLK_FREQ/2) / FREQ )- 1;
  TMR0CTL = _BV(TCTLENA)|_BV(TCTLCCM)|_BV(TCTLDIR)|
  	_BV(TCTLCP0) | _BV(TCTLIEN);
  INTRMASK = BIT(INTRLINE_TIMER0); // Enable Timer0 interrupt
  INTRCTL=1;    

}

void _zpu_interrupt()
{
  //Interrupt runs at 17KHz
  ymplayer.zpu_interrupt(); 
}

void loop() {
  // put your main code here, to run repeatedly: 
  if (ymplayer.getPlaying() == 1)
    ymplayer.audiofill();
}

Add a YM file to smallFs

The best way to make a YM file available to our sketch is to put it into SPI Flash using the smallFS library. It’s very easy to do, the library does all of the heavy lifting for us, we just need to create a directory named “smallfs” in our sketch directory, copy our mod file into it, and open that file in our sketch.

1) The first step is to open up our sketch’s project directory, be sure you have saved the code first, then go to “Sketch/Show Sketch Folder” in the ZAP IDE.

Show Sketch Folder

 

2) In your sketches folder create a new directory named “smallfs”.

3) Copy a mod file of your choice into the smallfs directory and name it “music.ymd”.

Important – This player does not play ym files directly, you must first convert ym files to a ymd file using the batch file in the ym_converter directory.

 

Open Sketch Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Important Parts of Sketch

Set mod filename

If you are wondering why we named the mod file in smallfs “music.ymd” we can look at the sketch code and see that we have hard coded that name into the sketch.

We see the following code on line number 53:

ymplayer.loadFile("music.ymd");

 Set Wishbone Slot

A very important piece of the code is where we define what Wishbone slot the YM2149 chip is connected to. If we look back at our schematic we see that we connected the YM2149 chip to Wishbone slot 5.

If we look at line 47 of the code we see the setup function for the ymplayer, we pass the Wishbone slot we have used in our Soft Processor as an option to the setup function.

//Set what wishbone slot the YM2149 device is connected to.
ymplayer.setup(&ym2149,5);

If you have used a different Wishbone slot then just change this line to reflect your setup.

Upload Sketch and Hear Sweet Music!

Make sure your Papilio board is connected to the USB port and check that you have the correct settings.

Select the correct board type, you want ZPUino 1.0 and then choose the Vanilla variant for the type of Papilio board you have.

Ensure the second serial port is selected.

Click the “Upload” icon to load the sketch to your custom Soft Processor.

Upload Sketch

You should see the progress in the console window on the bottom portion of the ZAP IDE. The things to watch for are something about the SmallFS filesystem being found and that the Programming completed successfully.

Programming Completed

If all went well you should be hearing the sweet, sweet retro sounds of an Amiga MOD file!

Upload Sketch Video

(Press fullscreen button in Youtube video and select HD 720p  for best quality.)

Comments

comments

About Gadget Factory

We make Open Source Hardware that is extremely Hackable, what we call Hack|Ware. Founded in 2009 by Aspiring Inventor Jack Gassett, we are hardware suppliers and inventors with a community focused approach. Home of the Papilio FPGA board and other open source hardware designs.

Located in Denver, Colorado just minutes away from beautiful Boulder, Colorado.

Gadget Factory Learning Site

Inspired by the excellent learning sites at Adafruit and Sparkfun we made our own learning site with tutorials about FPGA's, Electronics, and Making Open Source Hardware. If you have tutorials you would like to contribute please contact us at support@gadgetfactory.net.

If you have a project or code that you would like to share please post to the Showcase website.
© Gadget Factory 2013