<?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>nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84472/nrf51822-timer-capture-and-pwm-generation-with-softdevice</link><description>Hello, 
 I have been developing some products over the nRF51822 BLE. Got my introduction with nRF about 2 months back and despite the steep learning curve I was able to integrate the softdevice with LESC passkey and some GPIO peripheral control for a</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Feb 2022 08:02:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84472/nrf51822-timer-capture-and-pwm-generation-with-softdevice" /><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/354041?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 08:02:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b84d7dbd-c126-4158-b859-0bc8925e1e1d</guid><dc:creator>Sigurd</dc:creator><description>[quote user="shwetank vishnu"]Is there any other series that may solve this or I am lagging on the approach of the problem?[/quote]
&lt;p&gt;With e.g.the nRF52832 you have a dedicated PWM peripheral, and 5 TIMERS.&amp;nbsp;&lt;/p&gt;
[quote user="shwetank vishnu"]and started reading on the main loop for the timer capture values but nothing seem to work.[/quote]
&lt;p&gt;It would be better to read it from e.g. an&amp;nbsp;&lt;span&gt;app_timer&amp;nbsp;handler&amp;nbsp;that triggers/expires at a fixed interval. E.g. read it every 2 second.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/guides/short-range-guides/b/software-development-kit/posts/application-timer-tutorial"&gt;https://devzone.nordicsemi.com/guides/short-range-guides/b/software-development-kit/posts/application-timer-tutorial&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/353825?ContentTypeID=1</link><pubDate>Fri, 18 Feb 2022 11:52:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7de560f-347c-4190-92fc-9a48703902c0</guid><dc:creator>shwetank vishnu</dc:creator><description>&lt;p&gt;So I tried a lot with many permutation and combinations but this does not seem to work.&lt;/p&gt;
&lt;p&gt;I deleted the timer2 from code and started reading on the main loop for the timer capture values but nothing seem to work.&lt;/p&gt;
&lt;p&gt;I guess I am overkilling the nordic capabilities. A BLE stack along with PWM generation and capture feature looks like too demanding for the controller.&lt;/p&gt;
&lt;p&gt;Is there any other series that may solve this or I am lagging on the approach of the problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/352535?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 10:14:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8444b96d-246e-40aa-a430-49bcee53991f</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;app_timer uses RTC. But app_pwm will use a TIMER instance.&lt;/p&gt;
&lt;p&gt;There are 3 TIMER instances on the nRF51.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1644574010184v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Softdevice uses TIMER0, so 2 timers left for the application.&lt;/p&gt;
&lt;p&gt;app_pwm uses 1, and timer_init() code uses 2(m_timer_count and m_timer_read).&lt;/p&gt;
&lt;p&gt;Maybe you can try to remove&amp;nbsp;&lt;span&gt;m_timer_read, and use e.g an app_timer to trigger the reading of&amp;nbsp;m_timer_count instead.&lt;/span&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: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/352469?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 05:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4f90755-c2d3-474b-8e22-e1b6a3c9a27f</guid><dc:creator>shwetank vishnu</dc:creator><description>&lt;p&gt;So as I said, I am using one timer for control purpose i.e. a 100ms generic timer interrupt and one APP_PWM to generate the 125KHz pulse.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void pwm_init()
{
uint32_t err_code;
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(8L, MCU1); // 125KHz on MCU1 pin
err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,NULL);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&amp;amp;PWM1);
app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 100); //set initial duty as zero (instanct, channel, !duty)
}

void control_timer_init()
{
APP_TIMER_INIT(0, 4, false);
err_code = app_timer_create(&amp;amp;m_control_timer_id,
APP_TIMER_MODE_REPEATED,
control_timeout_handler);
err_code = app_timer_start(m_control_timer_id, TIMER_INTERVAL, NULL);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Now I am not sure what timer do either of these use since APP_PWM&amp;nbsp;and&amp;nbsp;APP_TIMER are handled internally.&lt;/p&gt;
&lt;p&gt;To re-iterate what I want to do :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. Use the softdevice and peer manager for BLE.&lt;/p&gt;
&lt;p&gt;2. One 125KHz pulse.&lt;/p&gt;
&lt;p&gt;3. One generic timer for control part (50 - 100msec).&lt;/p&gt;
&lt;p&gt;4. A method to measure incoming pulse width.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/352378?ContentTypeID=1</link><pubDate>Thu, 10 Feb 2022 14:26:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98539956-ac5b-4d40-8f6d-d24a096a8b9a</guid><dc:creator>Sigurd</dc:creator><description>[quote user="shwetank vishnu"]So I tried to use the examples provided, but when i integrate it in my code, the BLE part does not work.[/quote]
&lt;p&gt;The SoftDevice uses TIMER0, but this&amp;nbsp;timer_init functions uses TIMER1 and TIMER2, so it should not be a conflict here. Do you know if you use e.g. TIMER1 for something else in your application?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/351982?ContentTypeID=1</link><pubDate>Wed, 09 Feb 2022 09:10:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1007b3c3-5634-458e-a3f2-815b4ef2c6bb</guid><dc:creator>shwetank vishnu</dc:creator><description>&lt;p&gt;The timer init&amp;nbsp;that is in the code that you shared. Below is the code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void timer_init()
{
    ret_code_t err_code;
    // Configure TIMER1 for counting of low to high events on GPIO
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    timer_cfg.mode = NRF_TIMER_MODE_COUNTER;
    err_code = nrf_drv_timer_init(&amp;amp;m_timer_count, &amp;amp;timer_cfg, timer_handler_count);
    APP_ERROR_CHECK(err_code);

    // Configure TIMER2 for reading the counter timer at a given interval COUNT_READ_INTERVAL
    timer_cfg.mode = NRF_TIMER_MODE_TIMER;
    err_code = nrf_drv_timer_init(&amp;amp;m_timer_read, &amp;amp;timer_cfg, timer_handler_read);
    APP_ERROR_CHECK(err_code);
    
    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer_read, COUNT_READ_INTERVAL);
    nrf_drv_timer_extended_compare(&amp;amp;m_timer_read,
                                   NRF_TIMER_CC_CHANNEL0,
                                   ticks,
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   true);
    nrf_drv_timer_enable(&amp;amp;m_timer_read);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It is used along with the GPIOTE and PPI initialization.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/351975?ContentTypeID=1</link><pubDate>Wed, 09 Feb 2022 08:47:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03e556c6-00a2-4757-ace6-7f6d74dc2478</guid><dc:creator>Sigurd</dc:creator><description>[quote user="shwetank vishnu"]I think this is some issue related to timer conflicts because as soon as i comment the timer init part everything works.[/quote]
&lt;p&gt;What timer init part are you referring to here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/351812?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 13:07:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1291181b-a0bd-4f69-8eda-0943d1151db8</guid><dc:creator>shwetank vishnu</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;So I tried to use the examples provided, but when i integrate it in my code, the BLE part does not work. I think this is some issue related to timer conflicts because as soon as i comment the timer init part everything works.&lt;/p&gt;
&lt;p&gt;I was able to use the GPIOTE and get the interupt counts from the pulses but pulse width count is creating problem.&lt;/p&gt;
&lt;p&gt;As I mentioned I am already using one PWM channel, one timer for control part and softdevice must be using one. So I am not sure how to proceed here.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 : Timer capture and PWM generation with softdevice</title><link>https://devzone.nordicsemi.com/thread/351626?ContentTypeID=1</link><pubDate>Mon, 07 Feb 2022 17:00:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32a54693-0d35-44ed-a9cf-c71252a8011e</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]&lt;p&gt;Please let me know of any literature available or any example for the same.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;You can find&amp;nbsp;some examples in this post:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/34547/ppi-configuration-to-count-pulses"&gt;devzone.nordicsemi.com/.../ppi-configuration-to-count-pulses&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>