This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TLV320AIC3204: Digital microphone with PDM output - help needed please

Part Number: TLV320AIC3204


Tool/software:

Hello,

I never got to the point of exploring this further but I'm now back on this project.

My current circuit setup uses IN1_L (pin 13) and IN2_L (pin 14) for analog microphones.

For development purpose, I have blank pads on IN1_R (pin 14), IN2_R (pin 16), IN3_R (pin 21) and IN3_L (pin 20) inputs as well. They are currently not used but I can solder wires on the pads to access the pins.

DIN / MFP4 (pin 4) is not used;

SCLK / MFP3 (pin 8) is used as a PCM CLK 8kHz input from a modem.

MISO / MFP4 (pin 11) is used for PCM DATA output to a modem.

GPIO / MFP5 (pin 32) is used for PCM CLK 2.048MHz output to a modem.

Basically, pins 8, 11 and 32 route audio to a modem's PCM input voice channel and I need this.

Question 1: As per document SLOS602A–SEPTEMBER 2008, P0_R81 (ADC channel setup):

D5–D4 R/W 00 Digital Microphone Input Configuration
                         00: GPIO serves as Digital Microphone Input
                         01: SCLK serves as Digital Microphone Input
                         10: DIN serves as Digital Microphone Input
                         11: Reserved. Do not use
D3 R/W 0 Left Channel Digital Microphone Power Control
                         0: Left Channel ADC not configured for Digital Microphone
                         1: Left Channel ADC configured for Digital Microphone
D2 R/W 0 Right Channel Digital Microphone Power Control
                         0: Right Channel ADC not configured for Digital Microphone
                         1: Right Channel ADC configured for Digital Microphone

I presume that I need to select only ONE of the above options? So if I want to select right ADC as mic input, then I wouldn't need to configure D5-D4 so how do I configure these registers? Do I set them to '11' eventhough it says "Reserved. Do not use"? Basically, what I get from this is that a digital mic can stream its PDM data to 5 different digital inputs?

Question 2: As per the table in question 1, if I decide to use "left channel" as digital input, I presume that it blocks the entire left channel (pins 13, 15 and 20) for digital microphone inputs? If this is the case, then perhaps I should experiment with the right channel since it is not used? Therefore, I would set P0_R81 to 0bx10001xx?

Question 3: Again as per SLOS602A–SEPTEMBER 2008 page 25, figure 5.2 "Analog routing diagram", if I use INx_R for the digital microphone input, before going into the ADC, it goes into the Mic PGA. Since this is a digital mic, I presume I will not need the Mic PGA so then I would simply set P1_R59/60 to Left/Right MICPGA is set to 0dB? This would then make that I don't need to configure P1_R52/R54/R55/R57 either?

Question 4: Once I have the digital microphone input configured (e.g. IN1_R pin 14), I guess I don't have the choice but to sacrifice either pin 8, 11 or 32 for the microphone clock? Or is there another pin I can use to time the data? For instance, on my existing circuit, pin 1 MCLK has a 3.072MHz clock going to it coming from a microcontroller. Can I use that for the clock for microphone clocking since this is the base CODEC clock, therefore, everything should be synched off that clock?

Question 5: Once I confirm that microphone has proper clocking and sends its data to the CODEC input, how can I route that I2S audio to the DOUT / MFP2 (pin5) or SEC_DOUT / MISO_MFP4 (pin 11)?

Hopefully this all makes sense!

Thanks!

Benoit

  • Hi Benoit,

    1) You actually need to set all of them. The D5-D4 set which pin the PDM data will arrive into. D3 and D2 set a multiplexer that passes either the sigma delta data (Analog ADC) or the PDM data to the serial interface. The application reference guide gives a little more detail on this than the datasheet does.

    2) You're correct, that analog input pins will be ignored if you select a channel to be digital input.

    3) You're also correct here. As shown in the diagram above, the digital mic input skips the PGA. So settings here can be ignored.

    4) Pin 8 can't output the PDM clock, but yes you have to use either 11 or 32 as your clock output.

    5) DOUT (pin 5) by default is the digital serial output so no extra configuration should be needed. Pin 11 is the DOUT for the secondary interface, which is a different bus altogether, so I would stick with pin 5.

    Best regards,
    Jeff McPherson

  • Hi Jeff,

    Thanks for the detailed explanation. I'll just re-word a few things to make sure that the context of what I am trying to achieve is clear:

    My current design, which I want to avoid modifying as much as I can, has three main parts: an MCU, a modem and the CODEC.

    The MCU is tied to the CODEC's "master" port for IP audio and the "slave" port is tied to the modem's PCM port for voice audio.

    For the master port (IP audio), the MCU outputs a 128KHz BCLK and a 3.072MHz MCLK. In return, the CODEC outputs an 8KHz WCLK and 8-bit audio. The MCU samples the audio on the WCLK l-to-h transitions, each byte is packetized then at some point is sent over IP through some other means.

    For the slave port (voice call audio), given that the modem can only work in one configuration, it is the modem who provides a 2.048MHz BCLK and an 8KHZ WCLK to the CODEC then the CODEC outputs 16-bit PCM audio to the modem's PCM audio input.

    In either of these two cases (IP or voice), they both use the analog microphones on the IN1_L and IN2_L analog inputs. All this works perfectly well.

    Now, I want to add a digital microphone and the goal is to hopefully send its audio to either the IP channel (master) or voice channel (slave).

    The CODEC's slave port is already tied-up with pins 8, 11 and 32 for the modem's voice channel and the only pin left available is DIN / MFP1 (pin 4) and that's fine since it is one of the accepted pins for digital audio.

    The misunderstanding is more with the microphone's clocking: I was thinking of either using the MCLK of 3.072MHz or use S_BCLK of 2.048MHz coming from the modem. The problem with using the 2.048MHz is that it would work only during a voice call as opposed to the MCLK which is always present since it comes from the MCU so it would work on both the IP or voice audio. My guess is that if I use the CODEC's MCLK (from the MCU), I presume that this will make the whole system synch'ed-up with the digital mic's audio.

    Now for my questions to your answers:

    #1- Given that DIN / MFP1 (pin 4) is currently not used, that's the input I will have to use for the digital microphone input. So I understand now: I cannot use the analog input directly e.g. pin 13 for instance, contrary to what I understood at first (which I thought was weird!). Therefore, P0_R81 bits D5-D4 specify which digital input I will use - in my case I will set these bits to 10: DIN serves as Digital Microphone Input (pin 4). In that same register, I then need to specify which ADC input I will sacrifice for the digital mic and in my case, it will the the right ADC because I am using the left one for the two analog microphone inputs therefore bit D3 will remain '0' Left Channel ADC not configured for Digital Microphone and bit D2 will be set to '1' Right Channel ADC configured for Digital Microphone. Is that correct?

    #4- Since S_BCLK (GPIO / MFP5) pin 32 will already have a 2.048MHz signal on it coming from the modem going into the CODEC, can I use that same clock and just 'split' it and feed it to the microphone's CLK input? If so, instead, can I just split the 3.072MHz MCLK coming-out of the MCU going into the modem's MCLK input since that clock is always available in both voice or IP audio? That would be ideal.

    #5- I've indicated that ideally, I'd like to be able to stream the audio on both the IP or voice channel (one at a time). You indicated that DOUT (MFP2) pin5 is the default output for digital audio and that's fine. But how would I route it to the S_DOUT (MISO / MFP4) pin 11 instead of the default?

    New questions:

    #6- If I feed the digital mic with MCLK 3.072MHz and pipe its PDM data into DIN (pin 4) with the result being piped-out the CODEC on DOUT (pin 5), I can then just turn-off the PWM that goes to the CODEC' BCLK input and in return, the CODEC will stop outputting WCLK out of pin 3?

    #7- As for the format out of the CODEC on pin DOUT, for analog audio, I use DSP format because this is the equivalent of PCM. For the digital mic, can I keep DSP? Or do I absolutely have to force it to I2S?

    Thanks again!

    Benoit

  • Hi Benoit,

    Thank you for the context. I don't think I understand what you mean by "master" and "slave" port on the codec. I think you're referring to what the datasheets call "primary" and "secondary" I2S interface. Correct me if I'm wrong but I think my answers to your questions will be the same.

    1) You are correct.

    4) I'm not confident that this will work. The clock of interest here is the ADC_MOD_CLK that comes out of the clock tree in the codec. This clock is what your digital microphone will need in order to sync up correctly to the internals of the codec and decode the data properly. This clock gets derived from MCLK anyway so I don't think syncing is an issue anymore than it would be for the analog mics. But I do think you're out of pins since 11 and 32 are already being used up by your interfaces. Even if one of your clocks (either 3.072 or 2.048 MHz) was equal to the ADC_MOD_CLK, I worry that there'd be no way of ensuring that it was in sync with the internal ADC_MOD_CLK.

    5) Pin 11 becomes the output if you set the LSB of Page 0 Register 33 to 1.Both Pin 11 and Pin 5 are multiplexed to the output from the serial interface.

       

    6) If BCLK is used as the PLL input source, then yes WCLK will stop. If MCLK is used, then BCLK will have no effect.

    7) Once the data reaches the serial interface, you can choose whatever format you like. You will not be forced to I2S by using digital microphones.

    Best regards,
    Jeff McPherson

  • Hi Jeff,

    Thanks for the detailed reply.

    Yes, by "master" and "slave" port on the codec, I meant "primary" and "secondary" I2S interfaces.

    I'll do some testing with #4 re: ADC_MOD_CLK. So from what I understand now, previously with analog microphones, the MCU was reading the data bits off of the 128KHz clock during the high-cycle of the WCLK (the WCLK caused a interrupt on the MCU which triggered the MCU to read the data off the DOUT pin timed with the 128KHz clock transitions).

    Now with a digital mic, either GPIO or MISO clocks have to be setup to output a clock based off ADC_MOD_CLK. Fair enough, however...

    Using analog mics, each data bits were sampled off of the BLCK but every byte for these bits were clocked-off the WCLK.

    So now for the digital mic, S_DOUT/MISO will be used as the microphone clock, which will most likely be quite fast and its PDM data bits will go into DIN pin 4. Good up to here. But in order for the MCU to sample the bits, what clock does it sample the bits off-of? I'm trying to wrap my head around the mapping of analog signals to digital signals:

    > From the MCU's perspective, there are three things: it outputs an 128KHz BLCK to the CODEC, the CODEC generates a 16KHz WCLK and pipes its 8-bits of data out of DOUT.

    > For digital mic, S_DOUT (let's say) needs to be configured as an output clock based off ADC_MOD_CLK and this is the clock that feeds the mic. In return, the mic will then send its PDM audio data to DIN (pin 4) and the audio will come-out on DOUT (pin 5). Fine up to here.

    But now the question: how/where does the MCU sample the bits off of DOUT? In other words, what clock source does the MCU use to time each byte in order to sample the bits and off what clock does it sample each bit off-of?

    Also, Is there a way to make the CODEC output 8-bit data out of DOUT from the CODEC like with my analog configuration?

    Thanks again!

    Benoit

  • Hi Benoit,

    Using analog mics, each data bits were sampled off of the BLCK but every byte for these bits were clocked-off the WCLK.

    This is still true of the PDM/digital mics. The codec will still convert the digital mic data into I2S/TDM and place the data onto DOUT such that it is clocked against BCLK. From the MCU point of view here, the data format will be the same.

    Think of the ADC_MOD_CLK as being synchronous but not related to the I2S bus (BCLK and WCLK). The mod clock helps the mic latch the data coming from the mic, the codec receives this data, and then on the other side of the black box the PDM data is converted into I2S and sent out over DOUT with the data latched to BCLK. Likewise one sample/byte corresponds to a half cycle of WCLK just as it was in the analog mic case.

    Best regards,
    Jeff McPherson

  • Hi Jeff,

    It works!

    The microphone I am using is a Knowles V2D200S.

    For the electrical connections, the only thing I had to do was:

    1) Solder the microphone's PDM data output to the CODEC's pin 4 input;
    2) Solder the microphone's clock input to the CODEC's pin 11 output;

    As explained in an earlier post, I have an application I wrote that connects to my device over IP. Then, I press 'play' and it starts streaming from the analog side, over IP, to my app then I hear in my speakers.

    To get the digital mic working, I simply started streaming for the analog mic then sent it two commands to change CODEC parameters on the fly.

    Here are the only difference for the digital mic vs the analog mic:

    P0_R55: Analog: 002 --> 0x02 --> 0000 0010   Digital: 014 --> 0x0E --> 0000 1110
    >>> D4-D1=0111: MISO is clock output for Digital Microphone

    P0_R81Analog: 228 --> 0xE4 --> 1110 0100   Digital: 232 --> 0xE8 --> 1110 1000
    >>> D5-D4=10: DIN serves as Digital Microphone Input
    >>> D3=1: Left Channel ADC configured for Digital Microphone

    Now that it works, do you have any recommendations of other registers I should tweak or look into? Anything pertaining to gain or volume perhaps?

    I will be off for holidays as of today Friday December 20th and returning to the office on the 6th of January so if you respond to me and I don't, then that's why.

    Thanks again for all your help and happy holidays!

    Benoit

  • Hi Benoit,

    Glad to hear it's working. If you have a valid data stream there's not much else you need to change. At most you should adjust volume based on what kind of volume you are expecting at the next stage. You can try to increase or decrease the volume to find a balance between a strong output level without bringing up the noise floor too high.

    Best regards,
    Jeff McPherson

  • Hi Jeff,

    I know we're January 21st but happy new year anyways!

    Sorry for the delay, I had a few things on the go that had to be done after the holidays and now I'm back on this project.... so other than P0 R83/84 for the volume, is there anything else in terms of 'gains' or 'volume' you can think of? For analog mic, there's the mic gain then the ADC volume. What about a PDM microphones?

    Also, I'm looking through the SLOS602A datasheet and on page 4, for pin 4, it states that this pin can either be DIN or MFP1. For DIN, it states "Audio serial data bus data input" and if set to MFP1, one of the options is "Digital Microphone Input". What's the difference between these two statements? To me it sounds like the exact same thing? I'm sure it's not. Can you educate me on this?

    Thanks again!

    Benoit

  • Hi Benoit,

    Happy New-ish year to you too.

    The digital mic won't have access to a typical PGA gain or a digital equivalent. You'll only have the digital volume control. But I believe these digital PDM mics have some kind of gain given to them so that the data isn't buried in the noise floor. You'll have to check based on the sensitivity spec of the mic.

    "Audio Serial Data Bus" refers to an I2S stream. This is a 3 wire bus that is industry standard for transmitting audio ( BCLK, FSYNC, DIN, etc.) and is how the ADC data is transmitted, and the DAC data is received 

    Digital Microphone's typically don't use I2S and instead use a PDM modulation, resulting in a single wire stream that's latched to the given clock as we discussed above.

    So the pin is used to either receive an I2S stream (like from an MCU, PC, etc) or receive PDM data from a digital microphone. 

    Best regards,
    Jeff McPherson

  • Ok gotcha.

    I'm almost done with this testing but for the life of me, there are still a few things I cannot wrap my head around.

    As explained earlier, MCLK (pin 1) is getting a 3.072MHz PWM from an MCU. The following setup is for analog microphones and that works:

    Using the primary port for IP channel audio, the MCU sends a 128KHz PWM to BCLK and the CODEC is set to have WCLK as an 8kHz output back to the MCU. The audio sampled off the analog microphone front-end is digitized and returned on DOUT (pin 5). It then gets sampled by the MCU off the 8kHz WCLK, packetized and sent out over IP as an 8-bit 8kHz bit stream.

    Using the secondary port for voice channel audio, after a call is connected, the modem sends a 2.048MHz PWM to S_BCLK and an 8kHz short synch pulse to S_WCLK. In return, this samples the microphones on the analog front-end and returns the digitized data out on S_DOUT (pin 11). The end-result is that I can place a voice call to the modem and hear the audio in my phone.

    For the digital mic, here's what I have accomplished (I will eventually do a new circuit design when I have everything working):

    The PDM microphone's data pin is tied to the CODEC DIN (pin 4) and the microphone's CLK input is tied to MISO pin 11. For now just for testing, pin 11 is also tied to the modem's PCM data but I set it as a clock through the registers (to feed a clock to the PDM mic). When I connect over IP using my app, I press 'play' and all I need to do is to set P0_R55 to 0x0E and P0_R81 to 0xE8 and  then I can hear the audio from the PDM microphone over my IP stream. So far so good, this all works very well.

    The problem I am having now is trying to figure-out how to accomplish this over the voice channel with the least physical modifications possible to the hardware. As you stated earlier and as per the docs, the secondary interface used by the the voice audio with analog mics already uses pins 11 and 32 for the clocking from the modem. Unfortunately for me, these pins are the only two ones that can also be used for the PDM microphone clocking. So technically, I'm short one pin as you had explained in an earlier message.

    However, this is where I need your help: what about if I was to use the WCLK OUT (pin 3) as a PDM microphone clock? I understand that the PDM clock should be taken off of either 11 (MISO/MFP4) or 32 (GPIO/MFP5) "Digital microphone clock out" as per the documentation, but what if I was to modify the PLL values and use WCLK (pin 3) as my PDM microphone clock output? I mean, the PDM microphone won't know where the clock is coming from and that clock will also be derived from the MCLK though the different layers, correct? On the MCU, I can set the WCLK input as high-impedance so that it does not affect the PDM mic.

    If this works, I'm now just trying to figure-out how / which registers to configure so that the CODEC's MCLK still uses the 3.072MHz PWM from the MCU then from that, the CODEC will output a 1.024MHz clock out of WCLK that will then be fed to the PDM mic's clock. This would clock the PDM mic's data out to DIN (pin 4) (just like the IP audio) and S_BCLK, S_WCLK and S_DOUT would work like usual (when on a voice call using analog microphones).

    In fact, the microphone (a Knowles V2S200D) can work in low-power mode where fClock needs to be between 600kHz and 950kHz or in normal mode where fClock is between 1.2MHz and 3.3MHz.

    So would that work? Can I use WCLK as a clock output to feed to the PDM mic's clock input which in return will send its audio data to DIN (pin 4) then have that audio passed to the secondary port down to the modem? If all clocking is derived from the MCLK, why wouldn't it work?

    Does this make any sense?

    Thanks again!

    Benoit

  • Hi Benoit,

    This idea sounds solid to me but I don't think WCLK is the right option since it will get messy with maintaining the right sample rate.

    If GPIO or MISO is available (sorry hard for me to tell quickly since we're talking about this with no pictures) you could use one of those and directly interface with the MOD_CLK using the clock out function (the multi-function table calls this AUX CLOCK OUT).

     .

    I think this would be a cleaner path to doing what you're describing.

    Best regards,
    Jeff McPherson

  • Ah! I didn't realize that DOUT could also be a CLKOUT! 

    That's the thing, GPIO and MISO are used for the secondary audio interface when doing voice audio due to how the modem works; GPIO is used for S_BCLK input and MISO is used for S_DOUT output. S_BCLK and S_WCLK are both inputs coming from the modem's PCM channel and the problem is that the modem has to be the one driving the clocks so I don't have the choice but to use these.

    But when the device runs IP audio, then it uses the primary audio interface because the MCU samples the audio data and sends it to the modem using a UART.

    I think that using DOUT is the better option because it is an output that can be split and will be going into two inputs: the MCU's audio-in pin for IP audio and the PDM microphone's CLK pin.

    If this works, then I will reevaluate with the group here to see if we still need both IP and voice audio. The thing is that DOUT/MFPS2 is where the audio bitstream of the IP audio comes-out of and goes to the MCU therefore I won't be able to use DOUT with the PDM mic if it is being streamed as IP audio. This would only be good for the voice-channel audio. But that's my problem. I could always have an I2C "soft switch" that switches the PDM clock between different sources on the CODEC depending on if I need IP audio or voice audio.

    But for now, since I've already gotten the IP audio to work with the PDM mic, my goal is now to see what is involved in getting the voice-channel audio to work with the PDM mic. Once I know what is involved and what registers need to be modified to accomplish such task, then I will re-evaluate what the team needs and will adjust to that (most likely a revamped circuit to accommodate the PDM mic).

    Here's a quick look at that part of the schematics:

    Feel free to comment if you have more input.

    Again, many thanks for your help. In the meantime, I'll let you know if this works.

    [UPDATE] I used P0_R53 and set it to 0x16 and I see the DOUT pin go from low to high but I don't see a clock signal. So now, what clock signal should be there and how do I get it there? Meanwhile I will go through the docs.

    Benoit

  • Hi Benoit,

    Two more registers are at play to get the CLK OUT to work. You've already assigned DOUT to CLK OUT, now you need to select the clock source and power up the divider:

    Best regards,
    Jeff McPherson

  • hah! That's exactly what ChatGPT gave me just now! Ok, will check this right now and let you know.

    Thanks!

    Benoit

    [UPDATE] Ok, so it works but the audio stream has a loud repetitive clicking sound. Using my logic analyzer, the PDM clock give a perfect 1.024MHz with P0_R26=131. I can hear the audio if I tap the mic, it's just that clickity-click that is annoying. I attached a sample recorded off another phone... Not sure you'll be able to hear it. Was recorded on an iPhone.

    New Recording 6.m4a

  • Hi Benoit,

    Your M divider is equal to 3? The clock given from the normal "digital clock output" should be 3.072MHz right? I was expecting the M divider to be equal to 1 so that the clock out is the same as the MOD_CLOCK, which is equal to the PDM clock output.

    Best regards,
    Jeff McPherson

  • If I set the M divider to 1, the PDM clock is roughly 3.125MHz but the audio is just white noise. If I set it to 3, then the PDM clock is 1.024MHz, which is the the same frequency as when it transmits over IP (which works). However, on the voice channel, setting it to 3 create the clicks like in the audio file I attached in my last post. Did you manage to hear the audio file? So basically, setting to anything else other than 1 creates clicks or whitenoise.

    This is really the last problem I need to figure-out - how to get rid of the clicks. I'm confident it has to do with the clocking since everything works fine over IP and when I use analog mics, then it works both over IP and voice.

    Let me know if you have other ideas. I'll continue to test in the meantime.

    Thanks again!

    Benoit

    [UPDATE] Finally got it to work! I will admit, there's a lot of registers to go through and amidst all the available documentation, it is still a complex device. Anyhow, I think the one register I kept forgetting to set was P0_R25 as it was set to 0. As soon as I changed it to 7 (CDIV_CLKIN = ADC_MOD_CLK), the clicks went away. Let's not close this just now in case I have more questions but for now, I think I'm good for a while. Thanks a million for your help!

  • Hi Benoit,

    Gotcha. Without setting CDIV_CLKIN to ADC_MOD_CLK you probably got the right frequency but the phase was off creating the clicks.

    Glad to hear you got what you needed out of it. Let me know if there's anything else I can help with.

    Best regards,
    Jeff McPherson

  • The last thing that I don't seem to be able to get to work is the volume with P0_R83. It seems that regardless what I put-in, the volume is always the same. Is this normal?

  • Hi Benoit,

    Does it work with your primary interface with the analog mic? Looking at the diagram I think it's implied that the digital mics skip all the analog volume control because the tap happens after the sigma delta modulator.

    A bit of an obtuse way of applying some volume control after the fact is to implement a biquad (EQ) filter with a flat frequency response but a lower gain. But it's all digital volume anyway, so it might be easier to apply it on the I2S receiver side based on your system.

    Best regards,
    Jeff McPherson

  • Yes, I believe it worked with the primary interface but to re-test it to confirm, I'd have to desolder wires and I want to avoid doing that because my setup currently works with the modem on the voice channel so I'll leave it as-is because I can also tweak the volume on the modem's PCM interface, it has both audio volume and a microphone gain so that gives me more than what I need.

    Thank you so much for all your help, it is extremely appreciated, you are awesome!

    I will mark this as resolved.

    Have a great day!

    Ben from Canada