YM2612 write/read/register select

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

YM2612 write/read/register select

Post by foobat » Fri Sep 14, 2012 1:21 pm

Hi all, this is my first post here!

I'm doing some hardware interfacing between a YM2612 and a Teensy++, but I'm having a little trouble getting started. I hope you can help.

I expected that I would be able to select register 22h, then write 0x0F (pins 0, 1, 2, 3 high and pins 4, 5, 6, 7 low), then select 22h again and read from it. I was expecting to get 0x0F back. Instead I appear to get all zeroes every read.

Should this work? If I read, should I see the contents of the currently selected register?

This is my process:
1. Reset pin high, CS pin low (these will never change)
2. RD high, WR high, A0 low, A1 low
3. Write 22h on the 8 data pins
4. RD high, WR low, A0 high, A1 low
5. Write 0x0F on the 8 data pins
6. RD high, WR high, A0 low, A1 low
7. Write 22h on the 8 data pins
8. RD low, WR high, A0 high, A1 low
9. Read the 8 data pins

Is this correct?

Thank you for taking the time to read my post! I really appreciate it.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Fri Sep 14, 2012 2:02 pm

Hi,

you should talk with sigMate, he did (almost) the same thing :

read this post
viewtopic.php?t=1122

Charles MacDonald
Very interested
Posts: 292
Joined: Sat Apr 21, 2007 1:14 am

Re: YM2612 write/read/register select

Post by Charles MacDonald » Fri Sep 14, 2012 11:29 pm

Sadly you can't read from any of the registers. They are all write-only, and reading from any of the four addresses only returns the status flags.

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Re: YM2612 write/read/register select

Post by foobat » Sat Sep 15, 2012 12:30 am

Charles MacDonald wrote:Sadly you can't read from any of the registers. They are all write-only
This helps so much man, thanks for the info.

Does anybody know if my process up top is correct? I haven't gotten the chip to produce any audio yet. I currently have 10k pull-down resistors connecting MOL and MOR to ground. Can I then connect my headphones in parallel to the 10k resistors?

Charles MacDonald
Very interested
Posts: 292
Joined: Sat Apr 21, 2007 1:14 am

Re: YM2612 write/read/register select

Post by Charles MacDonald » Sat Sep 15, 2012 2:16 am

Does anybody know if my process up top is correct?
Not quite, but you almost have it. When you output a value on the data bus, you need to bring WR low then high. Only then can you change the data to a new value and start a new write. Think of the rising edge of WR latching the data in the chip.

So writing looks like this:

1. CS=L, RD=H, WR=H, output the data value you want on the data bus
2. CS=L, RD=H, WR=L, don't change the data
3. CS=L, RD=H, WR=H, don't change the data

Now you can repeat this process for a new write.

It's a nitpick, but some chips (maybe not the YM2612) depend on CS going high again after a read or write. So the complete sequence is:

Idle:
CS=H, RD=H, WR=H, Addr=Any, Data=Any

Write:
1. CS=H, RD=H, WR=H, Addr=Your address, Data=Your data
2. CS=L, RD=H, WR=H, Addr=Your address, Data=Your data
3. CS=L, RD=H, WR=L, Addr=Your address, Data=Your data
4. CS=L, RD=H, WR=H, Addr=Your address, Data=Your data
5. CS=H, RD=H, WR=H, Addr=Your address, Data=Your data

CS means the address lines are valid, so only change A1,A0 when CS is high. It may work on the YM2612 to keep CS low and change A1,A0 however, but that would be sort of a non-standard way of using the chip.
I haven't gotten the chip to produce any audio yet. I currently have 10k pull-down resistors connecting MOL and MOR to ground. Can I then connect my headphones in parallel to the 10k resistors?
You need an amplifier to drive headphones (or a speaker). Don't connect either directly to the YM2612. I think somebody posted here earlier (or maybe it was on SMS Power with the YM2413) about doing that and the chip got hot and died since it can't handle the load.

At least with the YM2413 I ran the output into a LM348 op-amp configured as a voltage follower, and then the output of that into the line-in input of my PC soundcard. This way I didn't need a dedicated amplifier IC. There are probably other ways to do this.

Can't wait to see (err, hear) the results of your project! :D

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Post by foobat » Sat Sep 15, 2012 2:34 am

man you guys are amazing, thanks a lot! I'll definitely post vids and a howto if I get this working!

I can't believe so many people are working on stuff like this, it's crazy awesome. This forum seems really active.

I just shot a few bux over via http://gendev.spritesmind.net/page-help.html ;)

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Post by foobat » Sat Sep 15, 2012 3:58 am

No seriously dude, you are great! My YM2612 just made its first piano sound :)

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Sat Sep 15, 2012 2:22 pm

I posted that it will get hot but I think there is more to that I am under an impression that I may have bought a relabeled part. I have heard alot of people having trouble with SID chips and the ym2612 is also a "famous" sound chip too so I think that what may be under in the plastic may not be ym2612 or I may have been doing something wrong. I have checked my wires many times. I have got two and I am interested in decaping one I do have a good CNC router that could aid in the process. Here is a picture of both of the ym2612 I bough
Image
Edit image too big click on thumbnail to see full res.

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Post by foobat » Sat Sep 15, 2012 2:59 pm

My crappy code is here if you want to test your chips against it: http://7355608.net/sketchbook/ym2612/ym2612.ino

I have pins d0 through d7 connected directly to the Teensy++ pins 0-7 and everything else clearly declared at the top of the file. The only nonstandard things I did were:

Used two 10k resistors to connect MOL and MOR each directly to ground (pull-down resistors)
Connected an LM386 just as suggested here to MOL as a voltage follower, attached my speaker's + to the output of that and - to ground.

There's also a status LED on pin 45.

I use a 7.68mhz 4-pin crystal oscillator to drive øM

This should run on an Arduino Uno with only changing constants. You should still use pins 0-7 for the data bus pins.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sat Sep 15, 2012 5:42 pm

You can keep !CE low all times, the YM won't mind it. !WR and !RD do have to be pulsed to do a write or read.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Sat Sep 15, 2012 7:26 pm

Oh wow thank you for the code I have finally got it to work! :D

Charles MacDonald
Very interested
Posts: 292
Joined: Sat Apr 21, 2007 1:14 am

Post by Charles MacDonald » Sat Sep 15, 2012 11:01 pm

Congratulations on getting it to work! This is a cool project and the Teensy seems like a good fit for FM soundchips.
Connected an LM386 just as suggested here to MOL as a voltage follower, attached my speaker's + to the output of that and - to ground.
Just FYI the LM348 isn't really intended to drive headphones/speaker directly, but it's fine for driving a line-in input. So like if the circuit stops working in a month, maybe the LM348 burned out. :P

On the flip side the circuit does work and that's all that matters!

@sega16:

Ah, so the chip was good and in working order after all?

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Post by foobat » Sat Sep 15, 2012 11:22 pm

I actually have the lm348 plugged into an amplifier I scrounged from a set of pc speakers so I think it's OK for now. I just wanted to give sega16 the simplest possible explanation for getting his chips in a known state. Without the amplifier it's so quiet you can just barely hear it, but it's enough to know the chip is working.

I'm really glad you got your circuit working dude, your "too hot" thread was really helpful to me (I didn't know I would need pulldown resistors on the outputs until I read it).

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Sat Sep 15, 2012 11:43 pm

Yep it is all good It was my fault that it did not work I tried alot of things so I ended up assuming it was dead but now it works just fine. It turns out that my code was wrong and the reason it got hot is still unknown to me. I have better find a dual op amp I think I have one some wear or is it ok to just plug it directly into my microphone jack?

foobat
Very interested
Posts: 92
Joined: Fri Sep 14, 2012 1:06 pm

Post by foobat » Sun Sep 16, 2012 1:35 pm

I wouldn't, use the lm348 and/or a proper amplifier.

I did some more work today; I made a very rudimentary VGM file parser. So far I've only used it with that one btc.vgm file, a recording of Behind the Circuit from Phantasy Star 4. If you build it with gcc in Linux or mingw, it will read from the file "btc.vgm" and barf text to stdout that you can paste into your code. I made it based on this doc: http://www.smspower.org/uploads/Music/v ... 7f0e3bd1ee

code here: http://7355608.net/sketchbook/ym2612/
(temporary url, might disappear any time)

btc.ino is some sample barf if you want to fool with it and don't have Linux. The timings are all messed up so it doesn't sound good and skips portions but you can definitely tell that the proper notes are getting played.

I also made some janky edits to ym2612.ino so it can access the 2nd set of registers.

The idea is that if I can parse VGM files, I can eventually extract instrument voices from them that can be used to make a rad midi synthesizer. It does sound kind of cool to play a real song from one of my favorite games when I was a kid, though, so I might put the effort into handling the delay cycles properly. I'll also have to figure out a way to play recordings that doesn't involve pasting it into my code lol
Last edited by foobat on Sat Oct 13, 2012 3:22 am, edited 1 time in total.

Post Reply