33

Just thought I'd share my current project: Taking an old ISA sound card I got off eBay and wiring it up to an Arduino to control its OPL3 synth from a MIDI keyboard. I have it mostly working now.

No intention to play audio samples, so I've not bothered with any of the DMA stuff - just MIDI (MPU-401 UART) and OPL3.

It has involved learning the pinout of the ISA bus connectors, figuring out which ones are actually used for this card, ignoring the standards a little (hello, amplifier chip that is wired up to the +12V line but which still happily works at +5V...)

Most of the wires going to it are for each bit of the 16-bit address and 8-bit data. Using a couple of shift registers for the address, and a universal shift register for the data. Wrote some fairly primitive ISA bus read/write code, but it was really slow. Eventually found out about SPI and re-wrote the code to use that and it became very fast. Had trouble with some timings, fixed those.

The card is an ISA Plug and Play card, meaning before I could use it I had to tell it what resources to use. Linux driver code and some reverse-engineering of the official Windows/DOS drivers got me past this stage.

Wired up IRQ 5 to an Arduino interrupt to deal with incoming MIDI data, with a routine that buffers it. Ran into trouble with the interrupt happening during I/O and needing to do some I/O inside the handler and had to set a flag to decide whether to disable/re-enable interrupts during I/O.

It looks like total chaos, but the various wires going across the breadboard are mainly to make it easier to deal with the 16-bit address and 8-bit data lines. The LEDs were initially used to check what addresses/data were being sent, but now only one of them is connected and indicates when the interrupt handler is executing.

There's still a lot to do after that though - MIDI and OPL3 are two completely different things so I had to write some code to manage the different "channels" of the OPL3 chip. I have it playing multiple notes at the same time but need to make it able to control the various settings over MIDI. Eventually I might add some physical controls to it and get a PCB made.

The fun part is, I only vaguely know what I'm doing with the electronics side of this. I didn't know what a "shift register" was before this project, nor anything about the workings of the ISA bus. I knew a bit about MIDI (both the protocol and generally how the MPU-401 UART works) along with the operation of a sound card from a driver/software perspective, but everything else is pretty new to me.

As a useful little extra, I made some "fake" components that I can build the software against on a PC, to run some tests before uploading it to the Arduino (mostly just prints out the addresses it is going to try and write to).

Comments
  • 6
  • 5
    First Arduino project because it looks like you're on a good way. Keep going! Two small tips though:

    1. Screw/glue your prototype together. You can move it around more easily and you won't get sudden inexplicable errors because a random wire became loose.

    2. It's considered good practice to have a (ceramic) 100 nF capacitor on all power supply pins for digital ICs, very close to the pins. The reason is that these tend to draw short and fast current spikes with each signal transition. Those can influence your other circuitry unless you provide a capacitor which can deliver them.
  • 4
    Do you by any chance go by the name Collin Cunningham in the real world (because you know, audio + electronics :3)? This is nothing short of amazing, I love it!
  • 1
    Why did you use Arduino Uno when you can use a 32bit mcu that it's cheaper and faster?
    Check out the STM32F103C8.
    Btw, nice work!
  • 1
    @LuxARTS most tutorials are for arduino unos... My brother is a robotic engenheir and is also starting now with Arduino, and he only uses unos. I'm a noob and I already have a few different MCUs. Still I'm checking your tip :p
  • 1
    How do you describe mind blown?
  • 1
    @LuxARTS: AVRs are a nice first microcontroller, because they're not too complex. You can fully grasp them fairly easily, while you'd be pretty overwhelmed at first by STM32s (as a beginner). Programming the AVR directly, without Arduino, would be the logical next step before moving to more complex architectures.
  • 0
    I would suggest the STM32F429IDISCOVERY as the next step. There should be many helpful tutorials online and you can start to learn about programming a graphical user interface. 🙂
  • 0
    @LuxARTS Actually liked this... Was expecting something expensive
  • 0
    @Crowns That's 70€ Up from China...

    For 100€ There is a new board (That I can't find) with 6core, 4GB ram, 32 eMMC, or for 80€ 6core, 2gbRam, 16eMMC ... If I find it again ill make a post.

    Btw Is ready for both Linux and Android.
  • 0
    @LuxARTS

    Ya talking about this right?

    https://aliexpress.com/store/...

    Can you tell the differences compared to a Arduino to a noob?
  • 2
    @7400 Thanks for the suggestions. I'll admit I have a bit of a blind spot when it comes to capacitors (I never know when I should use one). This makes sense though - so you're saying each of the shift registers should have one? (those are the only ICs I'm using on the breadboard).

    I'd rather not glue any of the other parts, but am curious about the screw option - how would I do that or are there some kind of breadboards designed for that purpose?

    @Condor Nope, that's not me, sorry!

    @LuxARTS It's basically what I'm familiar with and had available so it was a good starting point. I don't need it to be faster & am mostly working with 8-bit (or smaller) data. Plenty of Arduino tutorials - it's how I learned about SPI and shift registers. There was even a tutorial on making an Arduino-compatible circuit on a breadboard which will end up being part of this too. I'll probably use something like what you suggested if I have a project that requires more speed etc. though.
  • 3
    @7400 (Re: "AVRs are a nice first microcontroller, because they're not too complex") The Arduino libraries make things really easy, from setting pin modes to supporting other hardware components (e.g. SD card). I've had a good read of various parts of the documentation and understand how I'd use the I/O pins without the Arduino code.

    I've also read up on the different instructions the architecture supports and had a shot at making an emulator for it - in JavaScript, so it could run on a web page (was meant to be to teach low-level stuff but I got as far as making it run the Arduino bootloader code and show register values then stopped working on it).

    There's quite a lot to learn to fully understand it but getting started is just so easy - plug in, write some code, upload it, write some more code, repeat.
  • 3
    @nightowl: Exactly, each shift register should have one. Larger ICs often have more power pins than one VDD and one VSS and should get one capacitor for each pair VDD/VSS (they are often next to each other to make that easy).

    Just use a piece of wood. It's not pretty, but its just a prototype after all, isn't it? I like to use PCB material for construction purposes, too (the standard copper-clad stuff, without pre-drilled holes). Its pretty rigid and can be soldered to arbitrary shapes. You can even make pretty enclosures out of it.

    It's nice to hear about your experiences getting into the depth of your microcontroller! Often people just stay at the stage of looking for pre-made Arduino libraries and using off-the-shelf modules for their hardware, which kind of saddens me.

    Soon you'll be able to trick that controller into doing things at the edge of what's possible! Do you know the demos of lft? He has done pretty awesome stuff with AVRs.
  • 1
    @GyroGearloose There are a lot of differences. From hardware perspective: Faster CPU, more SRAM, more FLASH, more peripherals, different architecture, registers of 32 bits.

    From software perspective: You can program it like an Arduino (google STM32DUINO) but it a lot better if you use the programmer (ST Link v2) and the IDE provided by the manofacturer (Atollic TrueSTUDIO). Maybe it's hard at the begining because you are not familiarized with structs and other things but at the end it's way better than Arduino. A very cool option it's debug the program in real time, which using Arduino IDE you can't. This feature is a life saver when you are stuck because the code is not working like you want.

    Plus, as you saw, this microcontroller it's cheaper. Why not use it?
  • 1
    @Crowns I was planning to buy that board but it's very expensive and the hardware don't compensate it. I'm working in a GUI using two STM32F103C8. One as a "GPU" that refresh the screen and other to process the stuff to be displayed. Cheaper than STM32F4 board and in my opinion better to mantain.
  • 2
    @LuxARTS Mouser and Farnell are selling them for around 25€ most other retailers take 75€ 😅
  • 2
    Hey guys

    check out:

    https://instructables.com/id/...

    Already made it myself and works perfectly.

    You can even set one Arduino nano + this cable + BT for input and project to the screen.
  • 2
    @Crowns Yes, but STM32F103C8 cost $2USD
  • 2
    @GyroGearloose Good to see you get it work. Nice job!
  • 0
    @Crowns Thanks for the Mouser and Farnell Tip :p
  • 2
    @LuxARTS was actually the easiest once I find out one bug that didn't allow the code to run in another tutorial...

    But the cable did it watching the tutorial the first time.

    I'm waiting for the 3rd Easy driver module for CNCs, have a shield but it's a little quirkier so I'll start with easy drivers.
  • 3
    @7400 Been reading a bit about capacitors today, as I was wondering what determines which capacitor to use and I think I "get" it now - originally I thought "surely bigger is better?" but I see that smaller is better for short voltage dips.

    I know the ISA card has a bunch of capacitors on it already. Since the recommendation seems to be to put these as close to the chips as possible, can I assume that the card already has the relevant capacitors and that I don't need to worry about providing them myself to the +5v/+12v?

    And the capacitors should go between the "Vcc" and "Gnd"? (By the sound of things I need to use it as a "bypass" or "decoupling" capacitor?)

    I have some stripboard already but it seems really difficult to cut the copper traces and the board itself.

    I like to learn how things work and try things myself so often I avoid libraries :)

    I've not heard of lft, no. Might check his stuff out.
  • 2
    @nightowl: Yes, it's not only abput the capacitance, but also about parasitic inductance and series resistance. For short peaks these limit the current a capacitor can deliver (and that's exactly why it should be close to the IC, too). 100 nF is a rule of thumb that has been around for ages. It works in most cases [1] so usually you don't bother and just keep a roll of 100 nF caps around.

    You're right about the placement of the capacitors. Common terms are bypass, blocking or decoupling capacitors and they go between supply voltage and ground [2]. If you use an assembly that already has them (like your card surely does), there's no need for them.

    If you can afford one missing “pad”, you can use a drill bit to cut a strip board's traces.
  • 2
    _____
    [1] For very high speeds, ICs can be a bit pickier about the value. Sometimes, even a combination of different values is needed (but that's really rare).
    [2] If you have a symmetrical supply, they sometimes go between positive and negative. Depends on the IC structure.

    (Ran out of characters)
  • 0
    @7400 Hey dude, sorry to ask, I want to convert a psu into a power supply. I've read here that I need something to regulate the voltage, can you explain?

    Also, red wires are 12V or 5V?

    I think we talked before about this but can't remember...
  • 2
    This rant is starting to become som general electronics chat… @GyroGearloose: That was here: https://devrant.com/rants/1614723/...
    I mean, you could just look at the label of your PSU.

    If you want voltages other that 12 V, 5 V, 3.3 V, -5 V or 12 V, you'll need some sort of voltage regulator, yes. Also, if you want a current limit (which you should have). You can build your own, but that pretty much requires a scope. It seems you're just starting at the moment, so you probably don't have one yet?
  • 2
    @GyroGearloose A PSU *is* a power supply unit :P
    For other voltages you could get a regulator (something like LM317 should be good and can be set to limit current too) but those are only useful in low power applications and aren't efficient. I'd recommend you get a lab bench power supply for efficiently powering stuff with greater control than a PC power supply would.

    Also I doubt that this is the right place to do general electronics chit-chat. Feels like threadjacking to me.
  • 0
    @7400 Err... whats a scope?
  • 0
    Roger... You guys are right. And I'm blind as fuck since I was the one taking the picture and the PSU is right at my side.

    Well, I want to use them because I have quite a few laying around, plus the ones I unmounted for the wires (faulty ones).
  • 0
    Anyhow, I only want to work with that voltages, maby I'll lower a little the 12V If I want to power an MCU, other than that I just need to measure the strength so it won't burn my stuff :p but thanks, you ended up answering my question, and please don't mind me, not in my best days lately.
  • 2
    @GyroGearloose: An oscilloscope.

    If you want some sort of overcurrent protection, a neat trick is to use an integrated high-side switch as an electronic fuse (for example an AUIR3315S, but you can find many similar ones). Those are orders of magnitude faster than a fuse and electronically resettable.
  • 0
    @7400 Nice, I've seen a few videos of Oscilloscopes and didn't saw because didn't know what it was, meaning to advanced for me...

    Now I must watch them to understand since I now know I'll need it eventually.

    Thank you very much.
  • 0
    sorry @nightowl for highjacking your post.
  • 2
    @GyroGearloose It's OK :)

    @7400 It seems I don't have any 100nf capacitors in my collection (mostly I have bigger electrolytic ones, and a tiny amount of ceramic ones in the pf range) so I'll look into getting some of those.

    Incidentally, I have noticed that I get popping/clicking corresponding to when I'm doing I/O. Definitely when there's input from my MIDI keyboard (even if I disable all code that programs the synth chip, any input causes a click at the same time). Unsure about other cases (e.g. sending instructions to the card). I'm wondering if the capacitors will help with this, or if I need another somewhere else as well?

    Considering the amplifier chip is meant to run off a separate 12v supply but happily works at 5v so shares the same 5v line as everything else, I suspect that may be related. Might see how it behaves with a separate 12v supply.

    As for stripboard: Yeah I saw that drilling it is an option, but I'd love to solder a connector for the ribbon cable...
  • 3
    @nightowl Crackling noise from I/O may be due to stray induction, or bad connections somewhere.. I've got the same in my PC after I did some maintenance to it. Guess I'll have to take that fucker apart again :/
  • 3
    I love to see this electronic thread. What a wonderful community. 😁
  • 2
    @nightowl: That does sound like it was power supply related, yes. Either it is caused by the current spikes mentioned before or it's lower-frequent and caused by tge voltage drop in your wires when the current momentarily increases during communication.

    You can fix that with a RC lowpass for tge analog supply. An electrolytic cap is sufficient here, because there won't be any short current spikes for the analog stuff. Add a resistor with maybe 10 ohms (not critical either, just shouldn't drop too much voltage during normal operation).
  • 3
    @7400 After some experimentation, it seems to happen when there is any MIDI input (from external device). Usually triggers an interruot, which I do have wired up but it will never trigger again unless I read the input - even if I don't, I get clicks.

    One thing I did spot and fix... I didn't do any mixer control. So I set master to maximum values and that has helped a bit (less background noise as less gain needed).
  • 1
    @nightowl: Did you use optocouplers for your MIDI connections (like they usually have them, on one end)? If not, it might be a common mode transient.
  • 0
    @7400 I'm using the joystick/MIDI port on the soundcard for the MIDI input (MPU-401 UART mode) as I was familiar with how to control that from some software I wrote a few years ago. I thought I might as well use it because it already has an interrupt pin available and I can just draw on what I already know :)

    So, hopefully it's already using optocouplers on the card itself for this. I'll investigate further. Actually, just looking at some pictures I took of a different sound card, I had identified the optocoupler on that one (needed to identify the MIDI input pins). I don't see a similar component on this sound card.

    I've considered adding my own 5-pin DIN connector to the bit of the circuit I've been building. Could be an interesting sub-project to help complete this one.
  • 0
    @nightowl: Unlike ethernet, MIDI is only galvanically isolated on one end, which should be the receiving end. Strictly speaking, this isn't necessary, but it avoids a lot of problems.

    It isn't uncommon to find a large lump of ferrite in a drawer of an engineer's desk (like a big E core set) as a debugging tool. If you suspect a problem is caused by common mode interference, you start putting that core around your cables (closing the magnetic circuit and thus inserting something like a small common mode choke). If the signals change at some point, you have your culprit. It works best for high frequencies, though, so this might not be able to show your problem. But if you do have a ferrite core to put around your wires, it's worth a try.
  • 0
    Ordered some new components to play with, including some 5-pin DIN (MIDI) sockets, some opto-isolators and of course some 100nF capacitors as suggested (just a few for now, I'm still learning etc.)

    Since I'm using SPI for controlling the shift registers I figured I'd try and complete that part by adding a slave-select pin. I spent a while thinking about this and then realised that I can just wire up the ~OE (output enable, active low) pins as the slave select.

    I don't use any other SPI slaves at present but I did consider adding an SD card slot for storing synth patches/presets, so slave select seemed a useful thing to implement.

    Anyway I had loads of problems with it, but ONLY when I had ~OE connected to an Arduino pin. Attached to GND, it was fine. Even setting the pin LOW at the start and leaving it like that didn't help.

    Stuck one of these 100nF capacitors between ~OE and GND and it works. I guess maybe there is some noise during SPI transfer?
  • 0
    You can't really use /OE as a slave select, because these fulfill different purposes.

    You can think of the slave select sort of as a gating for the SPI slave. If it is high, the slave will just ignore SPI transmissions.

    Output enable on the other hand controls the outputs based on the data that was already clocked in. The shift register is completely unaffected by this pin, i. e. you could set /OE high, clock data in and apply a PWM to /OE to dim some LEDs connected to the outputs.

    If a SPI slave doesn't have a slave select, there's no replacement, really (except for an external latch before MOSI, MISO, SCK).

    The behaviour you're describing sounds a bit strange, though. /OE shouldn't affect the internal shift register at all.
  • 0
    @7400 I guess I don't *really* need it as the sound card won't care what's on the address or data lines until I pull IOR / IOW low to indicate that I want to transfer data from/to it.

    Just figured at least turning output off means I'm not spamming the pins unnecessarily but thinking about it, that'd happen in a real PC anyway so it's not worth worrying about.

    One of the components (MIDI input) seemed sensitive to timings so I reckon there was maybe some fluctuation on the outputs during transfer, causing the card to not "see" that I'd actually read some data (and then not providing me with any more).
  • 0
    hey man, I'd reeeeeeaaaaaallllly Like to talk to you about this project, I am currently trying to setup the same thing, and am really stuck on the pnp crap.

    looks like you are using a ymf71x which is a chip I want to migrate to from the ymf262 to also use the audio.The current synth I am working on is using 4x OPL3 chips that are strapped to analogue voltage controlled filters and vcas to make a hybrid FM/Subtractive style synth.

    holler at me from my website contact form?

    www.islainstruments.com
Add Comment