Hey guys, back again i'm afraid!
I've purchased a couple of PT8211's off ebay and they have recently arrived, they are a cheap as hell SPI 16bit dac.
While it does work with SPI, i've written a quick sketch following the protocol for left and right channel writing. I completely understand how crap this piece of code is and it is extremely slow, its just so I can get used to the workings of the dac.
const char Dat = 4, Ws = 5, Clk = 6, TL = 7;
int A, C;
boolean B = 0;
void setup(){
pinMode(Ws, OUTPUT);
pinMode(Clk, OUTPUT);
pinMode(Dat, OUTPUT);
pinMode(TL, OUTPUT);
}
void loop(){
A+=1000;
C-=2000;
if(A>65535){
A = 0;
digitalWrite(TL, B);
B^=1;
}
if(C<1){
C = 65535;
}
SD(A, C);
}
void SD(unsigned short datal, unsigned short datar){
digitalWrite(Ws, LOW);
digitalWrite(Clk, HIGH);
digitalWrite(Clk, LOW);
for(int w = 15; w>-1; w--){
digitalWrite(Dat, (datar>>w)&1);
digitalWrite(Clk, LOW);
digitalWrite(Clk, HIGH);
}
digitalWrite(Ws, HIGH);
digitalWrite(Clk, HIGH);
digitalWrite(Clk, LOW);
for(int w = 15; w>-1; w--){
digitalWrite(Dat, (datal>>w)&1);
digitalWrite(Clk, LOW);
digitalWrite(Clk, HIGH);
}
}
Now, for once, I plugged it in and it worked first time - an utter rarity. The problem lies in how the dac is writing the output. I've included in the code, a pin toggle everytime A resets to 0 from 65536. What I would expect is that this pin would toggle on the downward slope of a sawtooth wave (i'll include a pic). What it does though is that the pin toggles directly in the centre of waveform. Could anyone give me any heads up to why this is?
In my project, it will only be mono so I can use the SPI nss to set the channel.
Picture:
http://i747.photobucket.com/albums/xx118/hazmatazz/P1010476.jpg
Cheers!