Good Morning Gents, I'm stuck for 2 months on this project and I'm about to drop it...
So, I read the manual of the PSG and i did everything right but it does not work.
The setup is the following:
1 x 2Mhz resonator (working fine);
1 x SN74HC595N
1 x arduino mega 2560
1 x Ym2149
The shift register is connected to the arduino and to de PSG.
Here is the pinout: (available in the code as well)
PSG
D0->D7 -> Shift Register QA->QH
BCDIR/BC1 -> Arduino Mega PORTA (pins 22/23)
BC2 -> +5V
Audio out A, B, and C are each one connected to a 1k ohm resistor and them connected to the output which is connected to ground with a 100 ohm resistor
I used another code (not mine) and the PSG works fine but I can't understand it.
So the chip is not the problem nor the shift register.
Hope some of you experienced Gents will be able to help me!
Here is my code Btw:
//COMMANDS
// Digital pins output to YM2149F
int D0 = 37;
int D1 = 36;
int D2 = 35;
int D3 = 34;
int D4 = 33;
int D5 = 32;
int D6 = 31;
int D7 = 30;
//Address/reg select
int BDIR = 23;
int BC1 = 22;
//shift Registor
int data = 8;
int latch = 9;
int CLK= 10;
//Variables
int i = 0;
int l = 0;
int t = 0;
int Freq = 0;
int x = 0;
int test_n = 0;
//void data
int FB;
int LB;
#define Master_Clock 2000000;
//Automation Arrays
;
int testex [] = {1,2,4,8,16,32,64,128}; // not in use
int D_Output [] = {D0,D1,D2,D3,D4,D5,D6,D7,BDIR,BC1, data , CLK , latch};
int D_Output_n = 0;
void setup() { // Pin Config
while ( D_Output_n < 13) {
pinMode ( D_Output [D_Output_n] , OUTPUT);
D_Output_n++;
}
Serial.begin (9600);
Serial.println ("Codename *hidden* started");
delay (100);
D_Output_n = 0;
// DDRC = B11111111;
/*
// GOLDEN RULE
Freq = Master_Clock / TP * 16;
*/
}
void Address_mode(){
PORTA = B00000011;
delay(x);
}
void Inactive_mode(){
PORTA = B00000000;
delay(x);
}
void Write_mode() {
Latch();
PORTA = B00000010;
}
void mixer_EA(){ //corrected
Address_mode();
shiftOut (data ,CLK ,LSBFIRST, 6); //reg 7
Latch();
Inactive_mode();
shiftOut (data ,CLK ,LSBFIRST, B11111000); //Only melodical voices / io ports and noise off | IOB | IOA | Noise A | B | C | Sound A | B | C |
Write_mode();
Address_mode();
shiftOut (data ,CLK ,LSBFIRST, 7); //reg 8 Channel A Volume
Latch();
Inactive_mode();
shiftOut (data ,CLK ,LSBFIRST, B00001111);
Write_mode();
Inactive_mode();
}
void Clean(){
// shiftOut(data, CLK, LSBFIRST , 0); not in use
}
void Latch(){ //shift register latch
digitalWrite (latch , LOW);
digitalWrite (latch , HIGH);
digitalWrite (latch , LOW);
}
/* xxxxxxx
* ADDRESS MODE: BDIR=HIGH / BC1 = HIGH -> PORTA = B00000011
* WRITE MODE : BDIR= HIGH / BC1 = LOW -> PORTA = B00000010->BC1
* |
* BDIR
*/
void Wave_s (){ //corrected | wave type
Address_mode();
shiftOut (data , CLK , LSBFIRST , 13); //Reg 13
Latch();
Inactive_mode();
shiftOut (data, CLK , LSBFIRST , B00001011); // square wave
Write_mode();
Inactive_mode();
}
void Channel_A ( int FB , int LB) { //corrected | not in use
Address_mode();
shiftOut(data, CLK, LSBFIRST , 6);
Latch();
Inactive_mode();
shiftOut(data, CLK, LSBFIRST , FB);
Write_mode();
Inactive_mode();
Address_mode();
shiftOut (data, CLK, LSBFIRST , 7);
Latch();
shiftOut (data, CLK, LSBFIRST , LB);
Write_mode();
Inactive_mode();
}
void loop() {
//PORTX = B76543210 ->
// |||||||||
Inactive_mode(); //Resets Bus Control
Address_mode();
shiftOut(data, CLK, LSBFIRST , 6);//Address 7
Latch();
Inactive_mode();
shiftOut(data, CLK, LSBFIRST , B11000000); //reg 7 | config channels
Write_mode();
Inactive_mode();
Address_mode();
shiftOut (data, CLK, LSBFIRST , 7);//Address 8
Latch();
Inactive_mode();
shiftOut (data, CLK, LSBFIRST , B00011111); //reg 8 | config volume channel A
Write_mode();
Inactive_mode();
Wave_s(); //sets up Square Wave
Address_mode();
shiftOut(data, CLK, LSBFIRST , 0);//Address 1
Latch();
Inactive_mode();
shiftOut(data, CLK, LSBFIRST , B00000111); //sets fine tone channel A
Write_mode();
Inactive_mode();
Address_mode();
shiftOut(data, CLK, LSBFIRST , 1); // Address 2
Latch();
Inactive_mode();
shiftOut(data, CLK, LSBFIRST , B00000001); //sets rought tone channel A
Write_mode();
Inactive_mode();
delay (100);
}
I don't know if the program is running way to fast and the PSG isn't catching up or the order of the registers are wrong ...
The program only asks the PSG to generate one tone for testing but it does nothing.
Edit: the Shift register was added because for some reason all ports of my arduino mega had a problem where 3 or 4 outputs would not work (I'm thinking in replacing this board...).