Troubleshooting SAA1099 on Mega2560

Dear All,

I have made a post about controlling a SAA1099 sound chip with an Arduino Mega under a different topic last week and unfortunately didn't get any response, but with searching the forum and reading different articles, I managed to get it running. Then the real problems started and I'm at a loss of how to troubleshoot or find errors in the design...

Here's the chain of events. As I am a beginner, any pointer would be appreciated.

  1. Built the circuit on a breadboard.
  2. Uploaded the sketch.
  3. Didn't work, so I did research about the pins I used and changed from the port register method (using PORTD) to a function which just sets each pin to HIGH/LOW.
  4. It was working fine for a day and I played around with setting registers on the IC to modify the sound.
  5. Next day, no more sound output, but no change to circuit nor sketch.
  6. Also suddenly problems uploading any sketch to Arduino (avrdude timeout error).
  7. Suspected problem with pin 0 and 1, so changed wiring and sketch to use pin 30 to 37 instead.
  8. Uploading works again.
  9. IC still doesn't output any sound.
  10. Wired LEDs with 220 Ohm resistor to each output pin to see the communication. Now I hear a crackling noise in my headphones, every time a LED lights up.

The schematic and sketch are attached for reference.

Is it possible I blew something on my Arduino or my IC with the sketch/circuit?

const int PIN_WR = 44;
const int PIN_AO = 40;
const int PIN_CLOCK = 11; //Clock pin 11 on Arduino Mega 2560
const int PIN_BUS = 30; //start pin + 7

//                      B , C , C#, D , D#, E , F , F#, G , G#, A , A#
const byte freq[12] = {  2, 17, 34, 51, 69, 89,109,131,154,179,205,232};

// /WR active LOW
// /CS active LOW
// AO - LOW data to control register,  HIGH address buffer

void chipSend(byte address, byte data) {
	digitalWrite(PIN_AO, HIGH);

	for (byte pin = 0; pin < 8; pin++) {
			digitalWrite(PIN_BUS + pin, bitRead(address, pin));
		}
	digitalWrite(PIN_WR, LOW);
	delayMicroseconds(5);
	digitalWrite(PIN_WR, HIGH);

	digitalWrite(PIN_AO, LOW);

	for (byte pin = 0; pin < 8; pin++) {
				digitalWrite(PIN_BUS + pin, bitRead(data, pin));
			}
	digitalWrite(PIN_WR, LOW);
	delayMicroseconds(5);
	digitalWrite(PIN_WR, HIGH);
	for (byte pin = PIN_BUS; pin < PIN_BUS + 8; pin++) {
		digitalWrite(pin, LOW);
	}
}

// the setup function runs once when you press reset or power the board
void setup() {
	for (int i = 0; i < 14; i++) digitalWrite(i, LOW);

	//setup 8Mhz time on OCA1 (Mega on pin 11)
	pinMode(PIN_CLOCK, OUTPUT);
	//setup Timer 1
	TCCR1A = bit(COM1A0); //toggle OC1A on compare match
	TCCR1B = bit(WGM12) | bit(CS10); //CTC no pre-scaling
	OCR1A = 0; //output every cycle

	//SAA1099 setup
	pinMode(PIN_AO, OUTPUT);
	pinMode(PIN_WR, OUTPUT);

	//Setup output bus
	for (byte pin = 0; pin < 8; pin++) {
		pinMode(PIN_BUS + pin, OUTPUT);
		digitalWrite(PIN_BUS + pin, LOW);
	}
	//Testing output pins
	for (byte pin = 0; pin < 8; pin++) {
		digitalWrite(PIN_BUS + pin, HIGH);
		delay(500);
		digitalWrite(PIN_BUS + pin, LOW);
	}
	delay(1000);

	digitalWrite(PIN_WR, HIGH); //write disable

	//Reset/Enable all the sound channels
	chipSend(0x1C, B00000010);
	chipSend(0x1C, B00000000);
	chipSend(0x1C, B00000001);

	//Disable the noise channels
	chipSend(0x15, B00000000);

	//Disable envelopes on Channels 2 and 5
	chipSend(0x18, B00000000);
	chipSend(0x19, B00000000);

	delay(1000);
}

void loop() {
	chipSend(0x1C, 0b00000001); //sound enable all channels

	for (byte ch = 0; ch < 6; ch++){
		chipSend(ch+0x00, 0b11111111); 	//CH0-5 --> amplitude max D7-D4 right, D3- D0 left
	}

	//Setting octaves for CH0 to CH5
	/*
	 * 000 -  31 Hz to  61 Hz (lowest)
	 * 001 -  61 Hz to 122 Hz
	 * 010 - 122 Hz to 244 Hz
	 * 011 - 245 Hz to 488 Hz
	 * 100 - 489 Hz to 977 Hz
	 * 101 - 978 Hz to 1.95 kHz
	 * 110 - 1.96 kHz to 3.91 kHz
	 * 111 - 3.91 kHz to 7.81 kHz (highest)
	 */
	//chipSend(0x10, B00110001); //X O1 O1 O1 X O0 O0 O0
	//chipSend(0x11, B00010101); //X O3 O3 O3 X O2 O2 O2
	//chipSend(0x12, B01100100); //X O5 O5 O5 X O4 O4 O4


	chipSend(0x15, 0b00000000); //noise enable B(0 0 CH5 CH4 CH3 CH2 CH1 CH0)
	//chipSend(0x16, B00000010);

	//chipSend(0x16, B00NN00NN); //2 bits for noise generator control

	chipSend(0x18, 0b00000000); //envelope generator 0 disabled
	chipSend(0x19, 0b00000000); //envelope generator 1 disabled

	for (byte oct = 0b00000011; oct < 0b00000101; oct++) {
		chipSend(0x10, oct);
		for (byte f = 0; f < 12; f++){
			chipSend(0x08, freq[f]);
			chipSend(0x14, 0b00000001);
			delay(2000);
			//chipSend(0x14, 0b00000000);
			delay(10);
		}
	}
	delay(1000);
}

Troubleshooting Guidance Mega and SAA1099

This is rather general advice, but it usually works for me when trying to isolate problems.

Go thought your code, and incrementally implement it in a second sketch. Try one function, and when that works, add another one, and so on. I usually converge on the answer to my proble,s when I reduce the complexity and try small parts at a time.

You may kill the Arduino outputs with your circuit. Insert a resistor of at least 120 Ohm between the Arduino pins and your speaker circuit.

Hi,
The LEDS is a very good idea when intermittent things start occurring.

Have you built this on protoboard with jumpers, if so they can be somewhat temperamental/unreliable at times.

I just went and had a look at your other post.
You need to be a bit more specific in the subject line.

As you are the originator of this thread, you can edit the subject.

Instead of;
Troubleshooting Guidance

Edit it this thread to
Troubleshooting Guidance Mega and SAA1099

That way you may attract some forum members who are SAA1099 knowledgeable.

Thanks.. Tom.. :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.