I am new to nrf52.
I want to configure TIMER1 as a counter.
However it does not count. I have added it after advertisement_init
Does the nrf52 have any such limitations? How to handle them?
I am new to nrf52.
I want to configure TIMER1 as a counter.
However it does not count. I have added it after advertisement_init
Does the nrf52 have any such limitations? How to handle them?
Hello,
I am new to nrf52.
Welcome!
I want to configure TIMER1 as a counter.
However it does not count. I have added it after advertisement_init
Does the nrf52 have any such limitations? How to handle them?
No, there are no such limitations. However, please be aware that the SoftDevice ( if present and enabled ) will wrest control of the CPU to run timing-critical code.
When in a BLE connection, this means that every connection interval, the CPU will be controlled by the SoftDevice.
The SoftDevice has the highest priority, and thus takes priority over any application layer tasks.
With that being said, could you show me how you are initializing your timer? I see from the screenshot you have shared that you are calling TASKS_START, but how is the timer configured prior to this?
If the configuration is incorrect or missing, I would expect that the timer does not start.
Furthermore, what are you here trying to have your code do? I see that you highlight the LED1 PIN CLEAR code line in your screenshot - but this is not related to the timer in any way. I also see that you are calling a read_freq function in your for-loop, but I do not know anything about what that is meant to do.
If my assumption is correct, and you would like to have the LED controlled by the TIMER, then I highly recommend taking a look at the TIMER example from the SDK - it demonstrates exactly how to connect a LED toggle with a timer.
Please do not hesitate to ask if you should encounter any issues or questions!
Best regards,
Karl
Hello. The following are my function calls:
How to find if the code uses soft device?
I am editing the existing BPS example. I have added the following code to it.
static void hfclk_config(void)
{
ret_code_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
nrf_drv_clock_hfclk_request(NULL);
}
static void counter_init()
{
// Initialize timer module.
NRF_TIMER1->TASKS_STOP = 1;
NRF_TIMER1->MODE = TIMER_MODE_MODE_Counter;
NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
NRF_TIMER1->TASKS_COUNT;
}
static void read_freq(void)
{
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->TASKS_CAPTURE[1] = 1 ;
counter = NRF_TIMER1->CC[1];
NRF_LOG_INFO("Went here");
//NRF_LOG_INFO(counter);
while(counter < 100000)
{
counter = NRF_TIMER1->CC[1];
while(!(nrf_gpio_pin_read(BTN)));
while((nrf_gpio_pin_read(BTN)));
increment++;
//NRF_LOG_INFO("Went here");
}
freq = increment;
increment = 0;
//NRF_LOG_INFO(freq);
}
int main(void)
{
hfclk_config();
counter_init();
NRF_TIMER1->TASKS_START = 1;
for (;;)
{
read_freq();
//idle_state_handle();
}
}
You can ignore the LED part. I am just using it as a debug point.
I see that clock has been started:
Timer mode has been set to 1.
But the CC values are empty. They are not getting incremented.
Hello. The following are my function calls:
How to find if the code uses soft device?
I am editing the existing BPS example. I have added the following code to it.
static void hfclk_config(void)
{
ret_code_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
nrf_drv_clock_hfclk_request(NULL);
}
static void counter_init()
{
// Initialize timer module.
NRF_TIMER1->TASKS_STOP = 1;
NRF_TIMER1->MODE = TIMER_MODE_MODE_Counter;
NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
NRF_TIMER1->TASKS_COUNT;
}
static void read_freq(void)
{
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->TASKS_CAPTURE[1] = 1 ;
counter = NRF_TIMER1->CC[1];
NRF_LOG_INFO("Went here");
//NRF_LOG_INFO(counter);
while(counter < 100000)
{
counter = NRF_TIMER1->CC[1];
while(!(nrf_gpio_pin_read(BTN)));
while((nrf_gpio_pin_read(BTN)));
increment++;
//NRF_LOG_INFO("Went here");
}
freq = increment;
increment = 0;
//NRF_LOG_INFO(freq);
}
int main(void)
{
hfclk_config();
counter_init();
NRF_TIMER1->TASKS_START = 1;
for (;;)
{
read_freq();
//idle_state_handle();
}
}
You can ignore the LED part. I am just using it as a debug point.
I see that clock has been started:
Timer mode has been set to 1.
But the CC values are empty. They are not getting incremented.
Hello,
Raja Sumant said:How to find if the code uses soft device?
If you are doing BLE communication, then the SoftDevice is present and enabled.
From the screenshots you have shared this seems to be the case, since you are using the ble_app_bps example from the SDK as your basis.
Is there a particular reason for why you are accessing the timer registers directly, instead of using the drivers provided with the SDK?
If all you want to do is create a simple timer, then I highly recommend the Application Timer Library, or the TIMER peripheral driver.
For future reference, I would recommend that you use the " Insert -> Code " option when sharing code in the forum. This drastically increases readability.
Best regards,
Karl