Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit a5bce2f

Browse files
authored
Merge pull request #33 from arduino/pdm_mic_in_specs
Improve PDM microphone reliability
2 parents 67ef327 + 545c4c5 commit a5bce2f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libraries/PDM/src/PDM.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ int PDMClass::begin(int channels, long sampleRate)
4848
{
4949
_channels = channels;
5050

51+
// Enable high frequency oscillator if not already enabled
52+
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
53+
NRF_CLOCK->TASKS_HFCLKSTART = 1;
54+
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { }
55+
}
56+
5157
// configure the sample rate and channels
5258
switch (sampleRate) {
5359
case 16000:
54-
nrf_pdm_clock_set(NRF_PDM_FREQ_1032K);
60+
NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio80 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk);
61+
nrf_pdm_clock_set(NRF_PDM_FREQ_1280K);
5562
break;
5663
case 41667:
5764
nrf_pdm_clock_set(NRF_PDM_FREQ_2667K);
@@ -128,6 +135,8 @@ void PDMClass::end()
128135
pinMode(_pwrPin, INPUT);
129136
}
130137

138+
// Don't disable high frequency oscillator since it could be in use by RADIO
139+
131140
// unconfigure the I/O and un-mux
132141
nrf_pdm_psel_disconnect();
133142

0 commit comments

Comments
 (0)