Page 3 of 4

Re: Hardware

PostPosted: Fri Oct 30, 2015 6:56 am
by sto
Maybe I did something wrong and broke the chips, but could you please help? I wired it all up, with the reset and master clock signals running through the quad buffer chip to amplify them. The quad buffer (HCT125) is powered from the 5V supply from the teensy, and the clock and reset signals are connected to the inputs. The inverter pins are not wired at all, and the master clock signal comes from one of the PWM pins from which I try to produce a 12MHz signal. The OPL3's supply pin is also connected to the 5V source, and all other pins are connected either to the teensy or the quad buffer. They're all connected directly, i.e. no capacitors or resistors are present.

//edit: I should say that the problem is that I don't get the SY signal to work.

Here's the code I'm using to communicate with the chip:
Code: Select all
#include <TimerThree.h>

constexpr int OPL_MASTERCLOCK = 3;
constexpr int OPL_IC = 1;
constexpr int OPL_D2 = 2;
constexpr int OPL_D3 = 0;
constexpr int OPL_D4 = 4;
constexpr int OPL_D5 = 5;
constexpr int OPL_D6 = 6;
constexpr int OPL_D7 = 7;
constexpr int OPL_SMP_BD = 8;
constexpr int OPL_SMP_AC = 9;
constexpr int OPL_DO_AB = 10;
constexpr int OPL_DO_CD = 11;
constexpr int OPL_SY = 12;

constexpr int OPL_D1 = 16;
constexpr int OPL_D0 = 17;
constexpr int OPL_TEST = 18;
constexpr int OPL_CS = 19;
constexpr int OPL_RD = 20;
constexpr int OPL_WR = 21;
constexpr int OPL_A1 = 22;
constexpr int OPL_A0 = 23;

constexpr unsigned int Masterclock = 12e6; // 14.31818e6;
constexpr unsigned int SmpRate = Masterclock/288;
constexpr unsigned int SyRate = SmpRate*36;
volatile int toggleCounter = 0;
int toggleTs = 0;

void masterToggle()
  static bool state = false;
  state = !state;
  if(state) {
    digitalWrite(OPL_MASTERCLOCK, HIGH);
    digitalWrite(13, HIGH);
  else {
    digitalWrite(OPL_MASTERCLOCK, LOW);
    digitalWrite(13, LOW);

void setup() {
  // put your setup code here, to run once:
  pinMode(OPL_IC, OUTPUT);
  pinMode(OPL_A0, OUTPUT);
  pinMode(OPL_A1, OUTPUT);
  pinMode(OPL_WR, OUTPUT);
  pinMode(OPL_RD, OUTPUT);
  pinMode(OPL_CS, OUTPUT);
  pinMode(OPL_TEST, INPUT);
  pinMode(OPL_D0, INPUT);
  pinMode(OPL_D1, INPUT);
  pinMode(OPL_D2, INPUT);
  pinMode(OPL_D3, INPUT);
  pinMode(OPL_D4, INPUT);
  pinMode(OPL_D5, INPUT);
  pinMode(OPL_D6, INPUT);
  pinMode(OPL_D7, INPUT);
  pinMode(OPL_SMP_BD, INPUT);
  pinMode(OPL_SMP_AC, INPUT);
  pinMode(OPL_DO_AB, INPUT);
  pinMode(OPL_DO_CD, INPUT);
  pinMode(OPL_SY, INPUT);
  pinMode(13, OUTPUT);

  //analogWriteFrequency(OPL_MASTERCLOCK, Masterclock);
  tone(OPL_MASTERCLOCK, Masterclock);

  digitalWrite(OPL_CS, LOW);
  digitalWrite(OPL_IC, HIGH);
  digitalWrite(OPL_IC, LOW);

  //Timer3.initialize(1); // 1.0e6/(Masterclock*2));

int chAB[2] = {0,0};
int chCD[2] = {0,0};
int dataCtr = -1;
bool chBD = false; // second set of data?

void handleSy()
  const bool acState = digitalRead(OPL_SMP_AC);
  const bool bdState = digitalRead(OPL_SMP_BD);

  if(dataCtr < 0) {
    if( dataCtr == -1 ) {
      if(acState) {
        Serial.print("Sync start: ");
        Serial.print(" ");
        Serial.print(" ");
        dataCtr = -2; // wait for fall
    else if(dataCtr == -2) {
      if(!acState) {
        Serial.print("Sync stop: ");
        Serial.print(" ");
        Serial.print(" ");
        dataCtr = 16; // wait 2 samples, then start

  int index = dataCtr%18;
  int ofs = dataCtr/18;

    chAB[ofs] |= (1 << index);
    chCD[ofs] |= (1 << index);

  //if(dataCtr == 36)
  //  Serial.println(chAB[0]);
  dataCtr %= 36;

void loop() {
  static bool s = false;
  float delta = millis()-toggleTs;
  if(delta>1000) {
    toggleTs = millis();
    Serial.print("Toggle: ");
    toggleCounter = 0;
    //digitalWrite(13, s ? HIGH : LOW);
    s = !s;

    Serial.print(" ");
    Serial.print(" ");
    Serial.print(" ");
    Serial.print(" ");
    Serial.print(" ");
    Serial.print(" ");
  auto tm = pulseIn(OPL_SY, HIGH, 1e3);
  if(tm != 0) {
    Serial.print(" ");

Thanks in advance.

Re: Hardware

PostPosted: Fri Oct 30, 2015 9:12 pm
by opl3
Hi, I don't know how this Teensy environment works, but my guess is the serial port writes are not buffered, so at 9600 bps, each byte sent to serial port takes about 1.04 milliseconds to transfer, and the SY polling must be done at twice the SY frequency, ~3.6MHz. There's no time for sending serial data, or do nothing much else than just receive the serial bits.

In practice, the SY is not 50% duty square wave, it is 25% duty square wave, so that's why it needs to be polled at ~7.2 MHz.

To capture the data stream, I'd take a look at which hardware module could do it. SPI module is one, but not so convenient solution.

Re: Hardware

PostPosted: Sat Oct 31, 2015 12:01 am
by sto
I'm aware that the current solution is "suboptimal" (to say the least), but the SY doesn't seem to be triggered at all. In fact, I don't seem to get the OPL to do anything at all, as the outputs from the chip are never changing. I'm still trying to get it to do something, and only then I will start fiddling around with reading/transmitting the data.

Re: Hardware

PostPosted: Sun Nov 08, 2015 4:21 pm
by synthop
Do you have a scope? First thing I do when I bring up a new board or whatever is check the clocks, resets, power, ground. I know it sounds overly basic but often times one of those is the problem.

Re: Hardware

PostPosted: Sun Nov 08, 2015 10:22 pm
by sto
Well, unfortunately not. The only thing I have at hand is a voltmeter, which isn't of any use anymore, because the soldering points are properly connected. It was my first though to also buy an oscillosope, but everything I found was too expensive for the budget I've set. I'll try to play around with the PWM pins though, as I think I'm not programming them correctly.

Re: Hardware

PostPosted: Fri Jan 15, 2016 5:28 pm
by sto
Now that I own a oscilloscope, it turns out that I'm only generating a 7kHz master clock...

Re: Hardware

PostPosted: Fri Jan 15, 2016 7:53 pm
by synthop
Visibility is great isn't is? Glad you crossed that off the list. Keep us updated.

Re: Hardware

PostPosted: Fri Jan 15, 2016 11:05 pm
by sto
Hm, OK, I managed to get the PWM pin 3 working at 12 MHz and it's producing a nice sine wave. I tried to hook that up to the 74HCT125, but then I realized I need to change the "working point" of the input, because all I get is either HI or LO, independent of the output enable pin (which I hooked up to the PWM pin). The buffer's input should then be the 5V supply from the teensy, the output hooked up the the OPL's master clock, but what should the buffer's supply voltage be, 3.3V, 5V or GND?

I'm a bit overwhelmed by the complexity of hooking it up, so maybe I'll get it working in 2-3 years, once I managed to learn electrical engineering ;)

// EDIT: Turns out, my soldering skills are "optimizable"... time to solder another 74HCT125 onto an adaptor...

Re: Hardware

PostPosted: Mon Jan 18, 2016 3:07 am
by sto
Turns out that the jump wire board I bought seems to be not that good, too. But at least the OPL produces output, now I need to figure out a way to process the data in time...

Re: Hardware

PostPosted: Mon Jan 18, 2016 8:24 pm
by opl3
I bet the yellow is your 12MHz masterclock (M) from Teensy, and blue is 1.5 MHz bitclock (SY) from YMF262 because it has 25% duty cycle.