nRF Connect SDK - SAADC example (non blocking internal timer) - note on the sample app

Dear all,

just some note upon this sample.

Using VS Code and copying sample app just not work due to some error into the path, missing file so I've try to adjust to get all working, here enclosed the zip file of the project.

I've build it for a nRF52840 DK, with toolchain v2.7.0 and SDK v2.7.0, just do some little reformatting of the files, created the /src folder and put inside the main.c source file, then inside the /src folder created the /common folder where the other file resides.

Due to errors in missing files during the building stage I've figured that you have to copy the saadc_example_common.c and saadc_example_common.h from the ncs samples folder, in my default installation these files are at the following path:

C:\ncs\v2.7.0\modules\hal\nordic\nrfx\samples\src\nrfx_saadc\common

Next I've to change accordling the CMakeLists.txt file to point to the new folder structures and files that has to be included into the main.c source file. Here below a shot of the running project after flashing it into the nRF52840 DK board (my version was 3.0.0).

Here the whole modified project for your reference.

advanced_non_blocking_internal_timer.zip

Hope can help.

Let me know about some imprecision or change to do because I'm just starting with the nRF Connect SDK.

Best regards.

Fabio

  • Hi,

     

    There are some incompatibilities with the cmake macros when building with sysbuild.

    For now, I would recommend that you build without sysbuild, like shown here:

     

    Could you try this and see if it works now?

     

    Kind regards,

    Håkon

  • Dear Alseth,

    thanks for your reply!

    Using the settings below, as I did into my first post, I was able to get the sample design properly working.

    I've also tested the building without sysbuild as your request (with the project changes listed in my post not with the original CMakeLists.txt files) and seems also working properly.

    *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
    *** Using Zephyr OS v3.6.99-100befc70c74 ***
    [00:00:00.365,325] <inf> NRFX_EXAMPLE: Starting nrfx_saadc advanced non-blocking sampling with internal timer example.
    [00:00:00.385,375] <inf> NRFX_EXAMPLE: GPIOTE status: initialized
    [00:00:00.385,467] <inf> NRFX_EXAMPLE: SAADC event: CALIBRATEDONE
    [00:00:00.385,498] <inf> NRFX_EXAMPLE: SAADC event: READY
    [00:00:00.385,528] <inf> NRFX_EXAMPLE: SAADC event: BUF_REQ
    [00:00:00.385,772] <inf> NRFX_EXAMPLE: SAADC event: DONE
    [00:00:00.385,803] <inf> NRFX_EXAMPLE: Sample buffer address == 0x20001126
    [00:00:00.385,803] <inf> NRFX_EXAMPLE: [Sample 0] value == 41
    [00:00:00.385,803] <inf> NRFX_EXAMPLE: [Sample 1] value == 54
    [00:00:00.385,833] <inf> NRFX_EXAMPLE: [Sample 2] value == 41
    [00:00:00.385,833] <inf> NRFX_EXAMPLE: SAADC event: BUF_REQ
    [00:00:00.386,138] <inf> NRFX_EXAMPLE: SAADC event: DONE
    [00:00:00.386,169] <inf> NRFX_EXAMPLE: Sample buffer address == 0x2000112c
    [00:00:00.386,169] <inf> NRFX_EXAMPLE: [Sample 0] value == 57
    [00:00:00.386,199] <inf> NRFX_EXAMPLE: [Sample 1] value == 47
    [00:00:00.386,199] <inf> NRFX_EXAMPLE: [Sample 2] value == 61
    [00:00:00.386,230] <inf> NRFX_EXAMPLE: SAADC event: BUF_REQ
    [00:00:00.386,505] <inf> NRFX_EXAMPLE: SAADC event: DONE
    [00:00:00.386,535] <inf> NRFX_EXAMPLE: Sample buffer address == 0x20001126
    [00:00:00.386,535] <inf> NRFX_EXAMPLE: [Sample 0] value == 51
    [00:00:00.386,566] <inf> NRFX_EXAMPLE: [Sample 1] value == 66
    [00:00:00.386,566] <inf> NRFX_EXAMPLE: [Sample 2] value == 54
    [00:00:00.386,596] <inf> NRFX_EXAMPLE: SAADC event: BUF_REQ
    [00:00:00.386,901] <inf> NRFX_EXAMPLE: SAADC event: DONE
    [00:00:00.386,901] <inf> NRFX_EXAMPLE: Sample buffer address == 0x2000112c
    [00:00:00.386,901] <inf> NRFX_EXAMPLE: [Sample 0] value == 67
    [00:00:00.386,932] <inf> NRFX_EXAMPLE: [Sample 1] value == 58
    [00:00:00.386,932] <inf> NRFX_EXAMPLE: [Sample 2] value == 71
    [00:00:00.386,962] <inf> NRFX_EXAMPLE: SAADC event: FINISHED

    I kindly ask you if you can help me to modify this sample design in order to achieve these two goal:

    - configure the SAADC to sample two external analog input and also sample the internal VBAT;

    - setup the SAADC able to work with the Timer2 and 200Hz of sample frequency because I need to get samples at exactly 5ms of time.

    Coud you please point me how to do that?

    Thanks and best regards!

    F.

  • Hi,

     

    STE said:

    - configure the SAADC to sample two external analog input and also sample the internal VBAT;

    Then you need to assign one of the channels to "NRF_SAADC_INPUT_VDD".

    The default configuration when using macro "SAADC_CHANNEL_SE_ACQ_3US" is to use the internal 0.6V reference, so your VDD input voltage will scale towards this set reference.

    STE said:
    - setup the SAADC able to work with the Timer2 and 200Hz of sample frequency because I need to get samples at exactly 5ms of time.

    You can have a look at one of the nrfx_timer samples on how to setup a 200 Hz (5ms) timer, and combine that with one of the saadc-samples that matches your use-case the best.

     

    Kind regards,

    Håkon

Related