Hello!
I compare the timer every 1ms and process it.
In order to check whether it can be executed every 1ms, I am going to refer to the register value by "TASKS_CAPTURE".
The description of the timer itself is as follows.
Timer 1 is used.
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&TIMER, &timer_cfg, timer_twi_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_us_to_ticks(&TIMER, time_us); nrf_drv_timer_extended_compare( &TIMER, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER);
The description of "TASKS_CAPTURE" is as follows.
void timer_twi_event_handler(nrf_timer_event_t event_type, void* p_context)
{
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE1:
if(j == 48){
j = 0;
}
NRF_TIMER1 -> TASKS_CAPTURE[0] = 1;
uint8_t caputured_value = NRF_TIMER1 -> CC[0];
flags = true;
time++;
//receive_data();
ret_code_t ret = nrf_drv_spi_xfer(&spi,&xfer_spi,flags);//Function for starting the SPI data transfer with additional option flags
if(ret == NRF_SUCCESS)
{
uint32_t start_tsk_addr = nrf_drv_spi_start_task_get(&spi);
}
if(j < 24){
//put_in_array(buf);
for(int a = 0; a < 20; a++){
buf[j*21+a] = mpu_buf[a];
}
buf[j*21+20] = caputured_value;
}else if(j >= 24){
//put_in_array(buf2);
for(int a = 0; a < 20; a++){
buf[j*21+a+8] = mpu_buf[a];
}
buf[j*21+20+8] = caputured_value;
}
j++;
//data_handler();
break;
default:
//Do nothing.
break;
}
}
The captured value is confirmed by writing to the SD card.
The values are always as follows:
253.00000
253.00000
253.00000
253.00000
253.00000
253.00000
255.00000
255.00000
228.00000
228.00000
255.00000
75.00000
255.00000
252.00000
252.00000
252.00000
252.00000
252.00000
252.00000
252.00000
This will be repeated.
Is my code something wrong?
Since "NRF_TIMER_CC_CHANNEL1" is used in the comparison, cc [0] is used when reading the register. Is this correct?
Please give me an answer.