Playing audio via MQS in sln-local2-iot

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Playing audio via MQS in sln-local2-iot

2,975 Views
jnj
Contributor III

Hi All,

I want to play an audio file via MQS in sln-local2-iot. Audio is being played from a host processor which is connected to NXP via SAI2. So whatever data comes in SAI2 of NXP should be played via MQS . NXP could receive the data from SAI2.Checked by putting prints. But while writing the data to SAI3 using the following code snippet the data becomes zero.

sai_transfer_t xfer;

while (1)
{
xfer.data = Buffer;
xfer.dataSize = BUFFER_SIZE;
SAI_TransferReceiveEDMA(SAI2, &SAI2_SAI_Rx_eDMA_Handle, &xfer);
xfer.data = Buffer;
xfer.dataSize = BUFFER_SIZE;
SAI_TransferSendEDMA(SAI3, &txHandle, &xfer);
}

and MQS is configured by the following function.

void configMQS(void)
{
CCM->CCGR0 = CCM->CCGR0 & (~CCM_CCGR0_CG2_MASK) | (CCM_CCGR0_CG2(3)); /* Enable MQS hmclk. */

IOMUXC_MQSEnterSoftwareReset(IOMUXC_GPR, true); /* Reset MQS. */
IOMUXC_MQSEnterSoftwareReset(IOMUXC_GPR, false); /* Release reset MQS. */
IOMUXC_MQSEnable(IOMUXC_GPR, true); /* Enable MQS. */
IOMUXC_MQSConfig(IOMUXC_GPR, kIOMUXC_MqsPwmOverSampleRate64, 0u); /* 98.304MHz/64/(0+1) = 1.536MHz
Higher frequency PWM involves less low frequency harmonic.*/
}

Please help me to resolve the issue

Thanks in advance

0 Kudos
Reply
15 Replies

2,933 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

  From the RT1060 RM, you can find the MQS feature:

kerryzhou_0-1653017851363.png

So, maybe 16bit 16KHZ is not good, I suggest you test the matched sample rate, make sure that works normally.

Best Regards,

kerry

 

0 Kudos
Reply

2,934 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

  Do you test the MQS code directly previously?

  I mean, prepare the audio file, then use the SAI3 to play it to the MQS directly.

  I already share it in the community:

https://community.nxp.com/t5/i-MX-RT/Using-MQS-for-PAM8302A-amplifier-in-SLN-LOCAL2-IOT/m-p/1392638/...

  Please make sure this works at first.

Best Regards,

kerry

0 Kudos
Reply

2,929 Views
jnj
Contributor III

Hi @kerryzhou ,

Thanks for the response.I tried your source code directly first.But in that also I am getting noise along with the data.We checked the amplifier and speaker is working properly or not by feeding an analog signal as input of amplifier .It is working fine.But while giving the MQS as input we are facing the noise issue.In your source code also sai3 tx bit clock is 16KHz.

0 Kudos
Reply

2,925 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj 

   How do you check the noisy?

   In my post, you can hear the music also can play out clearly.

  Do you can't hear the clear music? Whether your GND is not plug OK?

Best Regards,

Kerry

0 Kudos
Reply

2,916 Views
jnj
Contributor III

Hi @kerryzhou ,

In your video audio is clear.But when I flashed the same in my setup I am getting noisy audio.I don't know whether it is hardware or software issue.I will share the hardware connections and audio file.

0 Kudos
Reply

2,910 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

  In fact, the code I have tested on a lot of boards, MIMXRT1050-EVKB, MIMXRT1060-EVK, SLN-LOCAL2-IOT, so the software works OK.

  My difference with you should the MQS driver circuit.

  I am using this one:

kerryzhou_0-1653048997189.jpeg

  You can try other driver hardware if you have.

  You also can record one video like me, let me hear it.

Best Regards,

Kerry

 

0 Kudos
Reply

2,905 Views
jnj
Contributor III

Hi @kerryzhou ,

We referred the sln-local-rd mqs driver circuit .Attaching the circuit diagram.Is it possible for you to test with this circuit?

0 Kudos
Reply

2,895 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj 

  Thanks for your updated information.

   Of course, sln-local-rd mqs circuit also OK to use.

   Do you design a new PCB, or add the MQS circuit externally?

  Can you share some connection photo about it? If you use the external MQS circuit, GND should also connect to your MCU board, otherwise, it may have noisy.

  Please also record one .mp4 like my file (https://community.nxp.com/t5/video/gallerypage/video-id/6289085416001), I need to hear it.

Best Regards,

kerry

 

 

0 Kudos
Reply

2,892 Views
jnj
Contributor III

Hi @kerryzhou ,

 

Thank you so much for your support.I will share the video.I have one more doubt. Do we need to give differential input instead of standard stereo signal to SAI3 while using sln-local2-rd MQS driver circuit?

0 Kudos
Reply

2,875 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

   SAI3 used as the MQS, it will output the MQS signal to MQS_RIGHT and MQS_LEFT, you just need to connect it to the following yellow area.

kerryzhou_0-1653363473445.png

You totally can use my previous working code, which already convert the audio data to the MQS data, then we can compare it, as we just have the MQS driver circuit difference. So, I don't think you need to use differential input now.

Best Regards,

Kerry

 

 

0 Kudos
Reply

2,859 Views
jnj
Contributor III

Hi @kerryzhou ,

Thanks for the response.One doubt regarding TFA9894DUK  (Already supported in sln-local2-iot) .How can we  change the amplifier frequency from 48kHz to 16KHz? Which all configuration files we need to change for setting the frequency as 16KHz. Could you please help me ?

0 Kudos
Reply

2,855 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

   I help you check with our solution expert.

   Due to the firmware in the TFA9894DUK , it is limit to the 48K, you can't set it to the 16Khz, you just can use 48K. And this chip is also out of stock.

  Wish it helps you!

  Any new issues, please help to create the question post, as one of the question post can't open too long time, thanks a lot for your understanding.

Best Regards,

Kerry

0 Kudos
Reply

2,844 Views
jnj
Contributor III

Hi @kerryzhou ,

Could you please do one help?Can you try your mqs software with the sln-local2-rd mqs driver circuit instead of your current circuit?Is it possible for you to try ?

0 Kudos
Reply

2,832 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @jnj ,

  Unfortunately, I don't have that circuit board, and chip ,otherwise, I will help you to check it, what I have is the 74 chip circuit which already share with you.

  So, if you have the 74 chip, you also can use my circuit to test it, that circuit is very easy. Then you can compare your result with my video.

 

Best Regards,

Kerry

0 Kudos
Reply

2,948 Views
jnj
Contributor III

Hi All,

We could playback via speaker now.But we are facing slight noise in the audio.We tried following ways

1.Tried to Write an audio buffer that is defined in the nxp sdk directly to SAI3 using SAI_TransferSendEDMA().We are able to play via speaker.But observing slight noise along with the audio data.
2.Recieve audio data that is playing from host processor via SAI2 , copy the data to a buffer and write the same on SAI3 for playing via speaker.In the above scenario also we are facing the same slight noise along with the audio data.Host sends mono data in the format 16 bit,16KHz.So SAI2 and SAI3 is configured with the same format.(sample rate is 16KHz,16bit and mono)


Queries

1.Does MQS work properly with 16bit,16KHz mono data? In reference manual it is mentioned that MQS accepts the following inputs:
                      • 44 kHz or 48 kHz input signals,2-channel, LSB-valid 16-bit, MSB shift-out first serial data (sdata)
                      • Frame sync asserting with the first bit of the frame (fs)
                      • Bit clock used to shift data out on the positive clock edge (bclk)

2.What should be the MQS_CLK_DIV and MQS_OVERSAMPLE for proper working as we are using the PAM8013AK amplifier?Currently we set it as the following values.
void configMQS(void)
{
    CCM->CCGR0 = CCM->CCGR0 & (~CCM_CCGR0_CG2_MASK) | CCM_CCGR0_CG2(3);        

    IOMUXC_MQSEnterSoftwareReset(IOMUXC_GPR, true);                            
    IOMUXC_MQSEnterSoftwareReset(IOMUXC_GPR, false);                            
    IOMUXC_MQSEnable(IOMUXC_GPR, true);                                        
    IOMUXC_MQSConfig(IOMUXC_GPR, kIOMUXC_MqsPwmOverSampleRate64, 0u);          
                                                                               
}

SAI3 clock as,
#define DEMO_SAI_CLOCK_SOURCE_SELECT (2U)
#define DEMO_SAI_CLOCK_SOURCE_PRE_DIVIDER (3U)
#define DEMO_SAI_CLOCK_SOURCE_DIVIDER (1U)
#define DEMO_SAI_CLK_FREQ (CLOCK_GetFreq(kCLOCK_AudioPllClk) / (DEMO_SAI_CLOCK_SOURCE_DIVIDER + 1U) / (DEMO_SAI_CLOCK_SOURCE_PRE_DIVIDER + 1U))


Kindly share your comments on the above queries 

0 Kudos
Reply