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. 

  • any chance you might be able to point me to the prescalar definition?

  • See Chapter 18 of the nRF51 Reference Manual v3.0.1

    I see now that the value TIMER_DEFAULT_CONFIG_FREQUENCY is actually the value of the PRESCALER register and should yield a 16MHz timer in your application. 

    I need you to read out the value of the CC[0] register when the timer is running to verify that it is correctly set to 800 000dec. 

    EDIT:

    Are you using the SoftDevice? If so then you cannot use TIMER0 as it is used by the SoftDevice, see System on Chip resource requirementsHardware peripherals.

  • Yes I am using SoftDevice. I have made sure to switch to Timer 1 per your earlier instructions. I will get the value of CC[0] and get back to you. 

  •  I just took a look at the value of register CC[0] and as I stepped through the code while debugging, after executing the line

    CC[0] appears to contain the value 0x00003500 which is 13,568 dec. So I guess this is the discrepancy that we are seeing here. I see that time_ticks equates to 800,000 and is being passed as the cc_value argument to be written to register CC[0]. 800,000 dec = 0xC3500 in hex and what is actually making it into CC[0] is 0x3500. Somehow the 0xC0000 is being dropped. I tried simply forcing the value of CC[0] with the following code:

    But I end up in the Hard fault Handler. 

    Any ideas?

  • Yeah, I think the timer is configured for 16-bit only. What's the value of the BITMODE register?

1 2 3 4 5 »