<?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>Timer/SAADC/(D)PPI differences between nRF52840 &amp;amp; nRF5340</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86324/timer-saadc-d-ppi-differences-between-nrf52840-nrf5340</link><description>Hi team ! 
 
 I&amp;#39;m facing issue when porting my code from nRF52840DK to nRF5340DK 
 I implemented SAADC acquisition, using Timer/SAADC/(D)PPI stack on both boards, handling the few differences I found (i.e: nrfx_ppi_channel... vs nrfx_dppi_channel... functions</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Feb 2023 16:10:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86324/timer-saadc-d-ppi-differences-between-nrf52840-nrf5340" /><item><title>RE: Timer/SAADC/(D)PPI differences between nRF52840 &amp; nRF5340</title><link>https://devzone.nordicsemi.com/thread/412339?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 16:10:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a1ec1ec-a2de-4a63-a70a-66139dac57e7</guid><dc:creator>Talkamynn</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;J&amp;oslash;rgen,&lt;/p&gt;
&lt;p&gt;I found out this old ticket, that we can close.&lt;br /&gt;I add to re implement my function and now it&amp;#39;s OK for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer/SAADC/(D)PPI differences between nRF52840 &amp; nRF5340</title><link>https://devzone.nordicsemi.com/thread/360866?ContentTypeID=1</link><pubDate>Wed, 30 Mar 2022 14:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0fc6bad-589e-49f2-b893-f3710a06684c</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I can&amp;#39;t see any obvious issues that should be causing this in the code.&lt;/p&gt;
&lt;p&gt;Can you read out and post the SAADC, TIMER1 and (D)PPI registers using a debugger after the initialization part of the code is done, on both devices, to see if there is any differences in the actual configuration?&lt;/p&gt;
&lt;p&gt;Do you have a minimal sample, with the code you have posted, that we can use to reproduce/debug this issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer/SAADC/(D)PPI differences between nRF52840 &amp; nRF5340</title><link>https://devzone.nordicsemi.com/thread/360496?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 09:50:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca7a7144-6df9-4863-847a-8c0e79144d31</guid><dc:creator>Talkamynn</dc:creator><description>&lt;p&gt;And here is the function to configure ppi.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ppi_init(void)
{
    nrfx_err_t err;
    nrf_timer_event_t evt_compare[4] = {
        NRF_TIMER_EVENT_COMPARE0,
        NRF_TIMER_EVENT_COMPARE1,
        NRF_TIMER_EVENT_COMPARE2,
        NRF_TIMER_EVENT_COMPARE3
    };

#if defined(DPPI_PRESENT)

	uint8_t m_timer_saadc_ppi_channel[4];

    for (int i = 0; i &amp;lt; 4; i++) {
    	err = nrfx_dppi_channel_alloc(&amp;amp;m_timer_saadc_ppi_channel[i]);
        if (err != NRFX_SUCCESS) {
            printk(&amp;quot;SAADC (D)PPI channel allocation error: %08x\n&amp;quot;, err);
            return;
        }
    }
#else
	uint8_t m_timer_saadc_ppi_channel[4];

    for (int i = 0; i &amp;lt; 4; i++) {
    	err = nrfx_ppi_channel_alloc(&amp;amp;m_timer_saadc_ppi_channel[i]);
        if (err != NRFX_SUCCESS) {
            printk(&amp;quot;SAADC (D)PPI channel allocation error: %08x\n&amp;quot;, err);
            return;
        }
    }
#endif

    for (int i = 0; i &amp;lt; 4; i++) {
        nrfx_gppi_channel_endpoints_setup(m_timer_saadc_ppi_channel[i],
            nrfx_timer_event_address_get(&amp;amp;m_sample_timer, evt_compare[i]),
            nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));
    }
    
	/* Enable (D)PPI channel. */
#if defined(DPPI_PRESENT)
    for (int i = 0; i &amp;lt; 4; i++) {
    	err = nrfx_dppi_channel_enable(m_timer_saadc_ppi_channel[i]);
        if (err != NRFX_SUCCESS) {
            printk(&amp;quot;Failed to enable SAADC (D)PPI channel, error: %08x&amp;quot;, err);
            return;
        }
    }
#else
    for (int i = 0; i &amp;lt; 4; i++) {
    	err = nrfx_ppi_channel_enable(m_timer_saadc_ppi_channel[i]);
        if (err != NRFX_SUCCESS) {
            printk(&amp;quot;Failed to enable SAADC (D)PPI channel, error: %08x&amp;quot;, err);
            return;
        }
    }
#endif
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then, I finally use this in my program&amp;#39;s main loop.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void main(void)
{
    [...]
    while(1) {
        time_start_sampling = k_uptime_get();
	    k_msgq_get(getADCQueue(), &amp;amp;adc_buffer, K_FOREVER);
	    time_end_sampling = k_uptime_get();
    	memcpy(buffer, adc_buffer, sizeof(adc_buffer));
    [...]
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer/SAADC/(D)PPI differences between nRF52840 &amp; nRF5340</title><link>https://devzone.nordicsemi.com/thread/360492?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 09:38:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f478eee1-0bfd-413c-9df5-41a31191a6bf</guid><dc:creator>Talkamynn</dc:creator><description>&lt;p&gt;Hi J&amp;oslash;rgen,&lt;br /&gt;&lt;br /&gt;Thanks for your answer.&lt;/p&gt;
&lt;p&gt;Here is the function I use to configure ADC, and there is no conditional settings depending on the board, beside calling nrfx_ppi or nrfx_dppi functions.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#define ADC_CHANNELS_IN_USE     1
#define SAADC_BUF_SIZE          ADC_CHANNELS_IN_USE * 25 * 4
#define SAADC_BUF_COUNT         2

bool adc_configure(void)
{
    nrfx_err_t err_code;
    nrf_saadc_value_t adc_samples[SAADC_BUF_COUNT][SAADC_BUF_SIZE];

    nrfx_saadc_adv_config_t saadc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
    saadc_adv_config.internal_timer_cc = 0;
    saadc_adv_config.start_on_end = true;
    saadc_adv_config.oversampling = NRF_SAADC_OVERSAMPLE_32X;
    saadc_adv_config.burst = NRF_SAADC_BURST_ENABLED;

    err_code = nrfx_saadc_init(NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY);
    printk(&amp;quot; * nrfx_saadc_init error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }

    static nrfx_saadc_channel_t channel_configs[ADC_CHANNELS_IN_USE];

    uint8_t channel_mask = 0;
    //nrfx_saadc_channel_t config = NRFX_SAADC_DEFAULT_CHANNEL_DIFFERENTIAL(
    //                                    NRF_SAADC_INPUT_AIN2, NRF_SAADC_INPUT_AIN3, 0);
    nrfx_saadc_channel_t config = NRFX_SAADC_DEFAULT_CHANNEL_SE(
                                        NRF_SAADC_INPUT_AIN1, 0);
    config.channel_config.reference = NRF_SAADC_REFERENCE_VDD4;          
    config.channel_config.gain = NRF_SAADC_GAIN1;

    // Copy to list of channel configs
    memcpy(&amp;amp;channel_configs[0], &amp;amp;config, sizeof(config));

    // Update channel mask
    channel_mask |= 1 &amp;lt;&amp;lt; 0;

    err_code = nrfx_saadc_channels_config(channel_configs, ADC_CHANNELS_IN_USE);
    printk(&amp;quot; * nrfx_saadc_channels_config error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }
    err_code = nrfx_saadc_advanced_mode_set(channel_mask,
                                            NRF_SAADC_RESOLUTION_14BIT,
                                            &amp;amp;saadc_adv_config,
                                            &amp;amp;adc_event_handler);
    printk(&amp;quot; * nrfx_saadc_advanced_mode_set error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }
    
    // Configure two buffers to ensure double buffering of adc_samples,
    // to avoid data loss when the sampling frequency is high
    err_code = nrfx_saadc_buffer_set(&amp;amp;adc_samples[next_free_buf_index()][0], SAADC_BUF_SIZE);
    printk(&amp;quot; * nrfx_saadc_buffer_set error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }

    err_code = nrfx_saadc_buffer_set(&amp;amp;adc_samples[next_free_buf_index()][0], SAADC_BUF_SIZE);
    printk(&amp;quot; * nrfx_saadc_buffer_set error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }

    err_code = nrfx_saadc_mode_trigger();
    printk(&amp;quot; * nrfx_saadc_mode_trigger error code: %d\n&amp;quot;, err_code == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS) {
        return false;
    }

    IRQ_CONNECT(SAADC_IRQn, 1, nrfx_saadc_irq_handler, NULL, 0);
    irq_enable(SAADC_IRQn);

    return true;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I actually tried to change several settings, looking for one which can have an impact on my timing constraint, but only pushing oversampling from 32x(my default value) to 256x added 1 or 2 ms on my loop duration.&lt;/p&gt;
&lt;p&gt;Regarding timer config, I also tried to change its frequency or its bit width, with no visible difference on loop duration.&lt;/p&gt;
&lt;p&gt;You should also know that I use another timer to toggle pins, but really not sure it can have this kind of influence on the new board.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer/SAADC/(D)PPI differences between nRF52840 &amp; nRF5340</title><link>https://devzone.nordicsemi.com/thread/360487?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 09:15:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbd5ca6a-28cf-4aa1-974a-e4ec44c6790f</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The only difference I can think of would be that one of the devices have oversampling enabled in some config, while the other does not. If oversampling is set to 4X without enabling BURST, you would need to sample 4 times for each result to be generated. However, with SCAN mode (multiple channels enabled), without BURST enabled, this would generate the wrong results.&lt;/p&gt;
&lt;p&gt;Can you post your config and all code for using SAADC?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>