<?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>HFCLK timer issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79283/hfclk-timer-issue</link><description>Hi Nordic Engineers, 
 
 I have few queries over HFCLK 16 MHz timer. 
 I am using nrf52840 custom board. IDE - segger embedded studio 
 
 I have enabled HFCLK timer and able to reach timer callback. 
 The problem is...If I set the Timeout as 2600 us,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Sep 2021 12:16:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79283/hfclk-timer-issue" /><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/330652?ContentTypeID=1</link><pubDate>Wed, 22 Sep 2021 12:16:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22aa6d00-9d70-4019-bcf2-8f6587d98c91</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I&amp;#39;m glad to hear you&amp;#39;ve solved the issue, don&amp;#39;t hesitate to ask for support in the future :)&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/330271?ContentTypeID=1</link><pubDate>Mon, 20 Sep 2021 11:56:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b4dd638-ef8f-4d74-acfd-5d90422794ef</guid><dc:creator>sudharsan</dc:creator><description>&lt;p&gt;Hi Haakonsh,&lt;/p&gt;
&lt;p&gt;I have an option to turn on/off the LEDs which is connected ADPD sensor.&lt;/p&gt;
&lt;p&gt;Now its doing well.&lt;/p&gt;
&lt;p&gt;Thanks for your support. Take care&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/329790?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 10:28:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8319fad1-4bcc-4ef8-b066-9df4e08914de</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey sudharsan, sry for the late response, i got sick with the flu last week :/&amp;nbsp;&lt;/p&gt;
[quote user="sudharsan"]Max speed that we can set in controller side is of 400K right??[/quote]
&lt;p&gt;&amp;nbsp;Yes, you&amp;#39;re right.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="sudharsan"]&lt;p&gt;&lt;span&gt;RED on for 250 us (IR should be off) ----- complete off ----- IR on for 250us&amp;nbsp; (RED should be off) ----- Both off ------ should continue in the same way.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Its not only switching but also I have to read the FIFO data from the sensor.&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I don&amp;#39;t think that is possible with a 400k TWI bus.&lt;/p&gt;
&lt;p&gt;I suggest you scope the TWI bus and LEDs with a logical analyzer and verify what timings you are actually getting.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328159?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 11:14:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a5737d9-a717-412f-ab36-768b5f74af4d</guid><dc:creator>sudharsan</dc:creator><description>&lt;p&gt;I am using ADPD4101 sensor which is from Analog devices. I was not talking about the color of the LED. Its about fast processing.&lt;/p&gt;
&lt;p&gt;I wish to switch RED and IR LEDs. I have sent you the while(1) block of code also.&lt;/p&gt;
&lt;p&gt;Max speed that we can set in controller side is of 400K right?? SPI cannot be used as I have only I2C provision&lt;/p&gt;
&lt;p&gt;&lt;span&gt;RED on for 250 us (IR should be off) ----- complete off ----- IR on for 250us&amp;nbsp; (RED should be off) ----- Both off ------ should continue in the same way.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Its not only switching but also I have to read the FIFO data from the sensor.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please have a look at the below model pic.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1630926553992v1.png" /&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: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328149?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 10:43:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3e5f337-30dd-42fe-8f56-e6b4c0ba50a1</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Yeah that can easily take a few millisecons, and it seems like that is a hard-limit for your use-case.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="sudharsan"]Should it be possible to see in naked eye ??[/quote]
&lt;p&gt;&amp;nbsp;The IR LED probably have some spectral components in the red color range. Or are you talking about the switching frequency?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What sensor are you using btw?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-EDIT:&lt;br /&gt;I see you&amp;#39;re using an&amp;nbsp;ADPD410x of some kind, they seems to accept TWI speeds up to 1mbps and SPI speeds upt to 24mbps. At what speed is the TWI bus currently running on?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328144?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 10:19:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdd154f1-46d0-4aaf-a489-ae2ccc566b67</guid><dc:creator>sudharsan</dc:creator><description>&lt;p&gt;This is not LED which is connected to GPIO. It is connected to HRM sensor where the enable/disable should be I2C write.&lt;/p&gt;
&lt;p&gt;Please check the below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void EnableHRMLed(enum enable_led_t led_on)
{
     if(led_on == HR_RED_LED){
        switch_on_LED_1A_2A(&amp;amp;m_twi, ADPD410X_TS_A, ENABLE_HRLED_2A);
        cal_HR_red_enabled = true;
        cal_HR_ir_enabled = false;
     }
     else{
        switch_on_LED_1A_2A(&amp;amp;m_twi, ADPD410X_TS_B, ENABLE_HRLED_1A);
        cal_HR_red_enabled = false;
        cal_HR_ir_enabled = true;
     }
} 

void DisableHRMLed(void)
{
     switch_off_LEDs(&amp;amp;m_twi, PAIR_12, ADPD410X_TS_A); 
     switch_off_LEDs(&amp;amp;m_twi, PAIR_12, ADPD410X_TS_B);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328142?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 10:10:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbe74c53-08ea-47af-a0b6-1dd7dac6ae44</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;If it &amp;quot;works&amp;quot; now then it&amp;#39;s an indication that the the functions&amp;nbsp;DisableHRMLed() and&amp;nbsp;EnableHRMLed() takes ~2600µs to execute. Can you share their implementation as well?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I believe is happening is that there&amp;#39;s a pending TIMER COMPARE interrupt when you exit the TIMER event handler, therefore you never return to your main loop.&lt;/p&gt;
[quote user="sudharsan"]&lt;p&gt;Please confirm...Is my timer initialization function definition right or ...??&lt;/p&gt;
&lt;p&gt;Do I need to modify anything on timer side??&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;Your timer initialization seems okay to me. I think the issue lies in the LED toggling.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328135?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 09:31:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1e6672c-125a-4165-9508-fd5d1c4c4df8</guid><dc:creator>sudharsan</dc:creator><description>&lt;p&gt;Hi Haakonsh,&lt;/p&gt;
&lt;p&gt;Please confirm...Is my timer initialization function definition right or ...??&lt;/p&gt;
&lt;p&gt;Do I need to modify anything on timer side??&lt;/p&gt;
&lt;p&gt;I have changed the timer callback. Now I am just setting the flag and reading it in while(1)&lt;/p&gt;
&lt;p&gt;Now its fine and loop is also running...I have given 250us time-interval to switch the sensor&amp;#39;s LED.&lt;/p&gt;
&lt;p&gt;Sensor which is using I2C communication and speed - 400K&lt;/p&gt;
&lt;p&gt;I am able to see the LED switching (RED &amp;lt;-&amp;gt; GREEN) ...Should it be possible to see in naked eye ??&lt;/p&gt;
&lt;p&gt;This is where I am right now&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/***************Enter main loop********************/
for (;;)
{   
        while (app_usbd_event_queue_process());
        process_usb_event();
         
#if defined(CMD_MODE) || defined(BLECMD_MODE)
        APPTASK_Handler();
#endif

#ifdef BLECMD_MODE
        BLE_PROCESS();
#endif

        if(timerenabled == 1)
        {
              if(is_HF_timer_started){
                  if(!cal_HR_ir_enabled)
                  {
                      //nrf_drv_timer_pause(&amp;amp;TIMER_LED);
                      DisableHRMLed();       //Disabling RED and Enabling IR
                      EnableHRMLed(HR_IR_LED);
                      //nrf_drv_timer_resume(&amp;amp;TIMER_LED);
                  }
                  else if(!cal_HR_red_enabled)
                  {
                      //nrf_drv_timer_pause(&amp;amp;TIMER_LED);
                      DisableHRMLed();       //Disabling IR and Enabling RED
                      EnableHRMLed(HR_RED_LED);
                      //nrf_drv_timer_resume(&amp;amp;TIMER_LED);
                  }
              }
              timerenabled = 0;
        }


#ifdef HRMEN
      HRM_Process();
      
#endif
        idle_state_handle();
}
/****************************************************************/




void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
&amp;#160; switch (event_type)
&amp;#160; {
&amp;#160; &amp;#160; case NRF_TIMER_EVENT_COMPARE3:
&amp;#160; &amp;#160; &amp;#160; timerenabled = 1;
&amp;#160; &amp;#160; &amp;#160; break;

&amp;#160; &amp;#160; default:
&amp;#160; &amp;#160; //Do nothing.
&amp;#160; &amp;#160; break;
&amp;#160; &amp;#160;}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sudharsan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/328114?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 08:03:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d454e58d-6564-4b8c-a0ef-90efec65fe60</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;What&amp;#39;s the execution time of the TIMER_LED&amp;#39;s event handler?&lt;/p&gt;
&lt;p&gt;And yes, TIMER0 is reserved for the SoftDevice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HFCLK timer issue</title><link>https://devzone.nordicsemi.com/thread/327992?ContentTypeID=1</link><pubDate>Fri, 03 Sep 2021 13:28:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36b2de40-57d3-4c79-bcb3-8a5ddf179c93</guid><dc:creator>sudharsan</dc:creator><description>&lt;p&gt;My source code contains softdevice also. We should not use Timer 0 right??? which is reserved for softdevice&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>