This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

APP_TIMER is not functioning.

Hello

Created in SDK v17 and simple_timer example.
I made a simple code to control the LED using a timer. Every 500 milliseconds, the LED turns on sequentially. LED ON and OFF works well when running one line at a time with debug, but the timer doesn't seem to be running.
In sdk_config.h, APP_TIMER_ENABLE is set to 1.

#include "app_timer.h"
#include <stdio.h>
#include "boards.h"
#include "app_error.h"
#include "nrf_delay.h"

#define TIMEOUT_VALUE                    50000                          /**< 50 mseconds timer time-out value. */
#define TOGGLE_LED_COUNTER               (500 / (TIMEOUT_VALUE / 1000)) /**< Interval for toggling a LED. Yields to 500 mseconds. */
#define STATE_TRANSIT_COUNTER_INIT_VALUE (4 * TOGGLE_LED_COUNTER)       /**< Initial value for the state transition counter.  */
#define GENERIC_DELAY_TIME               1000                           /**< Generic delay time used by application. */


APP_TIMER_DEF(m_timer_id);

void gpio_init(void)
{
  nrf_gpio_cfg_output(BSP_LED_0); //board_led1
  nrf_gpio_pin_set(BSP_LED_0);

  nrf_gpio_cfg_output(BSP_LED_1); //board_led2
  nrf_gpio_pin_set(BSP_LED_1);

  nrf_gpio_cfg_output(BSP_LED_2); //board_led3
  nrf_gpio_pin_set(BSP_LED_2);

  nrf_gpio_cfg_output(BSP_LED_3); //board_led4
  nrf_gpio_pin_set(BSP_LED_3);
}


char Move_LED[] = {BSP_LED_0, BSP_LED_1, BSP_LED_2, BSP_LED_3};


static void timer_handler(void * p_context)
{
    nrf_gpio_pin_toggle(BSP_LED_3);  //0.5 sec toggle
}


static void timers_init(void)
{
    ret_code_t err_code;

    // Initialize timer module.
    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&m_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT, //SINGLE_SHOT or REPEATED //single shot timer
                                timer_handler);   
    APP_ERROR_CHECK(err_code); 
}


static void timer_start()
{
    ret_code_t err_code;

    // Start application timers.
    err_code = app_timer_start(m_timer_id, APP_TIMER_TICKS(500), NULL); //0.5sec delay
    APP_ERROR_CHECK(err_code);
}


static void move()
{
      for(int i=0; i<5; i++)
      {
        nrf_gpio_pin_set(BSP_LED_0); //led off
        nrf_gpio_pin_set(BSP_LED_1);
        nrf_gpio_pin_set(BSP_LED_2);
        
        timer_start();
        nrf_gpio_pin_clear(BSP_LED_0);
        timer_start();
        nrf_gpio_pin_clear(BSP_LED_1);
        timer_start();
        nrf_gpio_pin_clear(BSP_LED_2);
        timer_start();
      }
            
    /*for(int i=0; i<5; i++) //not output
    {
      nrf_gpio_pin_set(BSP_LED_0); //led off
      nrf_gpio_pin_set(BSP_LED_1);
      nrf_gpio_pin_set(BSP_LED_2);

      for(int j=0; j<3; j++)
      {
        nrf_gpio_pin_set(Move_LED[i]);
        timer_start();
      }
    }*/
}


/**@brief Function for the Power Management.
 */
static void power_manage(void)
{
    // Use directly __WFE and __SEV macros since the SoftDevice is not available.

    // Wait for event.
    __WFE();

    // Clear Event Register.
    __SEV();
    __WFE();
}


int main(void)
{
    timers_init();
    gpio_init(); 

    nrf_gpio_pin_set(BSP_LED_0); //led off
    nrf_gpio_pin_set(BSP_LED_1);
    nrf_gpio_pin_set(BSP_LED_2);

    //move();

    for (;;)
    {
        power_manage();
        move();
    }
}

Can I know the problem?


Thank you.

Parents Reply Children
No Data
Related