<?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>BLE APP TIMER</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6009/ble-app-timer</link><description>hi, 
 Our customer find BLE&amp;#39;s app_timer emerge a deviation when use the BLE&amp;#39;s app_timer. the customer is developing bracelet product , their programs with two app_timer, the one app_ timer generating 1 second timing for date and time information.another</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Apr 2015 10:06:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6009/ble-app-timer" /><item><title>RE: BLE APP TIMER</title><link>https://devzone.nordicsemi.com/thread/21020?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2015 10:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c87db3a-c6af-4389-8610-cb6200295849</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi guozhong.chen
I am sorry, i lost visibility of this thread, do you still have this problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE APP TIMER</title><link>https://devzone.nordicsemi.com/thread/21018?ContentTypeID=1</link><pubDate>Fri, 13 Mar 2015 05:18:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51a95422-a778-4f4d-ba57-88e2ea5ffe62</guid><dc:creator>guozhong.chen</dc:creator><description>&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;what kind of intervals (if in connection or advertising) is the device using?&lt;br /&gt;
Is usually not connected, but the advertising&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;when not counting steps, is the device still in connection/advertising? if not is it in sleep mode?
advertising or connection is possible, if it is connected APP.  Program calls the following function into Sleep.&lt;/p&gt;
&lt;p&gt;uint8_t PowerSave(void)
{
uint8_t mSdIsEnabled;
sd_softdevice_is_enabled(&amp;amp;mSdIsEnabled);&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; if(mSdIsEnabled)
 {
     uint32_t err_code;
     //TRACE1(&amp;quot;$&amp;quot;);
     err_code = sd_app_evt_wait();
     APP_ERROR_CHECK(err_code);  
}
else
{
     NRF_POWER-&amp;gt;TASKS_LOWPWR = 1;
     __WFE();

     __SEV();
     __WFE();  
}
return mSdIsEnabled;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the difference in app timer events when counting steps and when not countin steps is 40 times(1000ms/25ms). You say when counting steps the calender is faster by three minutes a day (which uses 25ms timer). Are you sure that when not counting steps (using app timer of 1 sec) the app_timer is still faster by 9 seconds (three minutes/40 = 180/40 = 9). If this is true then both of the deviations are atleast consistent.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;From Friday to now, almost pedometer and computer time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE APP TIMER</title><link>https://devzone.nordicsemi.com/thread/21019?ContentTypeID=1</link><pubDate>Fri, 13 Mar 2015 04:51:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f534a0fb-6f99-4c4d-b644-c0821599d6b8</guid><dc:creator>guozhong.chen</dc:creator><description>&lt;p&gt;my programer use two APP TIMER&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef struct{

    SoftWareRtcInterface Interface;

    //private:

    void (*mWakeUpIrq)(void * p_context);

    void (*mSecondIrq)(void * p_context);

    void (*mMinuteIrq)(void * p_context);

    void (*mHourIrq)(void *p_context);

    volatile uint32_t mWakeUpOverFlow;

    volatile uint32_t mSecondCount;

    volatile uint32_t mSecondtRecord;

    volatile uint32_t mPowerUpTime;

    //Used to generate one second timing to generate the date and time information

    app_timer_id_t    mSecondTimerId;  

    // Wake-up timer for system operation. Pedometer when 25MS wake every time.

    // Stationary wake every minute

    app_timer_id_t    mWakeUpTimerId;
}SoftWareRtcHal;


#define FW_APP_TIMER_MAX_TIMERS    6 

#define FW_APP_TIMER_OP_QUEUE_SIZE 20 // I tried defined as 1 OR 20


void lfclk_config(void)
{

    NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);

    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;

    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;

    while (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0)
    {
    }
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
}

void AppTimeInit(void)
{

    APP_TIMER_INIT(APP_TIMER_PRESCALER, FW_APP_TIMER_MAX_TIMERS, 
    FW_APP_TIMER_OP_QUEUE_SIZE, FALSE);

}

void InitSoftWareRtc(SoftWareRtcInterface *interface)
{

    uint32_t err_code;

    SoftWareRtcHal *pRtcHal = (SoftWareRtcHal *)interface;    


    interface-&amp;gt;SetWakeUpPeriod = &amp;amp;gRtcSetWakeUpPeriod;

    interface-&amp;gt;GetSecond32 = &amp;amp;gRtcGetSecond32;

    interface-&amp;gt;GetPowerUpTime = &amp;amp;gRtcGetPowerUpTime;

    interface-&amp;gt;SetDate = &amp;amp;gRtcSetDate;

    interface-&amp;gt;SetTime = &amp;amp;gRtcSetTime;

    interface-&amp;gt;GetDate = &amp;amp;gRtcGetDate;

    interface-&amp;gt;GetTime = &amp;amp;gRtcGetTime;

    interface-&amp;gt;RegisterWakeUpIrq = &amp;amp;gRtcRegisterWakeUpIrq;

    interface-&amp;gt;RegisterSecondIrq = &amp;amp;gRtcRegisterSecondIrq;

    interface-&amp;gt;RegisterMinuteIrq = &amp;amp;gRtcRegisterMinuteIrq;

    interface-&amp;gt;RegisterHourIrq = &amp;amp;gRtcRegisterHourIrq;

    interface-&amp;gt;StateCheck = &amp;amp;gRtcStateCheck;

    //interface-&amp;gt;IRQHandle = &amp;amp;gRtcIRQHandle;

    interface-&amp;gt;RestStart = &amp;amp;gRtcRestStart;

    pRtcHal-&amp;gt;mSecondtRecord = pRtcHal-&amp;gt;mSecondCount;

    pRtcHal-&amp;gt;mWakeUpIrq = NULL;

    pRtcHal-&amp;gt;mSecondIrq = NULL;

    pRtcHal-&amp;gt;mMinuteIrq = NULL;

    pRtcHal-&amp;gt;mHourIrq = NULL;	

    TRACE2(&amp;quot;pRtcHal-&amp;gt;gRtcSecond = %x&amp;quot;, pRtcHal-&amp;gt;mSecondCount);

    err_code = app_timer_create(&amp;amp;pRtcHal-&amp;gt;mSecondTimerId,
                 APP_TIMER_MODE_REPEATED,
                 gRtcAppTimerSecondHandle);

    APP_ERROR_CHECK(err_code);

    err_code = app_timer_start(pRtcHal-&amp;gt;mSecondTimerId,
                APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER),
                pRtcHal);

    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&amp;amp;pRtcHal-&amp;gt;mWakeUpTimerId,
                 APP_TIMER_MODE_REPEATED,
                 gRtcAppTimerWakeUpHandle);

    APP_ERROR_CHECK(err_code);
}

void gRtcAppTimerSecondHandle(void * p_context)
{

    SoftWareRtcHal *pRTC = (SoftWareRtcHal *)p_context;

    pRTC-&amp;gt;mSecondCount++;

    if(pRTC-&amp;gt;mSecondIrq != NULL)
    {
        pRTC-&amp;gt;mSecondIrq(NULL);
    }

    if((pRTC-&amp;gt;mMinuteIrq != NULL) &amp;amp;&amp;amp;
        (pRTC-&amp;gt;mSecondCount % 60 == 0))
    {
        pRTC-&amp;gt;mMinuteIrq(NULL);
    }

    if((pRTC-&amp;gt;mHourIrq != NULL) &amp;amp;&amp;amp;
        (pRTC-&amp;gt;mSecondCount % 3600 == 0))
    {
        pRTC-&amp;gt;mHourIrq(NULL);
    }

    //TRACE_INFO1(&amp;quot;*&amp;quot;);
}

bool gRtcSetWakeUpPeriod(SoftWareRtcInterface *RtcInterface, uint16_t period)
{

    /*************************************
    *    Ftick = 1000mS/period;
    *    Ftick == 32768/(PRESCALER+1)
    *==&amp;gt; PRESCALER + 1 == 32768 / Ftick
    *==&amp;gt;
    *==&amp;gt; PRESCALER == 32768 * period / 1000 -1
    *
    *TICK = 32768 / (127+1); 128分频
    *T = 1/TICK;
    *PROID = T * WakeUpOverFlow = WakeUpOverFlow / TICK;
    *WakeUpOverFlow = PROID * (32768 / 128);
    *30mS =&amp;gt; WakeUpOverFlow = 0.030 * (32768/128) = 8
    **************************************/

    uint32_t err_code;

    SoftWareRtcHal *pRTC;

    uint32_t mCurWakeUpOverFlow;

    if(RtcInterface == NULL)
        return -1;

    pRTC = (SoftWareRtcHal *)RtcInterface;

    mCurWakeUpOverFlow = APP_TIMER_TICKS(period, NRF_RTC1-&amp;gt;PRESCALER);

    if(mCurWakeUpOverFlow == pRTC-&amp;gt;mWakeUpOverFlow)
         return 0;

    pRTC-&amp;gt;mWakeUpOverFlow = mCurWakeUpOverFlow;	

    TRACE2(&amp;quot;pRTC-&amp;gt;mWakeUpOverFlow = %x&amp;quot;, pRTC-&amp;gt;mWakeUpOverFlow);

    if((pRTC-&amp;gt;mWakeUpOverFlow &amp;gt;= (MAX_RTC_CNT + 1 - RTC_COMPARE_OFFSET_MIN)) ||
		(pRTC-&amp;gt;mWakeUpOverFlow &amp;lt; 5))
    {
    
         TRACE_ERROR2(&amp;quot;Rtc WakeUpPeriod Set ERR pRTC-&amp;gt;mWakeUpOverFlow = %d&amp;quot;,
		              pRTC-&amp;gt;mWakeUpOverFlow);
        while(1);			
    }    

    if(pRTC-&amp;gt;mWakeUpIrq != NULL)
    {
         err_code = app_timer_stop(pRTC-&amp;gt;mWakeUpTimerId);
         APP_ERROR_CHECK(err_code);
   
         err_code = app_timer_start(pRTC-&amp;gt;mWakeUpTimerId,
                pRTC-&amp;gt;mWakeUpOverFlow,
                pRTC);
         APP_ERROR_CHECK(err_code);
     }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE APP TIMER</title><link>https://devzone.nordicsemi.com/thread/21017?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2015 12:18:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a30aa3d-92ab-417f-b479-7846e70abad8</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi,
We need more information to analyse this.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;what kind of intervals (if in connection or advertising) is the device using?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;when not counting steps, is the device still in connection/advertising? if not is it in sleep mode?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the difference in app timer events when counting steps and when not countin steps is 40 times(1000ms/25ms). You say when counting steps the calender is faster by three minutes a day (which uses 25ms timer). Are you sure that when  not counting steps (using app timer of 1 sec) the app_timer is still faster by 9 seconds (three minutes/40 = 180/40 = 9). If this is true then both of the deviations are atleast consistent.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>