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.
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
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