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

Change to use Timer1 of timer example,it failed.

[test result] change to use Timer1 of timer example,it failed. if you use timer0, it is OK..

SDK IS 9.0: nRF51_SDK_9.0.0_2e23562\examples\peripheral\timer

[test step] 1, test timer0, it is ok. 2. i want to test of timer1, so i change the demo code and config Timer1 enable in the configuation.,

the main.c code is the following.

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);

const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

/**

  • @brief Handler for timer events. */

void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)

{

static uint32_t i;

uint32_t led_to_invert = (1 << leds_list[(i++) % LEDS_NUMBER]);

switch(event_type)
{
    case NRF_TIMER_EVENT_COMPARE0:
        LEDS_INVERT(led_to_invert);
        printf("=== compare0 event =====\r\n");
        break;
    
    default:
        //Do nothing.
        break;
}    

}

/**

  • @brief Function for main application entry. */

int main(void)

{

uint32_t time_ms = 1000; //Time(in miliseconds) between consecutive compare events. uint32_t time_ticks; uint32_t err_code = NRF_SUCCESS;

//init log modify by jack.
app_trace_init();

//Configure all leds on board.
LEDS_CONFIGURE(LEDS_MASK);
LEDS_OFF(LEDS_MASK);

//Configure TIMER_LED for generating simple light effect - 

//leds on board will invert his state one after the other. err_code = nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler); APP_ERROR_CHECK(err_code);

time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

//print the log of time_ticks;
app_trace_log("====== time_ticks is : %d ======\r\n",time_ticks);

nrf_drv_timer_extended_compare(
     &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

nrf_drv_timer_enable(&TIMER_LED); 

while(1)
{
    __WFI();
} 

}

[test log of Timer1]: when running ,and reset board, log message is the following. i found that cc value is not ok after write cc[channel]. and compare0 event is trigged without 1000ms time interval.. just because it print so fast, the log message has some wrong.

================


prescaler_value is 0 ====== time_ticks is : 16000000 ====== cc_write cc_value = 16000000, cc_channel = 0 before write. read cc_value of cc_channel: 9216 after write === compare0 event ===== === compare0 event ===== === compare0 event ===== === compare0 eve========================

=========================================

this is a test


prescaler_value is 0 ====== time_ticks is : 16000000 ====== cc_write cc_value = 16000000, cc_channel = 0 before write. read cc_value of cc_channel: 9216 after write === compare0 event =====

=== compare0 event =====

=== compare0 event =====

=== compare0 eve===============

**and I change to another cc-channel=1, the same problem appear.

CC_Value= 0x00F42400, But write to CC[1], it became 0x00002400,**

image description

[test log of Timer0]: test timer0, it is ok, and cc value is good.

and compare0 event is trigged.

and clear task of short work fine. print the message one by one after 1000ms.

this is a test


prescaler_value is 0

====== time_ticks is : 16000000 ======

cc_write cc_value = 16000000, cc_channel = 0 before write.

read cc_value of cc_channel: 16000000 after write

=== compare0 event =====

=== compare0 event =====

=== compare0 event =====

=== compare0 event =====

Parents
  • You are aware that timer0 is the only one that has the 24 bit and 32 bit modes? The others are limited to 8 and 16 bit modes. This caught me out once.

  • thanks a lot.. in the file of nrf_drv_config.h, it has detail configuration of timers..

    Timer0 has 32bits width, Timer1 and Timer2 have 16 bits width.. So when you use timer,

    nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler), maybe it is not good for us,

    it will use default configuration by using NULL, it use 16MHz , prescaler = 0, as default; 1 tick= 0.0625 us, the time of 1 tick is so small, As result , total ticks of time you set are so large, maybe the length of

    this number is longer than 16bits . So my problem appeared.. thank JohnBrown .

Reply
  • thanks a lot.. in the file of nrf_drv_config.h, it has detail configuration of timers..

    Timer0 has 32bits width, Timer1 and Timer2 have 16 bits width.. So when you use timer,

    nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler), maybe it is not good for us,

    it will use default configuration by using NULL, it use 16MHz , prescaler = 0, as default; 1 tick= 0.0625 us, the time of 1 tick is so small, As result , total ticks of time you set are so large, maybe the length of

    this number is longer than 16bits . So my problem appeared.. thank JohnBrown .

Children
No Data
Related