How can I count I2S MCLK ticks?

Showing results for 
Search instead for 
Did you mean: 

How can I count I2S MCLK ticks?

Contributor III

I'm designing a USB audio interface which uses an isochronous feedback endpoint to tell the host machine the required number of audio frames per USB frame. In order to calculate this value I'd like to count the number of I2S MCLK ticks which have occurred since the last USB frame.

How can I do this please? If it's not possible, is there an alternative way of calculating the USB feedback value? 

2 Replies

NXP TechSupport
NXP TechSupport

Hi, Don,

If you want to count the number of frames you have received or transmitted, can you declare a variable in the ISR of  I2S transmitter or receiver and increment the variable in the ISR?

Hope it can help you


Xiangjun Rong

Specialist V

Hi Don

I haven't ever used a feedback endpoint but have developed USB-audio class devices (also based on I2S). I found it easy to measure the clock "drift" between the USB host and the I2S (not necessarily the number of clocks) and then adjust the I2S clock when needed - based on the drift measured and I expect that you could also feedback the required value to achieve this, if that is your preferred method.

Note also that it is best to set up the rx and tx with intentional delays in order to tolerate larger drifts before (re-)correction is needed (i.e. adjustment of the compensation factor before the chance of clicks and such become critical). In my case I used a PIT to monitor the buffer's DMA wrap interrupt interrupt delay from the USB host timing reference point, generating a delta value from the ideal, which is then used as feedback. It is in fact documented at

Note that the uTasker project includes a complete synchronised audio device solution which has been used in such products (I have tested such products for many hours watching DVDs and such and never had a click or glitch....) - I don't think that any NXP examples use synchronisation so they tend to fail after a few minutes.....