Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADC period 22us only supports 4 channels #441

Open
martinwork opened this issue Aug 19, 2024 · 3 comments
Open

ADC period 22us only supports 4 channels #441

martinwork opened this issue Aug 19, 2024 · 3 comments
Assignees
Milestone

Comments

@martinwork
Copy link
Collaborator

More than 3 analogue inputs, reduces mic rate

Try this in MakeCode live, then beta
https://makecode.microbit.org/_a277qf3sTHYs
https://makecode.microbit.org/_4q5L1eCcWFK9 (for import to beta with the pin blocks fixed)
Press A to record – see recording time in console
Press B to add 4 analogue inputs
Press A to record – see increased recording time in beta

@martinwork
Copy link
Collaborator Author

Similar C++ example: recording.zip

The hex in the zip has
DMESG("possibleSamples %d", possibleSamples);

inserted at
https://github.com/lancaster-university/codal-nrf52/blob/8802eb49140e0389e535cb6160d9080efd951ba7/source/NRF52ADC.cpp#L559

@martinwork
Copy link
Collaborator Author

The NRF52ADC period used to be set in MicroBit.cpp to 91us (note: 1e6/11000 == 90.9), but has been changed by MicroBitAudio to 45 (1e6/22000), then 90 (1e6/11000) and now 22 (1e6/44100).

The last change says "back up to 44100" but that number has not been used to set the NRF52ADC rate before, as far as I can see. Perhaps that referred to the Mixer2 output channel speed.

It looks like MicroBitAudio is turning the NRF52ADC speed dial up to 11 out of 10, even for programs that don't use the microphone. I don't think a MakeCode program can reduce the NRF52ADC rate.


History... Originally, the default NRF52ADC period was set to 91us

adc(adcTimer, 91),

MicroBitAudio started setting the default ADC period to 1e6/22000 (45) in 98d7dc9

MicroBitAudio was changed to set 1e6/11000 (90) in ceba6d7

Macro CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE == 11000 was added after issue #311 in d54ce9b

Finally, CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE was increased to 44100 in 2e664e6


Trying to understand CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE... It is

  • the default rate for a Mixer2 output channel
  • the default NRF52ADC sample rate

https://github.com/search?q=repo%3Alancaster-university%2Fcodal-microbit-v2%20CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE&type=code

These two things don't seem logically closely connected.

I'm not sure why MicroBitAudio needs to set the NRF52ADC rate in its constructor.

Does LevelDetectorSPL need the same high rate as sound recording?
Won't the NRF52ADC rate get increased if a faster rate is requested?
Isn't it the input and output rates for a StreamRecording that need to match for #311?

    SplitterChannel *splitterChannel = uBit.audio.splitter->createChannel();
    splitterChannel->requestSampleRate( SAMPLE_RATE );
    StreamRecording *recording = new StreamRecording(*splitterChannel, BUFFER_LEN);

Could the mic input pipeline be created on first use?

//Initilise input splitter

@martinwork
Copy link
Collaborator Author

Sound level is more noisy at 22us / 44100Hz.
When it’s quiet, MakeCode v6 sees lots of zeros, but v7 has a very jumpy graph.
https://makecode.microbit.org/_MDw9Tafqu9k3

C++
#include "MicroBit.h"

MicroBit uBit;

void forever()
{
    while (true)
    {
        int level = uBit.audio.levelSPL->getValue();

        uBit.serial.printf( "s:%d\r\n", (int) level);
        uBit.sleep(20);
    }
}

int main()
{
    uBit.init();
    //uBit.audio.activateMic();
    create_fiber( forever);
    release_fiber();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants