Hello Everyone,
Note: I'm pretty new to circuits and the Arduino; please forgive any ignorance on my part.
After playing with my UNO for a bit, I've decided to give a larger project a shot. I chose the SN76489AN PSG as a chip I'd like to interface with. This particular chip was used in the Sega Master System (among others), and has been suggested to be a somewhat easy chip to work with.
I've tried to keep the parts list relatively simple:
SN76489AN
74HC595N
Piezo Buzzer
Arduino UNO R3
Oodles of jumper wires
I am fairly sure my wiring is correct; you can see exactly what I have done with the diagram below [IC = SN76489] (clicking on the image will give you full size):
I have used the TimerOne library to give the PSG a 1MHz clock (according to the data sheet, the PSG is able to take up to a 4MHz clock), and I've used ShiftOut to transfer bytes from the UNO to the PSG. Using information from SN76489 - Development - SMS Power!, I have picked a few bytes to push to the PSG which should generate some noise over the piezo buzzer (see the latch and data bytes in the code below).
Material online says I should wait 32 cycles between the CE and WE and data writing; is delay(1) enough (I assume yes)? Is there a better way to do this?
I seem to be unable to get an descernable sound from the speaker; though from what I gather, I should be getting white noise of some sort. Can someone point out the noob mistake I've made? Is it the code, or the wiring job?
I've noticed that someone else has also done work with this PSG in 2008 - http://arduino.cc/forum/index.php/topic,7268.0.html. However they also use the YM2612 and stream data from an SD card (which is a level of complexity I am not ready for yet IMO). I wasn't able to glean any insight from this post however
#include "TimerOne.h"
// Sound Chip to ShiftRegister
//
// SN76489AN D0-D7
// 74HC595N Q0-Q7
int dataPin = 2;
int latchPin = 3;
int clockPin = 4;
int CLOCK = 10; //Clock Pin
int PWMPin = 9; //PWM Pin
int CE = 11; //Chip Enable
int WE = 12; //Write Enable
byte latchByte = B11011111; //(white noise, medium shift rate)
byte dataByte = B00000000; //(white noise, high shift rate)
//byte latchByte = B10001110; //~110Hz?
//byte dataByte = B00001111;
void setup()
{
//Setup Shift Register to output bytes
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
//Set Chip Enable to Off
pinMode(CE, OUTPUT);
digitalWrite(CE, HIGH);
//Set Write Enable to Off
pinMode(WE, OUTPUT);
digitalWrite(WE, HIGH);
//Set Pin 10 to be 1mhz clock for the SN76489AN
pinMode(CLOCK, OUTPUT);
Timer1.initialize(1);
Timer1.pwm(PWMPin, 512); //50% duty <-Is this even needed?
Timer1.attachInterrupt(callback);
}
void callback()
{
digitalWrite(CLOCK, digitalRead(CLOCK) ^ 1);
}
void loop()
{
TransmitToPSG(latchByte);
TransmitToPSG(dataByte);
}
void TransmitToPSG(byte value)
{
digitalWrite(CE, LOW);
delay(1);
digitalWrite(WE, LOW);
delay(1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, value);
digitalWrite(latchPin, HIGH);
digitalWrite(CE, HIGH);
delay(1);
digitalWrite(WE, HIGH);
delay(1);
}