Restarting NRFX SAADC measurement in "maximum performance" mode

Hi!

I liked the "maximum performance" example because it is driven by a timer and the measurements are on absolutely regular basis:

https://github.com/zephyrproject-rtos/hal_nordic/blob/master/nrfx/samples/src/nrfx_saadc/maximum_performance/main.c

So, I configured it (below is what I've changed compared to the example's original code) and run it (results are below).

My question is - how can I easily re-trigger new burst of measurements from the while loop?

I'm sampling at 50kHz, ADC is done, buffers are full, process the buffer and then I want in the main while loop (on a regular basis - after a pause of e.g. 10 seconds) to trigger a new measurement burst.

I tried as below by 'nrfx_gppi_channels_enable(NRFX_BIT(m_gppi_channels[SAADC_START_ON_END]));' but it does not trigger a new burst...

/** @brief Symbol specifying maximal possible SAADC sample rate (see SAADC electrical specification). */
#define MAX_SAADC_SAMPLE_FREQUENCY 50000UL

/**
 * @brief Symbol specifying the number of sample buffers ( @ref m_sample_buffers ).
 *        Two buffers are required for performing double-buffered conversions.
 */
#define BUFFER_COUNT 2UL

/** @brief Symbol specifying the size of singular sample buffer ( @ref m_sample_buffers ). */
#define BUFFER_SIZE 20UL

/** @brief Symbol specifying the number of SAADC samplings to trigger. */
#define SAMPLING_ITERATIONS 1UL // was 3UL

int main(void)
{
    // ...
    k_sleep(K_MSEC(1000));
    
    for (;;) {
		k_sleep(K_MSEC(10000));
		
		// NB - unfortunately this does NOT trigger a new measurement iteration:
		nrfx_gppi_channels_enable(NRFX_BIT(m_gppi_channels[SAADC_START_ON_END]));

		//... do my Bluetooth and application stuff
		printk(".\n");
	}
}

13:16:29:042 -> *** Booting Zephyr OS build v3.2.99-ncs2 ***
13:16:30:050 -> SAADC event: CALIBRATEDONE
13:16:30:052 -> SAADC event: READY
13:16:30:054 -> SAADC event: BUF_REQ
13:16:30:056 -> SAADC event: DONE
13:16:30:058 -> Sample buffer address == 0x200099d6
13:16:30:061 -> [Sample 0] value == 13748
13:16:30:063 -> [Sample 1] value == 13768
13:16:30:066 -> [Sample 2] value == 13776
13:16:30:068 -> [Sample 3] value == 13768
13:16:30:070 -> [Sample 4] value == 13740
13:16:30:073 -> [Sample 5] value == 13752
13:16:30:075 -> [Sample 6] value == 13760
13:16:30:077 -> [Sample 7] value == 13784
13:16:30:080 -> [Sample 8] value == 13776
13:16:30:082 -> [Sample 9] value == 13772
13:16:30:084 -> [Sample 10] value == 13772
13:16:30:087 -> [Sample 11] value == 13740
13:16:30:089 -> [Sample 12] value == 13780
13:16:30:092 -> [Sample 13] value == 13800
13:16:30:094 -> [Sample 14] value == 13768
13:16:30:097 -> [Sample 15] value == 13776
13:16:30:099 -> [Sample 16] value == 13756
13:16:30:101 -> [Sample 17] value == 13760
13:16:30:104 -> [Sample 18] value == 13756
13:16:30:106 -> [Sample 19] value == 13772
13:16:30:109 -> FINISHED
13:16:40:112 -> .
13:16:50:114 -> .
13:17:00:115 -> .
13:17:10:116 -> .

Parents Reply Children
  • Hi Jørgen, thanks for your help! As you suggested I have added nrfx_saadc_buffer_set() and used nrfx_saadc_mode_trigger() to retrigger the SAADC in the while loop as below.

    So, as it is visible below, my code now works as I want. Again - thank you!

    /** @brief Symbol specifying maximal possible SAADC sample rate (see SAADC electrical specification). */
    #define MAX_SAADC_SAMPLE_FREQUENCY 50000UL
    
    /**
     * @brief Symbol specifying the number of sample buffers ( @ref m_sample_buffers ).
     *        Two buffers are required for performing double-buffered conversions.
     */
    #define BUFFER_COUNT 2UL
    
    /** @brief Symbol specifying the size of singular sample buffer ( @ref m_sample_buffers ). */
    #define BUFFER_SIZE 20UL
    
    /** @brief Symbol specifying the number of SAADC samplings to trigger. */
    #define SAMPLING_ITERATIONS 1UL // was 3UL
    
    int main(void)
    {
        // ...
        k_sleep(K_MSEC(1000));
        
        for (;;) {
    		k_sleep(K_MSEC(1000));
    		
    		status = nrfx_saadc_buffer_set(m_sample_buffers[0], BUFFER_SIZE);
    		NRFX_ASSERT(status == NRFX_SUCCESS);
    
    		status = nrfx_saadc_mode_trigger();
    		NRFX_ASSERT(status == NRFX_SUCCESS);
    
    		//... do my Bluetooth and application stuff
    		printk(".\n");
    	}
    }

    17:25:27:085 -> SAADC event: CALIBRATEDONE
    17:25:27:087 -> SAADC event: READY
    17:25:27:089 -> SAADC event: BUF_REQ
    17:25:27:091 -> SAADC event: DONE
    17:25:27:093 -> Sample buffer address == 0x200099d6
    17:25:27:096 -> [Sample 0] value == 13740
    17:25:27:098 -> [Sample 1] value == 13736
    17:25:27:101 -> [Sample 2] value == 13752
    17:25:27:103 -> [Sample 3] value == 13760
    17:25:27:105 -> [Sample 4] value == 13736
    17:25:27:108 -> [Sample 5] value == 13720
    17:25:27:110 -> [Sample 6] value == 13732
    17:25:27:112 -> [Sample 7] value == 13764
    17:25:27:115 -> [Sample 8] value == 13736
    17:25:27:117 -> [Sample 9] value == 13724
    17:25:27:119 -> [Sample 10] value == 13752
    17:25:27:122 -> [Sample 11] value == 13720
    17:25:27:124 -> [Sample 12] value == 13732
    17:25:27:127 -> [Sample 13] value == 13724
    17:25:27:129 -> [Sample 14] value == 13760
    17:25:27:132 -> [Sample 15] value == 13748
    17:25:27:134 -> [Sample 16] value == 13760
    17:25:27:137 -> [Sample 17] value == 13760
    17:25:27:139 -> [Sample 18] value == 13716
    17:25:27:141 -> [Sample 19] value == 13752
    17:25:27:144 -> FINISHED
    17:25:28:172 -> SAADC event: READY
    17:25:28:173 -> SAADC event: BUF_REQ
    17:25:28:175 -> SAADC event: DONE
    17:25:28:177 -> Sample buffer address == 0x200099d6
    17:25:28:180 -> [Sample 0] value == 13756
    17:25:28:182 -> [Sample 1] value == 13740
    17:25:28:185 -> [Sample 2] value == 13724
    17:25:28:187 -> [Sample 3] value == 13736
    17:25:28:189 -> [Sample 4] value == 13744
    17:25:28:192 -> [Sample 5] value == 13724
    17:25:28:194 -> [Sample 6] value == 13724
    17:25:28:196 -> [Sample 7] value == 13740
    17:25:28:199 -> [Sample 8] value == 13732
    17:25:28:201 -> [Sample 9] value == 13740
    17:25:28:203 -> [Sample 10] value == 13732
    17:25:28:206 -> [Sample 11] value == 13760
    17:25:28:208 -> [Sample 12] value == 13724
    17:25:28:211 -> [Sample 13] value == 13740
    17:25:28:213 -> [Sample 14] value == 13716
    17:25:28:216 -> [Sample 15] value == 13760
    17:25:28:218 -> [Sample 16] value == 13780
    17:25:28:221 -> [Sample 17] value == 13792
    17:25:28:223 -> [Sample 18] value == 13752
    17:25:28:225 -> [Sample 19] value == 13724
    17:25:28:228 -> FINISHED
    17:25:28:230 -> .
    17:25:29:230 -> SAADC event: READY
    17:25:29:232 -> SAADC event: BUF_REQ
    17:25:29:234 -> SAADC event: DONE
    17:25:29:235 -> Sample buffer address == 0x200099d6
    17:25:29:239 -> [Sample 0] value == 13760
    17:25:29:241 -> [Sample 1] value == 13772
    17:25:29:243 -> [Sample 2] value == 13764
    17:25:29:246 -> [Sample 3] value == 13764
    17:25:29:248 -> [Sample 4] value == 13744
    17:25:29:250 -> [Sample 5] value == 13756
    17:25:29:253 -> [Sample 6] value == 13724
    17:25:29:255 -> [Sample 7] value == 13708
    17:25:29:257 -> [Sample 8] value == 13728
    17:25:29:260 -> [Sample 9] value == 13724
    17:25:29:262 -> [Sample 10] value == 13756
    17:25:29:264 -> [Sample 11] value == 13792
    17:25:29:267 -> [Sample 12] value == 13720
    17:25:29:269 -> [Sample 13] value == 13800
    17:25:29:272 -> [Sample 14] value == 13740
    17:25:29:274 -> [Sample 15] value == 13724
    17:25:29:277 -> [Sample 16] value == 13744
    17:25:29:279 -> [Sample 17] value == 13752
    17:25:29:281 -> [Sample 18] value == 13716
    17:25:29:284 -> [Sample 19] value == 13764
    17:25:29:286 -> FINISHED
    17:25:29:288 -> .
    17:25:30:289 -> SAADC event: READY
    17:25:30:290 -> SAADC event: BUF_REQ
    17:25:30:292 -> SAADC event: DONE
    17:25:30:294 -> Sample buffer address == 0x200099d6
    17:25:30:297 -> [Sample 0] value == 13764
    17:25:30:299 -> [Sample 1] value == 13740
    17:25:30:302 -> [Sample 2] value == 13724
    17:25:30:304 -> [Sample 3] value == 13776
    17:25:30:306 -> [Sample 4] value == 13724
    17:25:30:309 -> [Sample 5] value == 13760
    17:25:30:311 -> [Sample 6] value == 13756
    17:25:30:313 -> [Sample 7] value == 13736
    17:25:30:316 -> [Sample 8] value == 13748
    17:25:30:318 -> [Sample 9] value == 13752
    17:25:30:320 -> [Sample 10] value == 13736
    17:25:30:323 -> [Sample 11] value == 13736
    17:25:30:325 -> [Sample 12] value == 13744
    17:25:30:328 -> [Sample 13] value == 13752
    17:25:30:330 -> [Sample 14] value == 13732
    17:25:30:333 -> [Sample 15] value == 13760
    17:25:30:335 -> [Sample 16] value == 13748
    17:25:30:338 -> [Sample 17] value == 13748
    17:25:30:340 -> [Sample 18] value == 13764
    17:25:30:342 -> [Sample 19] value == 13736
    17:25:30:345 -> FINISHED
    17:25:30:347 -> .

Related