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

Timer/Counter configuration issues

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:

I have the following parameters that relate to Timer/counter configured in sdk_config.h as follows:

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. 

Parents
  • It sounds like the SoftDevice is using timer0, try initializing your interrupt to use timer1 instead.

  • Does my configuration not do just that?

  • LINE 737 in Main,

    Comment that out, and uncomment the same function inside the if statement, then reset the kickout value to 750, this should fix your problem.

  • How so? All I am doing is toggling a pin to verify how often the interrupt handler fires. With  uint32_t time_ms = 50; //Time(in miliseconds)  I should see pulse widths of 50ms not 4ms. Am I missing something? The interrupt handler words, just doesn't fire at the configured rate. 

  • nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;

    put this in, then try it.

    If the toggle time changes you'll have to do something similar to what was attempted in the timer handler with the kickout variable.

    I was grabbing at straws which weren't even there in that last message.

  • nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; already configures the bit width to 32-bits as this is the default configuration but I treid it anyway. Still no dice. 

  • What SDK version are you using?

    my value for NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH is 0, which corresponds to 16 bit timer widths.

    I don't know what the problem could be.

    Do you have any ideas on this?

Reply Children
  • I'm using Keil uVision. Thats likely bc the your directories are set up differently. 

    Also, NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH? I don't see that #define anywhere in my Project. I have TIMER_DEFAULT_CONFIG_BIT_WIDTH and thats set to 3 in sdk_config.h

  • Whats also puzzling is that upon debugging I can see that I am writing 800,000 dec to CC[1] which is 0xC3500 yet the register only gets 0x03500 which is indicative of TIMER_BIT_WIDTH being set to 16-bits but it is clearly configured to 32-bits.