<?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>How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28163/how-to-trigger-adc-from-a-timer-interrupt-while-generating-pwm-with-the-same-timer-and-while-using-ble-on-nrf51822</link><description>Hi. I am a newbie in Nordic chips, quite knowledgeable in Atmel AVR, though. I&amp;#39;m working with an nRF51822 on a board like this www.waveshare.com/.../BLE400 . I use the Mbed environment. 
 What I&amp;#39;m trying to do is this: 
 Generate a PWM signal on a pin</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Dec 2017 15:26:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28163/how-to-trigger-adc-from-a-timer-interrupt-while-generating-pwm-with-the-same-timer-and-while-using-ble-on-nrf51822" /><item><title>RE: How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/thread/111238?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2017 15:26:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c0fd024-5a79-4f83-9c0c-fbff99dd3cf1</guid><dc:creator>Pablo Gindel</dc:creator><description>&lt;p&gt;Thank you, Martin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/thread/111237?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2017 12:24:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee76717b-34f4-4480-95fa-f79cfb6f1824</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;If you are certain that the positive edge ISR has the highest priority in your system I suppose you are safe. But why not trigger the ADC sample task directly via PPI anyway? Then you don&amp;#39;t need CPU resources to start the sampling and wait for the result, but only to handle the conversion complete interrupt. You can also be certain that the Softdevice or other interrupts won&amp;#39;t interfere with the timings of the sampling.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/thread/111236?ContentTypeID=1</link><pubDate>Wed, 13 Dec 2017 12:24:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87f59dbd-9d74-42e5-836b-f928106bcbcf</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;One important thing to remember is that the Softdevice trumps everything. If you are doing anything at all other than BLE you need to assume that what you are doing might be interrupted by the Softdevice and put on hold for a certain amount of time. So consider the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;An ISR is triggered due to a positive edge on the PWM .&lt;/li&gt;
&lt;li&gt;The Softdevice suddenly needs the CPU to handle some BLE event.&lt;/li&gt;
&lt;li&gt;The Softdevice overrides your ISR and puts it on hold before you could start the sampling.&lt;/li&gt;
&lt;li&gt;Now according to &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.sds/dita/softdevices/s130/ble_processor_avail_interrupt_latency/ble_peripheral_connection_performance.html?cp=3_7_2_0_15_2_2_1"&gt;these calculations&lt;/a&gt; the Softdevice should have completed whatever it is doing before the PWM signal goes low again (assuming a 4ms period), but what if you get other interrupts too?&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/thread/111235?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2017 14:15:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ad06425-38a6-4062-932b-44f432f602ce</guid><dc:creator>Pablo Gindel</dc:creator><description>&lt;p&gt;Hi Martin, thank you for your response.&lt;/p&gt;
&lt;p&gt;Do you mean that I have to connect the pwm pin externally to another pin to capture the event? Another possibility would be to trigger the ADC conversion manually from any of the ISRs used for PWM?&lt;/p&gt;
&lt;p&gt;Regarding the second issue: yes, actually I want to sample the voltage on each positive edge. That&amp;#39;s why the PWM frequency is not really that high, 200Hz. I suppose that the ADC would have to be perfectly capable of sampling at 200Hz without consuming CPU (at least that is the case in AVR). I need that many samples to apply some algorithms like filters, etc. One piece of information I did not find in the datasheet is how the ADC works and how much time it takes to do its job.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?</title><link>https://devzone.nordicsemi.com/thread/111234?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2017 11:21:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcdae6bd-f52e-413b-84b9-d7261685193e</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I suggest that you use the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.3.0/lib_pwm.html?cp=4_0_5_3_24"&gt;PWM library for nRF51&lt;/a&gt;, a GPIOTE channel, and PPI. Since the PWM library use a GPIOTE channel to control the PWM pin, you will need to connect the PWM pin to a different GPIO &lt;em&gt;externally&lt;/em&gt; and use a second GPIOTE channel to register positive edges there. A GPIOTE event on a positive edge can then directly be used to trigger an ADC START task and make it do a conversion via PPI.&lt;/p&gt;
&lt;p&gt;However you might not want to sample the voltage on every edge? That sounds like quite a lot of work for the CPU while at the same time doing BLE. So what you could do then, is to use a TIMER/COUNTER and use the GPIOTE positive edge event to trigger a COUNT task in the counter. Then you can do measurements every time the counter reaches a certain count. This can all be done autonomously and you need only wake up when the ADC conversion is completed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>