News:

;) This forum is the property of Proton software developers

Main Menu

Digital Microphones and PICs

Started by Wimax, Aug 18, 2024, 01:40 PM

Previous topic - Next topic

Wimax

Hello everybody !

Has anyone experimented with interfacing and handling PDM or I2S digital microphones with DSP capable PICs ?

diebobo

Since nobody answered yet.. I have an I2S microphone on the way and a new board to put it on, however it will take prob. at least a month before i will start playing with it.. Will get back here with the results :)

Wimax

Hi Diebobo,

With which micro have you thought of interfacing it? I have searched the net a bit and, apart from the hardware, I have found very little in the way of software other than Arduino applications with the inevitable libraries.

diebobo

I've got a SPH0645LM4H-B on the way from Mouser. I wanted to do some experiments for fun with a microphone and read that into the AD PIC, then i learned there where Digital mems microphones and settled on that one.. I did not explore Arduino or other code examples, looking at the datasheet i think i can get it working with the PIC i selected, it supports I2S so getting data should be doable, interpreting that data is something else i guess but thats what we will find out :) .. The selected PIC is a dsPIC33CK256MP508-I/PT

Wimax

That MCU should have the power to handle it without any problems.
I look forward to hearing about it on the forum as soon as you have a chance to try it out! ;)

diebobo

Will do !.. Mic and PIC just delivered from the U S of A, waiting for the boards andddd time to do stuff after that.. Will report when i have something to report ;)

Wimax

Hi diebobo,

Did you try something ?

diebobo

The bugger is alive and have got the first data out of it a few days ago... Will be working on normalizing / formatting the data to something usefull the coming days...

Wimax

Very good ! I look forward to hearing about this channel  ;D

diebobo

Oké oké, couldn't resist to put my fingers at random keys on my keyboard and thing started happing all of a sudden.. A quick teaser, cause i was also curious so I started something quick to have something to show you :)

I there anything you would like me to test / code ? I did not have a special reason other then, ahh lets play with it, to add it to my board.. So if u have request -> tell me..

Also check the link for video demo i just took: https://photos.app.goo.gl/8Xj61Se6BTb8TCWi7

John Drew

Wow, that is amazing.  The video tells it all. Could you draft up a block diagram?
John

Wimax

Yes! It's amazing !

I'm very curious ;D

Some details about the board and the display ?

Could you share a positron test code ?


diebobo

Sorry for the delayed reply, i am trying to get it working with DMA but no luck so far.. Will be providing more info soon :)

Wimax

Don't worry! I've had to struggle with DMA in the past as well to get it working the right way.
My curiosity is really high !  ;D

diebobo

#14
Hi, here with an update..

Below this post i will attach my Library for this I2S Mic, the Lib needs some tidy up to do and for now its Fixed for SPI3 but i will do that some other time, for now you can use it or adjust yourselfs if other  SPI port is needed :)..

DMA works, or interupt driven works also if u prefer, but i prefer DMA because its less overhead compared to SPI but u need to stay out of trouble with CPU intense task like clearing an array with CLEAR Myarray, if that array is big then DMA has no chance to acces the Bus and the SPI buffer might not be read on time / be able to wright that data to memory = buffer full = problems :).. So you know.

For John i also included the Mic Part of the schematic, i gues that is what u meant ? If not ask again :)

In main code do this somewhere :

$define I2S_MIC_SPI             3
$define I2S_MIC_Sample_Size     135

Include "LIB_I2S_MIC.bas"

Sample Size, the DMA just keeps filling and does not stop.. This is the amount of real net samples taken. Normally you have a left and right mic, my lib counts on 1 mic so when constructing the samples only data > 0 is real data and put into the Samples buffer.

ANSELB  = %0000000000000000 '
TRISB   = %1111111101011111 ' 2 = Button 1, 3 = ROT_B, 4 = ROT_BUTTON, 5 = I2S CLK, 6 = I2S Data, 7 = I2S WS.

PPS_Input (cIn_Pin_RP38 ,  cIn_Fn_SDI3)   ' SPI 3 Data In                                     
PPS_Output(cOut_Pin_RP37, cOut_Fn_SCK3)   ' SPI 3 Clock     
PPS_Output(cOut_Pin_RP39, cOut_Fn_SS3OUT) ' SPI 3 SS     

ANSELB and TrisB included for reference, PPS IN/OUT for I2S setup.

I2S_MIC_Init (0x20)
I2S_MIC_DMA_Enable ()
''I2S_MIC_Interrupt_Enable ()

Init 1 time only, comment DMA and Uncomment Interrupt if prefer.. After this the I2S Collection is running.


    SSD1322_DrawString(4, 3,  "I2S MIC", Underlined, 15 )

    I2S_MIC_Sample_Construct ()

    Dim Sample_Size_Per_Y_Pixel As Dword

    Sample_Size_Per_Y_Pixel = I2S_MIC_Sample_Array_MaxValue - I2S_MIC_Sample_Array_MinValue ' Delta Max / Min
    Sample_Size_Per_Y_Pixel = Sample_Size_Per_Y_Pixel / 46 ' Target size of 46 Y Pixels.

    For I2S_MIC_Sample_Array_Index = 0 To I2S_MIC_Sample_Size - 1 ' Drawin of 135 X Pixels. 1 Pixel = 1 Sample. So make sure $define I2S_MIC_Sample_Size = at least this size + 1
      I2S_MIC_Sample = I2S_MIC_Sample_Array [ I2S_MIC_Sample_Array_Index ]  - I2S_MIC_Sample_Array_MinValue ' Format Sample relative to Min Value.
      I2S_MIC_Sample = I2S_MIC_Sample / Sample_Size_Per_Y_Pixel ' Re-Using Variable to calculate Y Loc
      SSD1322_Draw_Pixel ( I2S_MIC_Sample_Array_Index + 4 , I2S_MIC_Sample + 14, 15)
    Next


This is my code to make it visible, if this is the correct way i don't know. Just playing at the moment :)

Explanation : The data = 24 bits and has use swings so not dobale to just divide a sample by an x amount and call it a day...
The I2S_MIC_Sample_Construct () is taking the raw sample data which include 0 data value from the MIC which is not connected ( this is just how I2S works, it alternates between Left and Right channel. Not connected ? Tough luck, you just get zero's and need to deal with it )... This function also give's the maximum number and lowest number in sample array.. Now, this is not perfect ! The raw value keeps getting updated by the DMA while this function is called for, so there might be actually bigger data being written. So not perfect, but just for playing its oke.. I think 1 way to tackle this is to do DMA a 1 runf for X samples, when done its done..  You do your thing with the samples, and when done start DMA again . Couldn't get that working and moved on, for now ).

So with the Max number and Min number i get The Delta between them, Dived that by the number if vertical pixels it need to be divided. The rest is just to get next value form the array and draw it..

Soooo, with this post and the attach library which has comments in it as well i think you should get something started as wel :)

I tried to do some effort to get some VU meter thingy presented but was out of luck getting that working with some FFT ?? routines. The FFT routines where not compile-able or crashed the CPU in the DSPIC routines.... Anyway, another time i guess :)

About the board, i will post that in the lounge area. Think its a nice idea that sometimes people can show there current projects and creations to show off ;) I will edit this post with a link when setup is done...



Last video from it, also getting some more FPS and no errors anymore in data :) : https://photos.app.goo.gl/m489uQX6VPAFnj2C8

Board Topic : https://protoncompiler.com/index.php/topic,2374.msg18222/topicseen.html

Wimax

#15
Hi diebobo! It is very very interesting !!


Let me see if I understand a little how it works. The microphone you use accepts a clock from 1,024 to 4,096 MHz with an oversampling factor of 64x. Through SPI with I2S protocol you provide the clock at BCLK frequency and the WS signal at BCLK/64 frequency synchronized with the former. The microphone is activated by detecting a clock > 1 MHz and provides output data as sequences of I2S format 24-bit with the first 18 as useful bits and the following 6 unused bits at zero. Operating with only one microphone, stereo mode being provided anyway, the 24-bit packets are alternated for the left and right channels, so there will be 18 useful bits + 6 nulls followed then by 24 null bits and so on. The data are still loaded onto SPI at a rate of 16 to 64 kbps ?.
Have you tried to save the data via serial or other means with a test sine wave audio source to do some offline verification ? It would be very interesting to apply dsp on the data acquired in real time, the CK series should offer some "beer" for such things  ;)