Shop OBEX P1 Docs P2 Docs Learn Events
I2S interface for audio ADC — Parallax Forums

I2S interface for audio ADC

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.

Comments

  • As I said, this is probably not of much use for most people, here. But I post the code for the case anybody might be interested in using the ADC for audio input. This can't be done with the current code but it might serve as some sort of a primer.
  • This is interesting ManAtWork. In contrast to input, I was hoping to do some I2S output code at some point to drive an I2S PMOD DAC device I have and play back CD rate wave file sources, or other wavetable data, which hopefully should be easier than I2S input. Ideally @Ahle2 might even like add that to his audio driver one day.

    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.
  • rogloh wrote: »
    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.
  • For my servo drive the exact (absolute) frequency doesn't matter at all. But it's important that all internal frequencies have special relative ratio to each other. The PWM power stage driving the motor has voltages 100 times higher than the resolver signals. Although all cables are shielded some crosstalk can't be avoided. So it's important to exactly hit one of the notches of the ADC stop band attenuation to make sure the noise is suppressed as perfectly as possible.

    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 forgot to post the schematic. The connections of the signals to the P2 pins are listed in the source code.
    1108 x 901 - 26K
  • pik33pik33 Posts: 2,366

    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.

Sign In or Register to comment.