<?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>PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49683/ppi-with-multiple-saadcs-and-multiple-timers</link><description>Dear Nordic Support, 
 I am using PPI to link 2 timers (10ms &amp;amp; 5s) with 2 SAADC channel (AIN1 - channel 0 &amp;amp; AIN2 - channel 1). 
 The nrf_drv_saadc_init function is only called once so it means there is only one callback for the sampling event. In case</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Jul 2019 15:15:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49683/ppi-with-multiple-saadcs-and-multiple-timers" /><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198536?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2019 15:15:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f0d1591-bab7-4204-96dc-9b373fba262c</guid><dc:creator>Duy</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;One more question, which function or variable allows me to know that the sample belongs to SAADC channel 0, 1, 2...?&lt;/p&gt;
&lt;p&gt;Thank you and best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Duy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198382?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2019 09:38:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f34e9407-d695-477e-a1ea-1a17fb33808b</guid><dc:creator>Duy</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for your feedback. Now I understand. So all I need is only 1 PPI channel, is it right? It will trigger both SAADC channels too.&lt;/p&gt;
&lt;p&gt;I also found the answer for similar question about multiple SAADCs at different intervals:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/20214/multiple-saadc"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/20214/multiple-saadc&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198339?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2019 08:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ee1a061-658d-4a75-96b7-10304beb2397</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am very sorry, I have misinformed you previously.&lt;/p&gt;
&lt;p&gt;When you are enabling more than one channel, the SAADC enters&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=3_1_0_36_4_3#saadc_operationmodes_scan"&gt;scan mode&lt;/a&gt;, where it samples all enabled channels when you trigger the start task.&lt;/p&gt;
&lt;p&gt;Due to this behavior in hardware, you are actually sampling both inputs at 5 ms interval.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198226?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2019 15:36:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d209ef6c-3fd5-42cd-b637-b41dd7b6cad4</guid><dc:creator>Duy</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Please have a look at my code in main.c and my configuration is sdk_config.h file. Sorry for make it not clear but I still don&amp;#39;t get it work. I enabled TIMER1 and TIMER2.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;TRANSDUCER_TIMER is &lt;span&gt;TIMER1&lt;/span&gt; and&amp;nbsp;BATTERY_TIMER is &lt;span&gt;TIMER2&lt;/span&gt;. I think I have to clear a register to get this to work.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const nrf_drv_timer_t TRANSDUCER_TIMER = NRF_DRV_TIMER_INSTANCE(1);                 /**&amp;lt; ADC timer. */
const nrf_drv_timer_t BATTERY_TIMER = NRF_DRV_TIMER_INSTANCE(2);                    /**&amp;lt; Battery timer. */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thank you and best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Duy&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/55478.main.c"&gt;devzone.nordicsemi.com/.../55478.main.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0601.sdk_5F00_config.h"&gt;devzone.nordicsemi.com/.../0601.sdk_5F00_config.h&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198123?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2019 11:00:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7d59b09-0ecf-48bb-9882-63b3c1651537</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Duy,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="DuyLionTran"]Thank you for your answer, I am running 2 different timers running in different periods (10ms and 5s). If I run only 1 ADC channel + 1 TIMER with PPI, everything works fine.[/quote]
&lt;p&gt;&amp;nbsp;Yes, that is expected to work. In your initial code, you are using one timer (with 2 capture/compare events), which will cause the timer to clear itself on the last event, thus you end up in a scenario where it runs the first SAADC task after 5 ms, and the next one after 4.995 seconds, before the timer itself is cleared.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you add another timer instance to your application, it should work with 2 SAADC channels + 2 TIMERs.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198049?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2019 08:16:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6d8f320-b364-460c-adee-ed9130f19520</guid><dc:creator>Duy</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Thank you for your answer, I am running 2 different timers running in different periods (10ms and 5s). If I run only 1 ADC channel + 1 TIMER with PPI, everything works fine.&lt;/p&gt;
&lt;p&gt;Warm regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Duy&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define APP_ADV_INTERVAL                32                                          /**&amp;lt; The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms). */
#define ADC_ACQUISITION_INTERVAL        10          
#define BATTERY_LEVEL_MEAS_INTERVAL     10000                                       /**&amp;lt; Battery level measurement interval (ticks). */

#define APP_ADV_DURATION                18000                                       /**&amp;lt; The advertising duration (180 seconds) in units of 10 milliseconds. */

static void saadc_init(void)
{
    nrf_saadc_channel_config_t adc_channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
    nrf_saadc_channel_config_t battery_channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);

    APP_ERROR_CHECK(nrf_drv_saadc_init(NULL, saadc_transducer_callback));
//    APP_ERROR_CHECK(nrf_drv_saadc_init(NULL, saadc_battery_callback));

    APP_ERROR_CHECK(nrf_drv_saadc_channel_init(0, &amp;amp;adc_channel_config));
    APP_ERROR_CHECK(nrf_drv_saadc_channel_init(1, &amp;amp;battery_channel_config));

    APP_ERROR_CHECK(nrf_drv_saadc_buffer_convert(m_buffer_pool[0], RAW_ADC_BUFF_SIZE));
    APP_ERROR_CHECK(nrf_drv_saadc_buffer_convert(m_buffer_pool[1], RAW_ADC_BUFF_SIZE));
}


/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;

    /* Enable app timer */
    APP_ERROR_CHECK(app_timer_init());

    /* Create ADC timer */
    APP_ERROR_CHECK(nrf_drv_timer_init(&amp;amp;TRANSDUCER_TIMER, &amp;amp;timer_cfg, adc_acquisition_timeout_handler));
    nrf_drv_timer_extended_compare(&amp;amp;TRANSDUCER_TIMER, NRF_TIMER_CC_CHANNEL0, nrf_drv_timer_ms_to_ticks(&amp;amp;TRANSDUCER_TIMER, ADC_ACQUISITION_INTERVAL), NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    /* Configure BATTERY TIMER */
    APP_ERROR_CHECK(nrf_drv_timer_init(&amp;amp;BATTERY_TIMER, &amp;amp;timer_cfg, battery_level_meas_timeout_handler));
    nrf_drv_timer_extended_compare(&amp;amp;BATTERY_TIMER, NRF_TIMER_CC_CHANNEL0, nrf_drv_timer_ms_to_ticks(&amp;amp;BATTERY_TIMER, BATTERY_LEVEL_MEAS_INTERVAL), NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
}


static void saadc_sampling_event_init(void)
{
    uint32_t transducer_timer_compare_event_addr, battery_timer_compare_event_addr;
    uint32_t saadc_sample_task_addr;

    APP_ERROR_CHECK(nrf_drv_ppi_init());

    nrf_drv_timer_enable(&amp;amp;TRANSDUCER_TIMER);
    nrf_drv_timer_enable(&amp;amp;BATTERY_TIMER);

    transducer_timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;TRANSDUCER_TIMER, NRF_TIMER_CC_CHANNEL0);
    battery_timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;BATTERY_TIMER, NRF_TIMER_CC_CHANNEL0);
    
    saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
    /* Setup ppi channel so that timer compare event is triggering sample tasks in SAADC */
    APP_ERROR_CHECK(nrf_drv_ppi_channel_alloc(&amp;amp;TORQUE_SAADC_TIMER_PPI_CHANNEL));
    APP_ERROR_CHECK(nrf_drv_ppi_channel_alloc(&amp;amp;BATTERY_SAADC_TIMER_PPI_CHANNEL));

    APP_ERROR_CHECK(nrf_drv_ppi_channel_assign(TORQUE_SAADC_TIMER_PPI_CHANNEL, transducer_timer_compare_event_addr, saadc_sample_task_addr));
    APP_ERROR_CHECK(nrf_drv_ppi_channel_assign(BATTERY_SAADC_TIMER_PPI_CHANNEL, battery_timer_compare_event_addr, saadc_sample_task_addr));
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PPI with multiple SAADCs and multiple TIMERs</title><link>https://devzone.nordicsemi.com/thread/198015?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2019 07:35:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68fbda65-3b93-4a75-804d-22af4deff604</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want one SAADC channel to run every 5ms, and another to run every 5 seconds, you need to use two timers.&lt;/p&gt;
&lt;p&gt;This is because the timer itself will not count to 5 ms, fire the event for sampling your first channel, then run for another 4.995 seconds before triggering the event to sample your second channel.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you try to run a individual timer per event and see if that works better?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>