I2S interface for audio ADC
ManAtWork
Posts: 2,176
in Propeller 2
Today, I've written a preliminary version of the resolver driver for my servo project. It includes an SPI interface for configuring the external audio ADC, a synchronous serial I2S interface to get the audio data and some code to de-modulate the signals from the resolver coils and calculate the rotor angle with the CORDIC cartesian to polar conversion.
Although the resolver application is very special and probably of not much use to anybody but me I think it's a good example of how to use the smartpins to implement a non-standard serial communication interface. Well... it actually is a standard but not as common as UART, SPI or I2C.
I finally managed to read the latest Spin2 docs so the code is a lot clearer than my earlier work which used a lot of bit-banging and inline assembler. Some commands like PINSTART() are quite powerful but the documentation of the smart pins are still very sparse and many thing have to be found out by trial-and-error. For example, PINSTART can't be used for pulse and transition mode because the WYPIN is discarded until after the pin comes out of reset.
Although the resolver application is very special and probably of not much use to anybody but me I think it's a good example of how to use the smartpins to implement a non-standard serial communication interface. Well... it actually is a standard but not as common as UART, SPI or I2C.
I finally managed to read the latest Spin2 docs so the code is a lot clearer than my earlier work which used a lot of bit-banging and inline assembler. Some commands like PINSTART() are quite powerful but the documentation of the smart pins are still very sparse and many thing have to be found out by trial-and-error. For example, PINSTART can't be used for pulse and transition mode because the WYPIN is discarded until after the pin comes out of reset.
Comments
So I'd been wondering about the master clock accuracy with the standard P2-EVAL 20MHz crystal and you've already managed to get quite close to the 88200 sampling frequency just with an easy to setup 180MHz P2. Audio will only be ~6 cents flat I think, which for most of us is probably not going to be perceptible unless played back at the same time as the reference to hear the beat frequencies.
I think tweaking the P2 PLL settings can get even closer to the ideal 180.6336MHz if we require better sampling frequency matching. Setting DDDDDD=31(divisor=32), MMMMMMMMMM=288(multiplier=289) gets you to 180.625MHz, assuming 625kHz is still fine for the PLL input, just not sure how much jitter it adds.
569/63 is closer still and the closest possible with a 20 MHz oscillator.
If you need high quality audio with exact sample frequencies I agree tahat it would be probably better to use a crystal with a multiple of the standard sampling frequency like 18.432 or 24.576MHz. However, we could try out if the noise caused by the PLL jitter for odd multiplication factors with the 20MHz crystal makes a noticable difference.
I am testing a Raspberry Pi based MiniDexed synth. It uses i2s for output, so maybe this code can be useful to try a P2 as a DAC for MiniDexed instead of HifiBerry. To be tested. P2 based DAC can do a lot of other things, visualisations, scopes, sequencers etc. so it is worth trying.