Hi Nordic,
I need to read pulse time which is microsecond level in different channel, I have consider combining timers with GPIOE but the timer is millisecond level. Is there any example to achieve it?
BTW, I'm using SDK17.02 on nRF52810.
Hi Nordic,
I need to read pulse time which is microsecond level in different channel, I have consider combining timers with GPIOE but the timer is millisecond level. Is there any example to achieve it?
BTW, I'm using SDK17.02 on nRF52810.
Hi. Share your timer init part of code please.
I'm using HID demo in SDK17.02.
static void timers_init(void)
{
ret_code_t err_code;
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
// Create battery timer.
err_code = app_timer_create(&m_battery_timer_id,
APP_TIMER_MODE_REPEATED,
battery_level_meas_timeout_handler);
APP_ERROR_CHECK(err_code);
}
And the APP_TIMER_TICKS(xx) is millisecond level.
I'm using HID demo in SDK17.02.
static void timers_init(void)
{
ret_code_t err_code;
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
// Create battery timer.
err_code = app_timer_create(&m_battery_timer_id,
APP_TIMER_MODE_REPEATED,
battery_level_meas_timeout_handler);
APP_ERROR_CHECK(err_code);
}
And the APP_TIMER_TICKS(xx) is millisecond level.
static const nrfx_timer_t micros_sample_timer = NRFX_TIMER_INSTANCE(4); //select timer instance
uint32_t micros;
static void micros_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
micros++;
}
static int timer_init_micros(void)
{
nrfx_err_t err;
nrfx_timer_config_t timer_cfg = {
.frequency = NRF_TIMER_FREQ_16MHz,
.mode = NRF_TIMER_MODE_TIMER,
.bit_width = NRF_TIMER_BIT_WIDTH_32,
};
err = nrfx_timer_init(µs_sample_timer, &timer_cfg, micros_timer_handler);
if (err != NRFX_SUCCESS) {
LOG_INF("nrfx_timer_init failed with: %d\n", err);
return -EAGAIN;
}
/* For Zephyr*/
/*
IRQ_CONNECT(DEFAULT_TIMER_IRQ, DEFAULT_TIMER_PRIORITY,
DEFAULT_TIMER_IRQ_HANDLER, NULL, 0);
*/
nrfx_timer_extended_compare(µs_sample_timer,
NRF_TIMER_CC_CHANNEL4,
nrfx_timer_us_to_ticks(µs_sample_timer, 1), // 1 us tic
NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK,
true);
nrfx_timer_enable(µs_sample_timer);
return 0;
}
use micros for pulse period calc
The app timer tick frequency depends on the config you set in sdk_config.h (APP_TIMER_CONFIG_RTC_FREQUENCY). If you set it to 0 you get the max tick rate of 32768 ticks per seconds which equals about 30.5us per tick.
You cannot use any ticks less than 5 in app_timer_start, so the shortest delay you can get is around 152.5us. Getting smaller than that using app_timer is not possible. You should try to use high frequency TIMERS instead for that.