<?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>Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81004/clear-pwm-signal-in-watchdog-event-handler</link><description>Hi, 
 In our application we use a motor. In the case that the watchdog would trigger while the motor is running, we need to stop the motor. For this we need to set the PWM signal to 0 in the watchdog event handler. However I noticed that when I run to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Oct 2021 14:50:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81004/clear-pwm-signal-in-watchdog-event-handler" /><item><title>RE: Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/thread/336028?ContentTypeID=1</link><pubDate>Tue, 26 Oct 2021 14:50:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d3bbc53-b08e-4c94-9330-99d3d0b8d49d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Gaston"]Yes you are right about the APP_ERROR_CHECK, I do this in all my code, but I forgot it in this part. Thanks for reminding me.[/quote]
&lt;p&gt;No problem at all - it happens every now and then.&lt;br /&gt;Do you see any errors being generated when you check the returned error codes?&lt;br /&gt;&lt;br /&gt;Could you also show me your entire GPIOTE configuration, not just the init function call?&lt;/p&gt;
[quote user="Gaston"]&lt;p&gt;Because I make use of the app_pwm library, I can&amp;#39;t find the address of PWM0 by nrfx_pwm_event_address_get, because the instance type is different. Thats why I thought I can enter it manually because the base address of PWM0 is 0x4001C000 and TASK_STOP has an offset of 0x004, so that would be 0x4001C004. But now when I do the APP_ERROR_CHECK I get an NRF_ERROR_NO_MEM error so perhaps this is not correct.&lt;/p&gt;
&lt;p&gt;How can I retrieve the address of PWM0 when I use the app_timer library?&lt;/p&gt;[/quote]
&lt;p&gt;Oh, I was under the impression that you were using the pwm peripheral, not the pwm library - my mistake.&lt;br /&gt;The difference between the pwm peripheral and the pwm library implementation is that the pwm library does not use the pwm peripheral at all, but instead generates the PWM using a combination of PPI, TIMER and GPIOTE instances.&lt;br /&gt;To stop the timer used by the PWM library by triggering the TIMER instance&amp;#39;s&amp;nbsp;&lt;a title="TASKS_STOP" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/timer.html?cp=4_1_0_5_27_4_1#register.TASKS_STOP"&gt;TASKS_STOP&lt;/a&gt;&amp;nbsp;task - this should immediately stop the PWM generation.&lt;br /&gt;&lt;br /&gt;Which function is returning the NRF_ERROR_NO_MEM? Please make sure to have DEBUG defined in your preprocessor defines, like shown in the included image. This will make the logger output a detailed error message whenever a non-NRF_SUCCESS error message is passed to an APP_ERROR_CHECK.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/6330.enabling_5F00_debug_5F00_SES.PNG" /&gt;&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: Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/thread/335942?ContentTypeID=1</link><pubDate>Tue, 26 Oct 2021 11:32:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4147c10e-d47b-4287-86f1-68ddd5b88c8f</guid><dc:creator>Gueston</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes you are right about the APP_ERROR_CHECK, I do this in all my code, but I forgot it in this part. Thanks for reminding me.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/81004/clear-pwm-signal-in-watchdog-event-handler/335908#335908"]Could you show me your configuration of the GPIOTE pin as well?[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    err_code = nrfx_gpiote_in_init(25, &amp;amp;config2, gpiote_evt_handler);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/81004/clear-pwm-signal-in-watchdog-event-handler/335908#335908"]How did you acquire the pwm_task_addr?[/quote]
&lt;p&gt;Because I make use of the app_pwm library, I can&amp;#39;t find the address of PWM0 by nrfx_pwm_event_address_get, because the instance type is different. Thats why I thought I can enter it manually because the base address of PWM0 is 0x4001C000 and TASK_STOP has an offset of 0x004, so that would be 0x4001C004. But now when I do the APP_ERROR_CHECK I get an NRF_ERROR_NO_MEM error so perhaps this is not correct.&lt;/p&gt;
&lt;p&gt;How can I retrieve the address of PWM0 when I use the app_timer library?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/thread/335908?ContentTypeID=1</link><pubDate>Tue, 26 Oct 2021 09:55:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeddaaee-0ee3-4e5e-b059-6563c61f481c</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;First and foremost I notice that you are not checking any of the returned error codes. Please always make sure to pass the error codes returned by SDK function calls to an APP_ERROR_CHECK, or implement specific error handling, in order to be alerted in the case that a function call fails unexpectedly.&lt;br /&gt;Without checking the error codes you will never be alerted to a function call failing, and thus you will be unable to take any steps to avoid the program proceeding into a undefined state or general breakage.&lt;br /&gt;Could you show me your configuration of the GPIOTE pin as well?&lt;br /&gt;How did you acquire the pwm_task_addr?&lt;br /&gt;&lt;br /&gt;I also notice that you are referring to your pins with their number directly. I highly recommend making a #define for each pin you will be using, and targeting it using the NRF_GPIO_PIN_MAP macro to do so - to reduce the chance of targeting the wrong pin, and to increase maintainability of your code.&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: Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/thread/335826?ContentTypeID=1</link><pubDate>Mon, 25 Oct 2021 18:28:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8139449d-30f4-47ca-9ef5-74ee39edaa05</guid><dc:creator>Gueston</dc:creator><description>&lt;p&gt;Thanks for your reply. I don&amp;#39;t get it working, I have this code:&lt;/p&gt;
&lt;p&gt;In ppi_init:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    uint32_t gpio_event_addr;
    uint32_t pwm_task_addr;

    nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel3);
    gpio_event_addr = nrfx_gpiote_in_event_addr_get(25);
    nrfx_gpiote_in_event_enable(25, true);
    pwm_task_addr = 0x4001C004;
    nrfx_ppi_channel_assign(ppi_channel3, gpio_event_addr, pwm_task_addr);
    nrfx_ppi_channel_enable(ppi_channel3);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In gpio_init:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrf_gpio_cfg_input(25, NRF_GPIO_PIN_NOPULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and then when I press a button to trigger the task from the event:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;            nrf_gpiote_event_enable(25);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But this doesn&amp;#39;t work&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Clear PWM signal in watchdog event handler</title><link>https://devzone.nordicsemi.com/thread/335596?ContentTypeID=1</link><pubDate>Sun, 24 Oct 2021 17:54:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04d6bbe8-5a68-4567-91a2-10262aecf0fd</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]Is there a way to disconnect the PWM immediately from a pin and set the pin to 0 with very low latency?[/quote]
&lt;p&gt;For the lowest possible latency between the pin triggering and the pwm stopping you could use the PPI peripheral to connect a GPIOTE IN_EVENT to the PWM peripherals&amp;nbsp;&lt;a title="TASKS_STOP" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/pwm.html?cp=4_1_0_5_15_4_0#register.TASKS_STOP"&gt;TASKS_STOP&lt;/a&gt;. This will make the pin event immediately trigger the STOP task of the PWM peripheral, without requiring any CPU intervention (which might be what is adding to your delay here - if the CPU is busy with a higher-priority task or similar).&lt;br /&gt;&lt;br /&gt;If you are not already familiar with the PPI peripheral and how to use it, you could take a look at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ppi_example.html"&gt;the PPI example&lt;/a&gt;&amp;nbsp;or &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/nrf_dev_saadc_example.html"&gt;the&amp;nbsp; SAADC example&lt;/a&gt;&amp;nbsp;which demonstrates its usage.&lt;br /&gt;&lt;br /&gt;Please do not hesitate to ask if you should encounter any issues or questions regarding 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></channel></rss>