I2S example code

Post your cool example code here.
victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Fri Apr 21, 2017 5:47 am

ChrisMicro wrote:The MAX98357a seems to need a quite accurate timing.
The timing of the code example above ( timer interrupt triggers SPI ) seems to be not sufficient for this chip.
The bit sequence needs to start 1 bit delayed ( relating to the I2S specs ) which seems to me that it can not be done with DMA.
Agreed, I think it would only works for left justified mode, like the PT8211.

I don't know all the SPI modes though, so I dont know if there is any way to configure the spi peripheral to send a clk cycle before the first bit.

EDIT: Looks like the MAX98357b supports left justified mode.

ChrisMicro
Posts: 318
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: I2S example code

Post by ChrisMicro » Fri Apr 21, 2017 8:00 pm

EDIT: Looks like the MAX98357b supports left justified mode.
Well, yes ... but the breakout board from Adafruit is unfortunately the 'A' version ... and I have it ...
https://developer.mbed.org/users/Plugo/ ... -adafruit/

Ok, let's delay the problem for some years ..

victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Fri Apr 21, 2017 8:24 pm

ChrisMicro wrote:
EDIT: Looks like the MAX98357b supports left justified mode.
Well, yes ... but the breakout board from Adafruit is unfortunately the 'A' version ... and I have it ...
https://developer.mbed.org/users/Plugo/ ... -adafruit/

Ok, let's delay the problem for some years ..
You could loose 1 bit of resolution if you just shift the words 1 bit.


Now you output that in the SPI. The first 0 during the first clock cycle is discarded, next the MAX will take all other 15 bits and take them as the MSB of that word, but is still waiting for 1 BIT right?
Timer overflows, and the SPI sends the next 16bits, with the MSB set as 0 again. The MAX will take that first bit to complete the word for the other channel, and then take the next 15 for the current one.
That goes on and on until you stop playing.
So you actually lose the LSB, because it will be filled with the 1st bit sent out for the next word.
I know my explanation is completely clear, but look at figure 6 in the max98357a datasheet, and then imagine D15 was actually sent be the SPI as the second bit in the transfer. So if you shift every word by one, they will all fit in.

MSB ------------- LSB
1111111111111111
Shift it right:
0111111111111111 (LSB bit is lost)
If you put keep sending your data shifted 1 bit, you would get something like this right?
0111111111111111 0111111111111111 0111111111111111 0111111111111111....
Now, because the DAC actually expects the first bit in the 2nd clock, and the last bit in the first clock after the LRClk togles, the DAC will take them as this:
0 - 111111111111111 0 -1111111111111110 - 1111111111111110 - 1111111111111110....
0(lost) - word 1 - word2 - word 3 - word 4

So effectively you just made a 0 in the LSB. You get 15 bits of resolution out of 16

EDIT:
Or you can just order an RCT board from ebay or aliexpress ;)

ChrisMicro
Posts: 318
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: I2S example code

Post by ChrisMicro » Sat Apr 22, 2017 7:33 am

Or you can just order an RCT board from ebay or aliexpress ;)
Yes, sometimes I also tend to solve software problems by hardware ;-)

Here is a nice one, but it is made for self-soldering:
https://www.pjrc.com/store/pt8211_kit.html

victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Sat Apr 22, 2017 3:16 pm

ChrisMicro wrote:
Or you can just order an RCT board from ebay or aliexpress ;)
Yes, sometimes I also tend to solve software problems by hardware ;-)

Here is a nice one, but it is made for self-soldering:
https://www.pjrc.com/store/pt8211_kit.html
That's nice, if I had found it before I bought a bunch of pt8211 and DIP to SOP little pcbs I would have bought that instead.
Soldering the chip wasn't that much trouble.

The best board I think would be one like that + a small amplifier all in a single PCB.

Phoebus1966
Posts: 4
Joined: Fri Feb 16, 2018 11:24 am

Re: I2S example code

Post by Phoebus1966 » Fri Feb 16, 2018 7:00 pm

A have a question in regard to the TP8211 DAC.

Is the TP8211 a same kind of DAC as the PCM61P?

I have a hunch it is but I couldn't confirm that beyond the fact both have a word clock, a bit clock and a single serial data input plus that both are MSB first.

The PCM61P and similar of its kind have LE as word clock, then CLK and DATA.

victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Fri Feb 16, 2018 7:07 pm

That one has 18bit of resolution vs the 16 bits in the pt8211, so they are not the same or work the same.

Phoebus1966
Posts: 4
Joined: Fri Feb 16, 2018 11:24 am

Re: I2S example code

Post by Phoebus1966 » Fri Feb 16, 2018 10:52 pm

Concerning the 'example code', do I just open Arduino and start typing the code, hook up my ARM board and click on compile/upload? Of course not.

With the Arduino IDE having board setting we'd still have to know which board to select.

So which board must we select among the plethora of choices?

Are there other directives necessary to make the compilation and upload go successful?

Thanks for helping out.

Phoebus1966
Posts: 4
Joined: Fri Feb 16, 2018 11:24 am

Re: I2S example code

Post by Phoebus1966 » Fri Feb 16, 2018 11:07 pm

victor_pv wrote:
Fri Feb 16, 2018 7:07 pm
That one has 18bit of resolution vs the 16 bits in the pt8211, so they are not the same or work the same.
Thanks for your reply.
The resolution is indeed different. The EMAX II sampler that I own is 16-bit. Its schematics show a PCM53's as output DAC's for the different outputs. However the seats are occupied by AD1860 DAC's which are 18-bit. The fed bits are alligned as such that the 18-bit DAC behaves the same as the 16-bit DAC when it comes to producing output.

I should have asked if the PT8211 is as such similar to the PCM53 when it comes to the 3 serial data communication pins LE, CLK and DATA and the resulting output.

victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Sat Feb 17, 2018 1:18 am

Now I am getting confused, the PCM53 that I can find in google is a 16bit DAC, not like the PCM61 which is a 18bit DAC, but the PCM53 is a parallel DAC, so I am guessing that was a typo.

As far as the PCM61, you should check the datasheet of each and decide for yourself if it fits your applicaton.
If your question is whether you can replace one for the other without software changes the answer I would guess is NO. The PT8211 is a stereo DAC, and has a clk, datain, and WS (world select) that makes the input data go to one channel or the other. It stays high for a whole word, then low for the whole next word, and so on. The PCM61 is a single channel DAC and LE has to go up and down at the end of each word shift.

Post Reply