<?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>Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60377/acceleration-active-and-deactivate-gps</link><description>Dear, 
 
 Im trying to use the motion to activate the GPS and deactivate GPS: 
 1. when it moves, GPS will be activated: Position-ON 
 2. when it stops, GPS will be activated again: Position-OFF 
 Currently, I used the sensor_trigger_set() to enable GPS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 24 Apr 2020 14:47:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60377/acceleration-active-and-deactivate-gps" /><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/246575?ContentTypeID=1</link><pubDate>Fri, 24 Apr 2020 14:47:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bbf3a38-d5bb-4108-9d15-10b44c95b486</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Hoang,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can this be your issue? The timer is by default 16 bit, so it will not be able to count as long as 60 secs:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/timer.html?cp=2_0_0_5_15_4_18#register.BITMODE"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf9160/timer.html?cp=2_0_0_5_15_4_18#register.BITMODE&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use the kernel timer API as well, since you already have the &amp;quot;schedule to main&amp;quot; functionality implemented.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/1.12.0/kernel/timing/timers.html#defining-a-timer"&gt;https://docs.zephyrproject.org/1.12.0/kernel/timing/timers.html#defining-a-timer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To get it reoccurring, remember to add this to the _start function call:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;k_timer_start&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;my_sync_timer&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; &lt;span&gt;K_SECONDS&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt;),&lt;/span&gt; &lt;span style="text-decoration:underline;"&gt;K_SECONDS(10&lt;/span&gt;&lt;span&gt;&lt;span style="text-decoration:underline;"&gt;)&lt;/span&gt;;&lt;br /&gt; &lt;br /&gt;Kind regards,&lt;br /&gt;Håkon&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/246296?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2020 14:02:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:effaed54-f205-4aca-85db-7d174fa2e9a2</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;in the timer.zip&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#define TIMEOUT 60000 //milisecond 

static u32_t timestamp_prev;
int counter ;
bool gps_enable_timeout; 

nrfx_timer_t my_timer = NRFX_TIMER_INSTANCE(0);
nrfx_timer_config_t my_timer_config = NRFX_TIMER_DEFAULT_CONFIG;

void timer_cb(nrf_timer_event_t event_type, void * p_context) {
    
    timestamp_prev = k_uptime_get_32();
    counter += 1;
    printk(&amp;quot;counter: %d \r&amp;quot;,counter);
    printk(&amp;quot;timestamp_prev: %d \n\r&amp;quot;,timestamp_prev); 
    printk(&amp;quot;set_gps_enable----------\r&amp;quot;);
    printk(&amp;quot;start GPS ..\n&amp;quot;);
    set_gps_enable(true);
    gps_enable_timeout = true ; 

    printk(&amp;quot;gps_enable_timeout: %d \n\r&amp;quot;, gps_enable_timeout); 
}

void main() {

    printk(&amp;quot;Timer sample started\n&amp;quot;);
    counter = 0; 
    gps_enable_timeout = false; 

    IRQ_CONNECT(DT_NORDIC_NRF_TIMER_TIMER_0_IRQ_0, 
                DT_NORDIC_NRF_TIMER_TIMER_0_IRQ_0_PRIORITY, 
                nrfx_isr, 
                nrfx_timer_0_irq_handler, 
                0);


    my_timer_config.frequency = NRF_TIMER_FREQ_31250Hz;
    
    nrfx_err_t err = nrfx_timer_init(&amp;amp;my_timer, &amp;amp;my_timer_config, timer_cb);
    if (err != NRFX_SUCCESS) {
        printk(&amp;quot;timer_init error: %d\n&amp;quot;, err);
        return;
    }

    // Set the timer to trigger every second.
    
      uint32_t time_ticks = nrfx_timer_ms_to_ticks(&amp;amp;my_timer, TIMEOUT);
      printk(&amp;quot;Setting compare, timeout after %d ticks\n&amp;quot;, time_ticks ); 
    
  // nrfx_timer_compare(&amp;amp;my_timer, NRF_TIMER_CC_CHANNEL0, nrfx_timer_ms_to_ticks(&amp;amp;my_timer, TIMEOUT), true);
     nrfx_timer_compare(&amp;amp;my_timer, NRF_TIMER_CC_CHANNEL0,time_ticks, true);
   
    
     printk(&amp;quot;Starting timer\n&amp;quot;);
     nrfx_timer_enable(&amp;amp;my_timer);
    
     printk(&amp;quot;Timer started\n&amp;quot;);
    
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I changed the TIMEOUT to 60000 (miliseconds), I expected the timer will &amp;quot;trigger&amp;quot; after TIMEOUT&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But, it always trigger after 1s.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I check the document:&amp;nbsp;&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fgroup__nrfx__timer.html&amp;amp;cp=7_1_6_9_0_37_1_10&amp;amp;anchor=ga949efcc263af88d63ecdce7eaa3d5761"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fgroup__nrfx__timer.html&amp;amp;cp=7_1_6_9_0_37_1_10&amp;amp;anchor=ga949efcc263af88d63ecdce7eaa3d5761&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Did I misunderstand somewhere?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hoang&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/246078?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 14:00:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aef3ca6f-7b25-424c-b92d-04d8a697489a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Hoang,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Its not stated directly that you shouldn&amp;#39;t call socket operations directly from interrupt, nor that the kernel timers are executed in interrupt context, and we should document this a bit better. I&amp;#39;ll write it down as a improvement and report it internally.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/246053?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 13:05:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a173a4c-6762-4379-9ea3-7c500bad41e0</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;Thank &lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I will read and try to understand your guide. Thanks a lot ( Sorry, I don&amp;#39;t have knowledge about programming )&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hoang Nguyen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/246041?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 12:46:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6448ec69-3354-4b87-ae8f-0d411b3e46a4</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are asserting because a kernel function is called from interrupt context. Try setting a flag and handle it in main, or push the work to a workqueue instead.&lt;/p&gt;
&lt;p&gt;Note that all socket operations will trigger an interrupt to communicate with the modem, so no socket functions should be called from an interrupt.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/245926?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 00:51:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75424fae-86ad-4f0b-8768-24b3f20246db</guid><dc:creator>Hoang</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/hkn"&gt;Håkon Alseth&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="201" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1587515724371v1.png" width="506" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;1. accelerate trigger will :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.1. Reset the timer: Timer&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.2. Start the timer: Timer&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;2. If the Timer &amp;gt; 5mn (no motion in 5mn) --&amp;gt;Stop --&amp;gt; enable GPS to find Stop-Position&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, I need a function for the timer , and i found :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/59950/timers-in-nrf9160-soc/244049#244049"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/59950/timers-in-nrf9160-soc/244049#244049&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And, i modified the timer_cb() to test:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
void timer_cb(nrf_timer_event_t event_type, void * p_context) {
    printk(&amp;quot;start GPS ..\n&amp;quot;);
    gps_control_init(&amp;amp;application_work_q, gps_trigger_handler);
    printk(&amp;quot;set_gps_enable----------\r&amp;quot;);
    set_gps_enable(true);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;i want i can start the GPS, but I got the error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;start GPS ..
 gps_control_init(struct k_work_q  gps_trigger_handler_t handler 

 device_get_binding ---------- 

 gps_trigger_set ---------- 

ASSERTION FAIL [!arch_is_in_isr()] @ C:/Demos/nordic/ncs_09032020/zephyr/kernel/include/ksched.h:269
	
[00:00:01.542,327] [1B][1;31m&amp;lt;err&amp;gt; os: r0/a1:  0x00000004  r1/a2:  0x0000010d  r2/a3:  0x00000001[1B][0m
[00:00:01.551,177] [1B][1;31m&amp;lt;err&amp;gt; os: r3/a4:  0x40008000 r12/ip:  0x00000000 r14/lr:  0x0002e7cb[1B][0m
[00:00:01.560,058] [1B][1;31m&amp;lt;err&amp;gt; os:  xpsr:  0x6100001f[1B][0m
[00:00:01.565,368] [1B][1;31m&amp;lt;err&amp;gt; os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[1B][0m
[00:00:01.575,988] [1B][1;31m&amp;lt;err&amp;gt; os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[1B][0m
[00:00:01.586,639] [1B][1;31m&amp;lt;err&amp;gt; os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[1B][0m
[00:00:01.597,259] [1B][1;31m&amp;lt;err&amp;gt; os: s[12]:  0x00000000  s[13]:  0x00000002  s[14]:  0x00000000  s[15]:  0x00000000[1B][0m
[00:00:01.607,910] [1B][1;31m&amp;lt;err&amp;gt; os: fpscr:  0x4000f000[1B][0m
[00:00:01.613,220] [1B][1;31m&amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00033284[1B][0m
[00:00:01.621,307] [1B][1;31m&amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0[1B][0m
[00:00:01.629,180] [1B][1;31m&amp;lt;err&amp;gt; os: Fault during interrupt handling
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;How can I use the timer to start the GPS?&lt;/p&gt;
&lt;p&gt;Do you have any suggestions?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks so much&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/245822?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 11:17:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:517d6865-ffb0-4d4e-9018-3c5dc4032808</guid><dc:creator>Hoang</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/60377/acceleration-active-and-deactivate-gps/245724"]How&amp;nbsp;do you define the &amp;quot;STOP&amp;quot; position? Is it to be detected based on a sensor event, or a timeout event? How to distinguish a stop at a traffic light vs. an actual stop?[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried to use the timeout event, for example in 1mn, if no motion --&amp;gt; actual stop&amp;nbsp;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/60377/acceleration-active-and-deactivate-gps/245724"]One way of doing this can be: if&amp;nbsp;you store the time since last registered movement,&amp;nbsp;then start the GPS a given amount of time after the last movement was detected.[/quote]
&lt;p&gt;Ja,&amp;nbsp; I will try this one &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&amp;nbsp;&lt;/p&gt;
&lt;p&gt;BR&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/245724?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 07:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80dc5ebe-818c-418f-8488-fb648e2a911d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How&amp;nbsp;do you define the &amp;quot;STOP&amp;quot; position? Is it to be detected based on a sensor event, or a timeout event? How to distinguish a stop at a traffic light vs. an actual stop?&lt;/p&gt;
&lt;p&gt;One way of doing this can be: if&amp;nbsp;you store the time since last registered movement,&amp;nbsp;then start the GPS a given amount of time after the last movement was detected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/245658?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 19:58:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44e88302-ce96-4692-a043-68c32080f1c1</guid><dc:creator>Hoang</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/60377/acceleration-active-and-deactivate-gps/245557"]Do you want to stop the GPS, or start it again? These two functions enable/disable the gps_controller[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I want to start GPS again. For example, my thingy:91 is staying in my car, when the car is moving: start GPS and capture the start-Position, then stop GPS. When the car stops, start GPS again, and capture the stop-Position. During the moving time of the car, the THINGY:91 will sleep (to save the power), it just captures 2 positions: start and stop position.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Acceleration active and deactivate GPS</title><link>https://devzone.nordicsemi.com/thread/245557?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 13:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:250daf57-5044-4816-94c3-dcddf2451457</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]But, I dont know how to implement the step 2:&amp;nbsp;&amp;nbsp;&lt;span&gt;when it stops, GPS will be activated again: Position-OFF&lt;/span&gt;[/quote]
&lt;p&gt;Do you want to stop the GPS, or start it again? These two functions enable/disable the gps_controller library:&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/applications/asset_tracker/src/gps_controller/gps_controller.c#L125-L133"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/applications/asset_tracker/src/gps_controller/gps_controller.c#L125-L133&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re using asset_tracker, as-is, you can also look at this function:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/applications/asset_tracker/src/main.c#L1221"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/applications/asset_tracker/src/main.c#L1221&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>