突然發現好久沒發文了,作品生產率有點低,所以趕快把這個做完拿來貼
這次把耳機接頭的放回PCB板子上,佔了不少面積...
另外就是修正VR的線路沒接到的問題,還有就是這次VR的孔位特別預留了更大的位置,然後其他的部分不變,架構上一樣是一個OPA Buffer給PGA2311再用Attiny控制PGA2311這樣
至於為啥正負電壓產生器不放上去....
一來是沒啥地方放,二是就算把PCB加大面積,這種Charge pump的東西也是有一定的噪音在,要如何和OPA線路隔離也是種考驗,所以除非我找到一個迷你的Charge pump IC,而且夠力,還有好的小電容再說吧
#define PGA_ZCEN_PIN 3
#define PGA_CS_PIN 1
#define PGA_SDATA_PIN 0
#define PGA_SCK_PIN 2
#define VR A2
int val;
int volume_left, old_l;
int volume_right, old_r;
void pga2311_init(void)
{
pinMode(PGA_CS_PIN, OUTPUT); // pga-chipselect pin
pinMode(PGA_SDATA_PIN, OUTPUT); // pga-data-out (our data out to it) pin
pinMode(PGA_SCK_PIN, OUTPUT); // pga-clock pin
pinMode(PGA_ZCEN_PIN, OUTPUT);
}
void pga2311_enable_zero_crossing_detection()
{
digitalWrite(PGA_ZCEN_PIN, HIGH);
}
void pga2311_disable_zero_crossing_detection()
{
digitalWrite(PGA_ZCEN_PIN, LOW);
}
void SPI_write(uint8_t out_spi_byte )
{
uint8_t i;
// loop thru each of the 8-bits in the byte
for (i=0; i < 8; i++) {
// strobe clock
digitalWrite(PGA_SCK_PIN, LOW);
// send the bit (we look at the high order bit and 'print' that to the remote device)
if (0x80 & out_spi_byte) { // MSB is set
digitalWrite(PGA_SDATA_PIN, HIGH);
}
else {
digitalWrite(PGA_SDATA_PIN, LOW);
}
// unstrobe the clock via local SPI
digitalWrite(PGA_SCK_PIN, HIGH);
// get the next bit
out_spi_byte <<= 1; // left-shift the byte by 1 bit
}
}
void pga2311_mute()
{
pga2311_set_volume(0, 0);
}
void pga2311_set_volume( uint8_t left, uint8_t right )
{
// Gain (dB) = 31.5 − [0.5 * (255 − N)]
digitalWrite(PGA_CS_PIN, LOW); // assert CS
SPI_write(left); // left value (0..255)
SPI_write(right); // right value (0..255)
digitalWrite(PGA_CS_PIN, HIGH); // deassert CS
}
void setup() {
pga2311_init();
pga2311_enable_zero_crossing_detection();
}
void loop()
{
int Read = analogRead(2);
int val = map(Read, 0, 1023, 0, 255);
pga2311_set_volume(val,val);
delay(10);
}