<?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>Power sequence issue SAADC read</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71773/power-sequence-issue-saadc-read</link><description>Hello Everyone, 
 I am developing a Zigbee-based device using nRF52840. 
 So far all functionalities are working without any problem. Now for device load detection, we are developing an initial sequence that reads ADC and depending on that procced for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 26 Feb 2021 07:07:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71773/power-sequence-issue-saadc-read" /><item><title>RE: Power sequence issue SAADC read</title><link>https://devzone.nordicsemi.com/thread/296418?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 07:07:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4d86734-3041-4463-8c21-6000441b76c1</guid><dc:creator>Rohit Rajapure</dc:creator><description>&lt;p&gt;Hi J&amp;oslash;rgen,&lt;/p&gt;
&lt;p&gt;Thanks for the feedback,&lt;/p&gt;
&lt;p&gt;One update from my end. I have resolved the RESET issue in the power-on sequence. I had made some changes in my first approach &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1258.main_5F00_20210218.c"&gt;1258.main_20210218.c&lt;/a&gt;. Files are attached in my query post. Now I am able to make power-on sequence and SAADC working.&lt;/p&gt;
&lt;p&gt;Yes, SAADC reading needs some configuration fine-tuning. We are testing the same. &lt;/p&gt;
&lt;p&gt;Thank you for your constant support &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;. I will get back to you in case of any queries.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks and Regards&lt;/p&gt;
&lt;p&gt;Rohit R&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power sequence issue SAADC read</title><link>https://devzone.nordicsemi.com/thread/296380?ContentTypeID=1</link><pubDate>Thu, 25 Feb 2021 18:24:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd351e50-7412-4a83-9d18-f65ba447eeee</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>[quote user="Rohit Rajapure"]I tried your wait for a suggestion as shared in the snippet but after the flag gets to set it did not enter into the below while condition statement because of that brightness not incrementing as well as no further execution.[/quote]
&lt;p&gt;Did you set the flag to false initially, and set the flag to true in&amp;nbsp;saadc_event_handler when you receive the&amp;nbsp;NRF_DRV_SAADC_EVT_DONE event?&lt;/p&gt;
[quote user="Rohit Rajapure"]I can not use delay because while incrementing brightness it is flickering so end-user point it is not acceptable.[/quote]
&lt;p&gt;My suggestion was to reduce the delay to around 15 microseconds (us). I do not see how that could give visible flickering.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power sequence issue SAADC read</title><link>https://devzone.nordicsemi.com/thread/295481?ContentTypeID=1</link><pubDate>Mon, 22 Feb 2021 05:03:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3df912b-e894-432f-932c-b2eaaca7ea9f</guid><dc:creator>Rohit Rajapure</dc:creator><description>&lt;p&gt;Hi J&amp;oslash;rgen,&lt;/p&gt;
&lt;p&gt;Thank you for the feedback.&lt;/p&gt;
&lt;p&gt;yes, I tried setting a flag and block but a different way and it did not work.&lt;/p&gt;
&lt;p&gt;I refer to your code and check the result.&lt;/p&gt;
[quote userid="14926" url="~/f/nordic-q-a/71773/power-sequence-issue-saadc-read/295348#295348"]I&amp;#39;m not sure I understand exactly what is not working with your power-on sequence, do you get an error code or similar?[/quote]
&lt;p&gt;- No, I do not get any error but unable to read ADC values. with my 2nd code attached in the previous post. But it works without hard RESET.&lt;/p&gt;
&lt;p&gt;I tried your wait for a suggestion as shared in the snippet but after the flag gets to set it did not enter into the below while condition statement because of that brightness not incrementing as well as no further execution. &lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
  while((ui16CurrentADCValue &amp;gt;= MIN_ADC_VAL) &amp;amp;&amp;amp; (ui32Brightness &amp;lt;= ui32DutyCycle100))
  {
      ui32PrevDutyCycle = ui32Brightness;
      ui32Brightness += 10;

      nrf_drv_gpiote_in_event_enable(ZERO_CROSS_DETECTION,true); //enable ZCD

      err_code = nrf_drv_saadc_sample();//trigger ADC
      APP_ERROR_CHECK(err_code);

      while(ui8Saadc_done_flag == false);
      ui8Saadc_done_flag = false;

//      nrf_delay_ms(50); //adding delay able to read adc values 

  }
  
  &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Let me know what is the cause.&lt;/p&gt;
&lt;p&gt;I can not use delay because while incrementing brightness it is flickering so end-user point it is not acceptable.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks and Regards&lt;/p&gt;
&lt;p&gt;Rohit R&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power sequence issue SAADC read</title><link>https://devzone.nordicsemi.com/thread/295348?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2021 13:21:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:835cba17-b7be-41c7-afa0-82efd0db36de</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure I understand exactly what is not working with your power-on sequence, do you get an error code or similar?&lt;/p&gt;
&lt;p&gt;The SAADC works asynchronously, meaning that the call to the sample-function will only trigger a sample, and you will get a callback in the event handler when the sampling is done.&lt;/p&gt;
&lt;p&gt;the delay-method should work, and with a single channel and 10 us acquisition-time, you should be able to reduce it to around 15 us. However, to be sure to get long enough, but shortest possible wait, you should set a flag and do a blocking wait for this flag to be set:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t saadc_done_flag = false;

static void InitialSequence(void)
{
  ...
  
  //read ADC value of capacitor
  err_code = nrf_drv_saadc_sample();
  APP_ERROR_CHECK(err_code);
  
  while(saadc_done_flag == false);
  saadc_done_flag = false;
  

  while((ui16CurrentADCValue &amp;gt;= MIN_ADC_VAL) &amp;amp;&amp;amp; (ui32Brightness &amp;lt;= ui32DutyCycle100))
  {
      ...

      err_code = nrf_drv_saadc_sample();//trigger ADC
      APP_ERROR_CHECK(err_code);
	  
	  while(saadc_done_flag == false);
	  saadc_done_flag = false;	  
  }
 
}

void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        uint32_t          err_code;

        ui16CurrentADCValue = p_event-&amp;gt;data.done.p_buffer[0];
		saadc_done_flag = true;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, 1);
        APP_ERROR_CHECK(err_code);
      
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>