<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63067/nrfx_saadc-advanced-mode-oversampling</link><description>Hi all, 
 
 I am currently developing audio sampling on a custom board using the nrf52832. I&amp;#39;d like to sample at 20khz and am using the nrfxlib driver for this ( https://github.com/zephyrproject-rtos/hal_nordic/blob/master/nrfx/drivers/include/nrfx_saadc</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 Nov 2021 10:43:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63067/nrfx_saadc-advanced-mode-oversampling" /><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/338347?ContentTypeID=1</link><pubDate>Wed, 10 Nov 2021 10:43:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc397d03-f364-4c2a-b028-c4cf140c3e7d</guid><dc:creator>picatostas</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;I have been using the example &lt;a href="https://github.com/NordicSemiconductor/nrfx/wiki/SAADC-Advanced-mode-with-IRQs"&gt;https://github.com/NordicSemiconductor/nrfx/wiki/SAADC-Advanced-mode-with-IRQs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;but I am struggling t get it working when I want to stop and continue the conversion at some point.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;my init funcition is the same, with some difference based on my application, 500 samples instead of 1000 and my sampling freq is 10kHz:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void adc_init(void) {
    ret_code_t err_code;
    nrfx_saadc_channel_t tuner_ch   = NRFX_SAADC_DEFAULT_CHANNEL_SE(GUITAR_IN_ADC_CH, 0);
    nrfx_saadc_adv_config_t adc_cfg = {
        .oversampling      = NRF_SAADC_OVERSAMPLE_DISABLED, // Disable oversample.
        .burst             = false,                         // Disable burst.
        .internal_timer_cc = 16000000UL/ADC_SAMPLE_RATE,    // Sample at 10kHz.
        .start_on_end      = false,                         // Latch next buffer at END event in interrupt.
    };
    err_code = nrfx_saadc_init(NRFX_SAADC_CONFIG_IRQ_PRIORITY);
    APP_ERROR_CHECK(err_code);
    err_code = nrfx_saadc_channels_config(&amp;amp;tuner_ch, 1);
    APP_ERROR_CHECK(err_code);
    err_code = nrfx_saadc_advanced_mode_set((1&amp;lt;&amp;lt;0), NRF_SAADC_RESOLUTION_10BIT, &amp;amp;adc_cfg, adc_evt_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrfx_saadc_buffer_set(adc_buf[buf_to_load % 2], SAMPLES_NUMBER);
    APP_ERROR_CHECK(err_code);
    buf_to_load++;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and whenever I want to get a set of samples i do:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;my event handler looks like this, I modified it a bit for the sake of my application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void adc_evt_handler(nrfx_saadc_evt_t const * p_event) {
    switch (p_event-&amp;gt;type) {
        case NRFX_SAADC_EVT_DONE: {
            // Buffer with data is available here: p_event-&amp;gt;data.done.p_buffer
            adc_samples = p_event-&amp;gt;data.done.size;
            for (uint32_t i = 0; i &amp;lt; adc_samples; i++) {
                guitar_samples[i] = p_event-&amp;gt;data.done.p_buffer[i];
            }
            eventq_add(EVENT_TUNER_ADC_READY, 0, NULL);
        }
        break;
        case NRFX_SAADC_EVT_BUF_REQ:
            nrfx_saadc_buffer_set(adc_buf[buf_to_load % 2], SAMPLES_NUMBER);
            buf_to_load++;
            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The first time I get the samples correctly. From what I understand since I configured the adc&lt;/p&gt;
&lt;p&gt;with :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        .start_on_end      = false,                         // Latch next buffer at END event in interrupt.
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Once the event :&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;NRFX_SAADC_EVT_DONE &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;is published ADC block wont convert anymore.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;If call again
&lt;div style="background-color:#16171d;color:#f8f8f0;font-family:&amp;#39;Droid Sans Mono&amp;#39;, &amp;#39;monospace&amp;#39;, monospace, &amp;#39;Droid Sans Fallback&amp;#39;;font-size:11.4px;font-weight:normal;line-height:15px;white-space:pre;"&gt;
&lt;div&gt;
&lt;div style="background-color:#16171d;color:#f8f8f0;font-family:&amp;#39;Droid Sans Mono&amp;#39;, &amp;#39;monospace&amp;#39;, monospace, &amp;#39;Droid Sans Fallback&amp;#39;;font-size:11.4px;font-weight:normal;line-height:15px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#f8f8f0;"&gt; &lt;/span&gt;&lt;span style="color:#19d1e5;"&gt;ret_code_t&lt;/span&gt;&lt;span style="color:#f8f8f0;"&gt; err_code &lt;/span&gt;&lt;span style="color:#ff3f4f;"&gt;=&lt;/span&gt;&lt;span style="color:#f8f8f0;"&gt; &lt;/span&gt;&lt;span style="color:#81f900;"&gt;nrfx_saadc_mode_trigger&lt;/span&gt;&lt;span style="color:#f8f8f0;"&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#f8f8f0;"&gt; &lt;/span&gt;&lt;span style="color:#81f900;"&gt;APP_ERROR_CHECK&lt;/span&gt;&lt;span style="color:#f8f8f0;"&gt;(err_code);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;error_code is 8.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;What is the proper way of utilizing the adc to start stop samples on demand without having the ADC running non_stop ?&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/338261?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 21:15:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eadf6c4-d1ed-4655-9d21-0ecda27a099b</guid><dc:creator>picatostas</dc:creator><description>&lt;p&gt;The mentioned example worked for me, thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/266734?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 12:25:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6842555b-6354-411e-9a59-01cc1311fa63</guid><dc:creator>mafi</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;I have been using the double buffering implementation quite succesfull, however, I am now trying to run the ISR on a lower priority level since it is conflicting with some other system interrupts (radio).&lt;/p&gt;
&lt;p&gt;Whenever I lower the priority my initial problem is popping up again: weird outliers. Do you have any idea what&amp;#39;s the cause?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Mattia&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/258634?ContentTypeID=1</link><pubDate>Mon, 06 Jul 2020 14:21:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62c9739f-fb7b-4ae3-b675-6fade7779548</guid><dc:creator>mafi</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Many thanks for your answer, I could not find any example code. I have not yet tried this but I am certain this will resolve my question, I have verified your answer.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Mattia&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/257862?ContentTypeID=1</link><pubDate>Wed, 01 Jul 2020 13:29:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a775d5e2-5026-4e1e-82e5-feb5142f05db</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Mattia,&lt;/p&gt;
&lt;p&gt;I am sorry for the late reply.&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t realize the saadc drivers from NCS were so different from the nRF5 SDK drivers.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you look at the advanced mode example implementation found &lt;a href="https://github.com/NordicSemiconductor/nrfx/wiki/nrfx-1.8.1-to-2.0.0#saadc-1" rel="noopener noreferrer" target="_blank"&gt;here&lt;/a&gt;, you can see that there are some differences in the event handler. Look at how they handle the p_event-&amp;gt;data.done.p_buffer[].&lt;/p&gt;
&lt;p&gt;Also, they don&amp;#39;t set the buffer in NRFX_SAADC_EVT_DONE, but in the NRFX_SAADC_EVT_BUF_REQ event.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;They also use the double buffer. sample0 and sample1, both containing SAMPLES_NUMBER (1000) elements.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What does your saadc configuration look like?&lt;/p&gt;
&lt;p&gt;nrfx_saadc_adv_config_t config = ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I suggest you try to use double buffering, like it is done in the example from the link. You don&amp;#39;t need to for-loop in the event handler. It can be done elsewhere to free up the buffer (in case you are working on your buffer, and another ADC_DONE event occurs before you are done.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/257177?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 14:38:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2620f0b7-5610-4ba6-9c2f-ade0915c1b46</guid><dc:creator>mafi</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thank you for the response I will try with proper double buffers I think here lies the problem.&lt;/p&gt;
&lt;p&gt;Regarding the implementation that I&amp;#39;m using: it is a fork of the official HAL from Nordic here &lt;a href="https://github.com/NordicSemiconductor/nrfx/tree/v2.2.0"&gt;https://github.com/NordicSemiconductor/nrfx/tree/v2.2.0&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;This HAL does not have the function nrf_drv_saadc_buffer_convert, which is why I&amp;#39;m using the buffer_init inside my IRQ in stead.&lt;/p&gt;
&lt;p&gt;Is this then the correct approach? Or what should I replace nrf_drv_saadc_buffer_convert with based on this HAL?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Mattia&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/257171?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 14:11:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23d120ee-80dc-4c7f-942c-f12f01324f62</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you compare your implementation with the saadc from the &lt;a href="https://www.nordicsemi.com/Software-and-tools/Software/nRF5-SDK/Download#infotabs" rel="noopener noreferrer" target="_blank"&gt;nRF5 SDK&lt;/a&gt; example:&lt;/p&gt;
&lt;p&gt;SDK\examples\peripheral\saadc\&lt;/p&gt;
&lt;p&gt;which uses a double buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In fact, I think you should take a look at this example. I don&amp;#39;t understand why you use nrf_drv_saadc_buffer_convert() in your NRFX_SAADC_EVT_DONE event. What you should use is nrf_drv_saadc_buffer_convert().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you find this implementation somewhere? I am sorry if that is a stupid question. I have not worked much with NCS (the zephyr SDK) yet. Check out the implementation in the saadc example from the nRF5 SDK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Even though your implementation is working, it may be that when you set the single buffer in each interrupts, it may act a bit weird if it doesn&amp;#39;t have time to do this on time (perhaps it is blocked by a BLE event some times?). The values that you say that you see sometimes looks like multiples of ~3785&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try to use the double buffers, and use nrf_drv_saadc_buffer_convert() in the interrupt, and see if it still glitches like this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfx_saadc advanced mode oversampling</title><link>https://devzone.nordicsemi.com/thread/257096?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 10:40:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b7df3b7-6ced-4ee9-8052-fb7d795525a9</guid><dc:creator>mafi</dc:creator><description>&lt;p&gt;Sample data that I get:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;3788
3782
3785
3786
3783
3782
3781
15112
3782
3777
3779
3783
3782
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With an internal ADC reference and 1/6 Gain, the DC offset is approx 0.81Volt, however, the outlier of 15112 I can&amp;#39;t explain as this would mean a peak of 3.5 Volt which is highly unlikely.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>