<?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>ADC and PWM events</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82024/adc-and-pwm-events</link><description>Hi, 
 I have set up the PWM to trigger the ADC via PPI. It works but now i want to verify the exact behaviour by setting a GPIO when the ADC starts a conversion and when it stops. Once the ADC has a new value it will report it via 
 
 
 But how do I do</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 06 Jan 2022 14:01:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82024/adc-and-pwm-events" /><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/346507?ContentTypeID=1</link><pubDate>Thu, 06 Jan 2022 14:01:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a960a91-2301-4e80-a673-14b550c62bc5</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again,&lt;br /&gt;&lt;br /&gt;Thank you for your patience with this - I have been out of office for some time, but now I am back again.&lt;/p&gt;
[quote user="Nppn7"]how is it possible that the PWM blocks the ADC? Shouldn&amp;#39;t the PWM only start the ADC? And then it is up to the ADC how long it will need.[/quote]
&lt;p&gt;The PWM will not be blocking the SAADC&amp;#39;s execution - the SAADC will start a conversion as soon as the TASKS_SAMPLE task is triggered if it is not already busy. Which SAADC event are you now using to indicate that a single conversion has finished, and what buffer size for the SAADC are you using?&lt;br /&gt;&lt;br /&gt;It seems to me that the conversions itself take a lot shorter than 190 µs, if that is what is being indicated by the second channel going low in your oscilloscope picture.&lt;br /&gt;&lt;br /&gt;Please also see my other questions in my previous comment.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/344409?ContentTypeID=1</link><pubDate>Mon, 20 Dec 2021 15:01:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57bdee42-637e-47a3-a884-42b343f4795c</guid><dc:creator>Nppn7</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;how is it possible that the PWM blocks the ADC? Shouldn&amp;#39;t the PWM only start the ADC? And then it is up to the ADC how long it will need. These are my PWM settings:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static nrfx_pwm_t TIMEAPI_pwm_instance_s = NRFX_PWM_INSTANCE(0);
static nrf_pwm_values_individual_t TIMEAPI_pwm_sequence_values_s;
nrf_pwm_sequence_t const TIMEAPI_pwm_sequence_s =
{
    .values.p_individual = &amp;amp;TIMEAPI_pwm_sequence_values_s,
    .length              = NRF_PWM_VALUES_LENGTH(TIMEAPI_pwm_sequence_values_s),
    .repeats             = 0,
    .end_delay           = 0
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrfx_pwm_config_t const pwm_config_s =
    {
        .output_pins =
        {
            GENAPI_GpioGetMotorDir1_s().pin_number, // channel 0
            GENAPI_GpioGetMotorDir2_s().pin_number, // channel 1
            NRFX_PWM_PIN_NOT_USED, // channel 2
            NRFX_PWM_PIN_NOT_USED  // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_HIGHEST,
        .base_clock   = NRF_PWM_CLK_2MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 100, // 100 @ 2MHz -&amp;gt; 20kHz
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    APP_ERROR_CHECK(nrfx_pwm_init(&amp;amp;TIMEAPI_pwm_instance_s, &amp;amp;pwm_config_s, NULL));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    TIMEAPI_pwm_sequence_values_s.channel_0 = motor_pwm_duty_cycle_U8;
    TIMEAPI_pwm_sequence_values_s.channel_1 = 0;
    (void)nrfx_pwm_simple_playback(&amp;amp;TIMEAPI_pwm_instance_s, &amp;amp;TIMEAPI_pwm_sequence_s, 2, NRFX_PWM_FLAG_LOOP);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/342425?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 16:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04a6b229-46bd-46ca-85db-232c39006cd3</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;The PWM is responsible for the 190uSecs, nothing to do with the SAADC .. what are the PWM settings? I don&amp;#39;t see them in the posts above&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/341917?ContentTypeID=1</link><pubDate>Fri, 03 Dec 2021 14:55:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:590ad1bb-fac6-40d0-9911-684fe4e50e0a</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="Nppn7"]thanks for the input. Using your code I could see the ADC conversion as GPIO. It seems to be started correctly but needs a lot of time (&amp;gt;190 uS). I need the PWM to run a motor. And measuing the motor current should be synched with PWM.[/quote]
&lt;p&gt;Great, I am happy to hear that you were able to see the SAADC timing using the PPI.&lt;br /&gt;Are you saying that a single conversion takes 190 µs? This would indeed indicate that something is wrong with the usage of the SAADC.&lt;/p&gt;
[quote user="Nppn7"]I need the PWM to run a motor. And measuing the motor current should be synched with PWM.[/quote]
&lt;p&gt;How does your circuitry for measurement of the motor current using the SAADC look?&lt;br /&gt;How will you synchronize the motor with the SAADC - do you mean to map the duty cycle to the SAADC&amp;#39;s sample rate, for instance? If so, how closely does the SAADC need to match the motors changes in duty cycle?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/341855?ContentTypeID=1</link><pubDate>Fri, 03 Dec 2021 11:46:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4a5d55b-3d7d-4ed8-864f-e35d19c61e87</guid><dc:creator>Nppn7</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thanks for the input. Using your code I could see the ADC conversion as GPIO. It seems to be started correctly but needs a lot of time (&amp;gt;190 uS). I need the PWM to run a motor. And measuing the motor current should be synched with PWM.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2021_2D00_12_2D00_03_2D00_12_2D00_39_2D00_34_2D00_757.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;These are my settings:&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_ENABLED 1&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_CONFIG_RESOLUTION 2&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_CONFIG_OVERSAMPLE 0&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_CONFIG_LP_MODE 0&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_CONFIG_IRQ_PRIORITY 6&lt;/p&gt;
&lt;p&gt;And I am using default settings for the channel:&lt;/p&gt;
&lt;p&gt;#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P) \&lt;br /&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .resistor_p = NRF_SAADC_RESISTOR_DISABLED,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .resistor_n = NRF_SAADC_RESISTOR_DISABLED,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .gain&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_SAADC_GAIN1_6,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .reference&amp;nbsp; = NRF_SAADC_REFERENCE_INTERNAL,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .acq_time&amp;nbsp;&amp;nbsp; = NRF_SAADC_ACQTIME_10US,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_SAADC_MODE_SINGLE_ENDED,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .burst&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_SAADC_BURST_DISABLED,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .pin_p&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = (nrf_saadc_input_t)(PIN_P),&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .pin_n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_SAADC_INPUT_DISABLED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/340554?ContentTypeID=1</link><pubDate>Wed, 24 Nov 2021 13:30:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60841662-dd5e-491a-a34c-d4dc2565f982</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;As @hmolesworth mentions you may do this through connecting the SAMPLE and DONE/END event to the setting and clearing task of a GPIO through&amp;nbsp;the PPI peripheral. You should then be able to see the exact time spent on the conversion on the oscilloscope scoping the GPIO. I am however not certain that I have understood why you would want / need the PWM peripheral in this mix - could you elaborate on this?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC and PWM events</title><link>https://devzone.nordicsemi.com/thread/340443?ContentTypeID=1</link><pubDate>Wed, 24 Nov 2021 02:47:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed0044ac-d521-4245-a1b1-0c5ac41ab9ef</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Maybe try using the PPI, either separate channels or FORK from PWM. Here&amp;#39;s an example just using the SAADC (not tested):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// softdevice uses PPI channels 17-31 and groups 4-5
// See &amp;quot;Mask of PPI channels reserved by the SoftDevice when the SoftDevice is enabled&amp;quot;
//  nrf_soc.h: NRF_SOC_SD_PPI_CHANNELS_SD_ENABLED_MSK
//             NRF_SOC_SD_PPI_GROUPS_SD_ENABLED_MSK
// maybe use sd_ppi_channel_assign() if enabling when SD enabled
// Up to three tasks can be used in each GPIOTE channel for performing write operations to a pin, two
// are fixed (SET and CLR), and one (OUT) configurable to perform Set, Clear or Toggle
//  - &amp;quot;HiToLo&amp;quot; Task mode: Clear pin from OUT[n] task 

// PPI Peripheral channel assignments for driving PIN_MONITOR_SAADC
#define SAADC_GPIOTE_CH      0
#define SAADC_PPI_CH_A       0
#define SAADC_PPI_CH_B       1
// Arbitrary pin - say P0.05
#define PIN_MONITOR_SAADC    5

   // Set PIN_MONITOR_SAADC high at start of sample
   NRF_PPI-&amp;gt;CH[SAADC_PPI_CH_A].EEP = (uint32_t)&amp;amp;NRF_SAADC-&amp;gt;EVENTS_STARTED;
   NRF_PPI-&amp;gt;CH[SAADC_PPI_CH_A].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_SET[SAADC_GPIOTE_CH];
// NRF_PPI-&amp;gt;FORK[SAADC_PPI_CH_A].TEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;TASKS_STOP;     // &amp;lt;&amp;lt;== optionally can do a second action with a FORK
   // Clear PIN_MONITOR_SAADC low at end of sample
   NRF_PPI-&amp;gt;CH[SAADC_PPI_CH_B].EEP = (uint32_t)&amp;amp;NRF_SAADC-&amp;gt;EVENTS_DONE;
   NRF_PPI-&amp;gt;CH[SAADC_PPI_CH_B].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_CLR[SAADC_GPIOTE_CH];
// NRF_PPI-&amp;gt;FORK[SAADC_PPI_CH_B].TEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;TASKS_NEXTSTEP; // &amp;lt;&amp;lt;== optionally can do a second action with a FORK

   NRF_GPIOTE-&amp;gt;CONFIG[SAADC_GPIOTE_CH] = GPIOTE_CONFIG_MODE_Task       &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos | 
                                         GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos | 
                                         PIN_MONITOR_SAADC             &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos | 
                                         GPIOTE_CONFIG_OUTINIT_Low     &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos;
   // Enable
   NRF_PPI-&amp;gt;CHENSET = ((1UL &amp;lt;&amp;lt; SAADC_PPI_CH_A) | (1UL &amp;lt;&amp;lt; SAADC_PPI_CH_B));
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Using the PWM PPI FORK as the set should also work ok&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>