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

Improve PDM microphone reliability #33

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libraries/PDM/src/PDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ int PDMClass::begin(int channels, long sampleRate)
{
_channels = channels;

// Enable high frequency oscillator if not already enabled
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { }
}

// configure the sample rate and channels
switch (sampleRate) {
case 16000:
nrf_pdm_clock_set(NRF_PDM_FREQ_1032K);
NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio80 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk);
nrf_pdm_clock_set(NRF_PDM_FREQ_1280K);
break;
case 41667:
nrf_pdm_clock_set(NRF_PDM_FREQ_2667K);
Expand Down Expand Up @@ -128,6 +135,8 @@ void PDMClass::end()
pinMode(_pwrPin, INPUT);
}

// Don't disable high frequency oscillator since it could be in use by RADIO

// unconfigure the I/O and un-mux
nrf_pdm_psel_disconnect();

Expand Down