How can i set a timer in my project?

Hello everyone,

I want to be able to set a timer in my project. With this timer i want to be able to make my current comsumption evaluation easier.

I am using the nrf9160 DK.

I proceeded the following way:

#include <zephyr.h>
#include <stdio.h>
#include <nrf9160.h>
#include <device.h>

#define TIMER_INTERVAL_SEC 1

struct k_timer my_timer;

void my_expiry_function(struct k_timer *timer_id){};


void main(void){

        k_timer_init(&my_timer, my_expiry_function, NULL);
        k_timer_start(&my_timer, K_SECONDS(TIMER_INTERVAL_SEC), K_SECONDS(TIMER_INTERVAL_SEC));
        
}

unfortunately it is not working, can someone please help me resolve this issue?

Best regards,

Cedric

Parents
  • I tested your sample and was able to make it work

    • Extract the following project to ncs

    simple_timer.zip

    • Build it with the board nrf9160dk_nrf9160_ns
    • Open a serial terminal and you will see the following output:

    .
    .
    .
    .
    26 NRF_I2S              Non-Secure	OK
    27 NRF_GPIOTE1          Non-Secure	OK
    
    SPM: NS image at 0x10000
    SPM: NS MSP at 0x200159a0
    SPM: NS reset vector at 0x12379
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.6.99-ncs1  ***
    [00:00:00.205,627] [1B][0m<inf> asset_tracker: Timer sample started[1B][0m
    [00:00:01.205,688] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:02.205,718] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:03.205,688] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:04.205,749] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:05.205,688] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:06.205,718] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m
    [00:00:07.205,688] [1B][0m<inf> asset_tracker: Expiry function is running[1B][0m

    Best regards,

    Simon

  • Hi @Simon,

    Thanks your very much.

    BR,

    Cedric

Reply Children
No Data
Related