Teensy 4.1 Audio bit clock activation

Status
Not open for further replies.

DonP

Member
I am trying to do what should be simple, but I can't find how. Without using any of the Teensy audio library code, I simply want to turn on the audio bit clock BCLK1 at 1.41MHz. I imagine (hope?) that this involves just a couple of lines of code. Can somebody please guide me?
 
Well I think its various lines of code, the setup for I2S hardware could be copied from the I2S classes and the BCLK changed to
16 per sample from the 32 per sample used by the audio library. What exactly are you trying to do?
 
I simply want to turn on the audio bit clock BCLK1 at 1.41MHz. I imagine (hope?) that this involves just a couple of lines of code. Can somebody please guide me?

It's a lot more than just a couple lines. First the audio PLL has to be turned on and configured. If you only want MCLK, that is just a few extra lines once the PLL is on. But for BLCK, you need to configure almost everything about the I2S port, because the BCLK waveform depends on how the I2S hardware settings use the incoming timing from MCLK.

The code can be found in output_i2s.cpp. Look for the config_i2s() function, and skip the first half which is code for Teensy 3.x. You'll also need to find the set_audioClock() clock function, which configures the PLL hardware. I recommend copying too much code first to just get it working before you try trimming it down to just the bare essentials.

Might also be worth mentioning we default to use of 2.82 MHz BCLK, mainly because some chips (particularly I2S MEMS microphones) do not work with 1.41 MHz, but virtually all I2S chips work with 2.82 MHz and just ignore the extra bits they don't actually use.
 
It's a lot more than just a couple lines. First the audio PLL has to be turned on and configured. If you only want MCLK, that is just a few extra lines once the PLL is on. But for BLCK, you need to configure almost everything about the I2S port, because the BCLK waveform depends on how the I2S hardware settings use the incoming timing from MCLK.

The code can be found in output_i2s.cpp. Look for the config_i2s() function, and skip the first half which is code for Teensy 3.x. You'll also need to find the set_audioClock() clock function, which configures the PLL hardware. I recommend copying too much code first to just get it working before you try trimming it down to just the bare essentials.

Might also be worth mentioning we default to use of 2.82 MHz BCLK, mainly because some chips (particularly I2S MEMS microphones) do not work with 1.41 MHz, but virtually all I2S chips work with 2.82 MHz and just ignore the extra bits they don't actually use.

Thank you. That is very helpful - hopefully I can find my way through that code (better commenting would be really nice)
 
I have the bit clock running - thank you, but only at 2.8 MHz. My microphones are only specced to 1.5MHz, so I really need the 1.4MHz option. What should I do to achieve that? Sorry all, floundering a bit here.
 
I have the bit clock running - thank you, but only at 2.8 MHz. My microphones are only specced to 1.5MHz, so I really need the 1.4MHz option. What should I do to achieve that? Sorry all, floundering a bit here.

A Question: Why don't you just use the Audio library and set it's samplerate to 22kHz?
That's easy. You can find the setting in AudioStream.h

#define AUDIO_SAMPLE_RATE_EXACT 44100.0

Or use the code you copied and use 22khz instead of AUDIO_SAMPLE_RATE_EXACT.
 
Sure (but I now have my answer to how to achieve the 1.41MHz bclk1, although how I was supposed to guess the method is beyond me). Anyway, it is a TDK T3902.

Unless anyone would like to take this off in a new direction, I'm happy to call this question closed.
 
TDK T3902 uses PDM format. It should work with the PDM input feature in the audio library.

https://www.pjrc.com/teensy/gui/?info=AudioInputPDM

Looking at the datasheet, I can't find any mention of a 1.5 MHz clock speed limit. In fact, the specs on page 6 seem to say the clock range for standard mode is 1 to 3.3 MHz.

screenshot.png

This microphone really ought to just work if you use the audio library's PDM input feature.
 
Yes, I'd forgotten the mic spec. It had got itself mixed up in my head with a need to run this at the lowest speed I could manage. so when I used the pjrc block diagram too and I saw that the clock could be 2.82 or 1.41MHz, I just decided to use the lower speed - confident that the code would show what to change to use the lower speed.
 
TDK T3902 uses PDM format. It should work with the PDM input feature in the audio library.

https://www.pjrc.com/teensy/gui/?info=AudioInputPDM

Looking at the datasheet, I can't find any mention of a 1.5 MHz clock speed limit. In fact, the specs on page 6 seem to say the clock range for standard mode is 1 to 3.3 MHz.

View attachment 26116

This microphone really ought to just work if you use the audio library's PDM input feature.
Hello, I think I have a similar question. I am using Digital MEMS Mic SPH0641LU4H-1 (https://www.elecrow.com/digital-mems-microphone.html) to apply PdM in bearings. I am using Arduino Framework and, according to the datasheet of the microphone, it is capable of "hearing" a range between 100Hz to 80kHz. To make it operate in ultrasonic mode, I need to change the clock to 3.072 MHz ≤ fCLOCK ≤ 4.8 MHz. I have done this code, but the FFT is not detecting any frequencies, even in the first bins. Can you help me, please?

#include <Audio.h>
#include "setI2SFreq.h"
#define SAMPLE_RATE_192K 192000
// GUItool: begin automatically generated code
AudioInputPDM pdm1; //xy=180,111
AudioFilterStateVariable filter1; //xy=325,101
AudioOutputI2S i2s1; //I2S audio output
AudioAmplifier amp1; //xy=470,93
AudioAnalyzeFFT1024 fft1024_1; //xy=616,102
AudioConnection patchCord1(pdm1, 0, filter1, 0);
AudioConnection patchCord2(filter1, 2, amp1, 0);
AudioConnection patchCord3(amp1, fft1024_1);
// GUItool: end automatically generated code
void setup() {
AudioMemory(50);
filter1.frequency(30); // filter out DC & extremely low frequencies
amp1.gain(8.5); // amplify sign to useful range
setI2SFreq(192000);
}

void loop() {
if (fft1024_1.available()) {
// each time new FFT data is available
// print 20 bins to the Arduino Serial Monitor
//512 bins, 187.5 hz each bin
Serial.print(millis());
Serial.print("FFT: ");
for (int i = 0; i < 20; i++) {
float n = fft1024_1.read(i);
if (n >= 0.001) {
Serial.print(n, 3);
Serial.print(" ");
} else {
Serial.print(" -- "); // don't print "0.000"
}
}
Serial.println();
}
}
 
Status
Not open for further replies.
Back
Top