Hi: I want to capture the parameter of a digital wave like this, I want to get every 't' value. The wave is same in a period of time, but the 51822 capture value of 't' is shaking(the right value is 1500us,and 51822 capture value is 1400 to 1600us random ). I use nrf_drv_gpiote and nrf_drv_timer.My code is as follow. Can you give me some suggestions.
function inital
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);
nrf_drv_gpiote_init();
const nrf_drv_gpiote_in_config_t GP_config =
{
NRF_GPIOTE_POLARITY_HITOLO,
NRF_GPIO_PIN_PULLUP,
false,
true
};
nrf_drv_gpiote_in_init(PPM_pin, &GP_config, pin_event_handler);
nrf_drv_gpiote_in_event_addr_get(PPM_pin);
nrf_drv_gpiote_in_event_enable(PPM_pin, true);
const nrf_drv_timer_config_t TI_config =
{
NRF_TIMER_FREQ_1MHz,
NRF_TIMER_MODE_TIMER,
NRF_TIMER_BIT_WIDTH_32,
0,
NULL
};
nrf_drv_timer_init(&TIMER_LED, &TI_config, timer_led_event_handler); nrf_drv_timer_enable(&TIMER_LED);
void pin_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
static uint32_t ftime=0,stime=0;
static uint8_t ch_num = 0;
if((pin == PPM_pin) && (action == NRF_GPIOTE_POLARITY_HITOLO))
{
ftime = nrf_drv_timer_capture(&TIMER_LED,NRF_TIMER_CC_CHANNEL3);
//printf("%d\n\r",ftime);
dtime = ftime - stime;
//printf("%d\n\r",dtime);
//stime = ftime;
if(dtime > 2550)
{
ch_num = 0;
}
else
{
Channel_data[ch_num] = dtime;
ch_num++;
}
nrf_gpio_pin_toggle(25);
stime = nrf_drv_timer_capture(&TIMER_LED,NRF_TIMER_CC_CHANNEL3);
}
//NRF_GPIOTE->EVENTS_IN[0] = 0;
}
PS: the dtime is the value I want. Please give me some suggestion. Thank you!