Hello,
I am having an issue with setting up the event generation timing on the nRF51822. Long story short, I am configuring Timer/Counter 0 to generate an event every 50ms. I am using this to generate an emergency kick-out during data exchange between an external uController and the nRF51822. I am seeing the timer/counter generate an event every 4ms instead.
Now for a little background on my implementation. I am using the nRF51 development kit fly-wired to my external uController. I am building on the example implementation called ble_app_uart_pca10028_s130 using the s130 Bluetooth stack. This example did not have any of the 4 timer/counters enabled and implemented so to do so I referenced the timer_pca10028 example. I initialized timer/counter 0 in the following way:
const nrf_drv_timer_t TIMER = NRF_DRV_TIMER_INSTANCE(0); volatile uint16_t EmergencyKickOut; // Used an infinite loop bailout or a time delay /**@brief Application main function. */ int main(void) { uint32_t err_code; bool erase_bonds; uint32_t time_ms = 50; //Time(in miliseconds) between consecutive compare events. uint32_t time_ticks; /* Set up the P0.04 MP_INT as an input ready to receive data wakeup pin */ nrf_gpio_cfg_input(MP_INT, NRF_GPIO_PIN_NOPULL); /* Set up P0.05 BT_INT pin as MP wakeup pin */ nrf_gpio_cfg_output( BT_INT ); nrf_gpio_pin_write( BT_INT, PIN_LEVEL_LOW ); /* Set up P0.06 DEBUG_PIN_06 pin as debug pin */ nrf_gpio_cfg_output( DEBUG_PIN_06 ); nrf_gpio_pin_write( DEBUG_PIN_06, PIN_LEVEL_LOW ); // Initialize. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false); uart_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); //printf("\r\nUART Start!\r\n"); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Configure TIMER_COUNTER_1 nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&TIMER, &timer_cfg, timer_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER, time_ms); nrf_drv_timer_extended_compare(&TIMER, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER); // Enter main loop. for (;;) { power_manage(); } } /** * @brief Handler for timer events. */ void timer_event_handler(nrf_timer_event_t event_type, void* p_context) { nrf_gpio_pin_toggle( DEBUG_PIN_06 ); // debugging trace if ( EmergencyKickOut ) { EmergencyKickOut--; } }
I have the following parameters that relate to Timer/counter configured in sdk_config.h as follows:
// <e> TIMER_ENABLED - nrf_drv_timer - TIMER periperal driver //========================================================== #ifndef TIMER_ENABLED #define TIMER_ENABLED 1 #endif #if TIMER_ENABLED // <o> TIMER_DEFAULT_CONFIG_FREQUENCY - Timer frequency if in Timer mode // <0=> 16 MHz // <1=> 8 MHz // <2=> 4 MHz // <3=> 2 MHz // <4=> 1 MHz // <5=> 500 kHz // <6=> 250 kHz // <7=> 125 kHz // <8=> 62.5 kHz // <9=> 31.25 kHz #ifndef TIMER_DEFAULT_CONFIG_FREQUENCY #define TIMER_DEFAULT_CONFIG_FREQUENCY 0 #endif // <o> TIMER_DEFAULT_CONFIG_MODE - Timer mode or operation // <0=> Timer // <1=> Counter #ifndef TIMER_DEFAULT_CONFIG_MODE #define TIMER_DEFAULT_CONFIG_MODE 0 #endif // <o> TIMER_DEFAULT_CONFIG_BIT_WIDTH - Timer counter bit width // <0=> 16 bit // <1=> 8 bit // <2=> 24 bit // <3=> 32 bit #ifndef TIMER_DEFAULT_CONFIG_BIT_WIDTH #define TIMER_DEFAULT_CONFIG_BIT_WIDTH 3 #endif // <o> TIMER_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice // <0=> 0 (highest) // <1=> 1 // <2=> 2 // <3=> 3 #ifndef TIMER_DEFAULT_CONFIG_IRQ_PRIORITY #define TIMER_DEFAULT_CONFIG_IRQ_PRIORITY 1 #endif // <q> TIMER0_ENABLED - Enable TIMER0 instance #ifndef TIMER0_ENABLED #define TIMER0_ENABLED 1 #endif
I notice immediately upon flashing the nRF51 dev kit that it completely stops broadcasting Bluetooth. I have not taken time to debug exactly what occurs at this point but it seems that the application code in the nRF51822 has completely cratered at this point. Upon tinkering, I changed the implementation from using Timer/counter 0 to 1 and as soon as I did, it boot up and began executing as expected. The event generation works and I am able to use it as means to generate bailouts during inter-processor communication.
I am configuring the Timer/counter to generate events at a 50ms rate however my debugging trace on pin P0.06 tells me that it is instead banging away at 4ms instead. I am assuming that I am having some sort of cross peripheral conflict here. To be blunt, I am still very new to the nRF line and still learning as I go so some insight on how to properly configure these peripherals to be congruent with the intended output would be greatly appreciated.