hello Nordics,
i am trying to configure 1ms timer along with BLE_STACK is enable and same time i am sending 3byte data for every 500ms . and 1ms timer is very important for me bcoz entire projects depends on this timer and BLE COMMUNICATION also necessary . but i am suffering with timer bcoz mostly i am getting 0.4-0.8 ms error and bcoz of this error my all calculation giving wrong answer ,and this calculation is depends on time below my timer configuration code is there ,im not sure its 100% correct or not .
and im using s110 SD and NRF51822 core
/* This is timer 2 initialization for 1millisecond*/
void start_timer2(void)
{ NRF_TIMER2->TASKS_STOP = 1; NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // Set the timer in Counter Mode NRF_TIMER2->TASKS_CLEAR = 1; // clear the task first to be usable for later NRF_TIMER2->PRESCALER = 4; //Set prescaler. Higher number gives NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit; NRF_TIMER2->CC[0] = 1000; //Set value for TIMER2 compare register 0 for 1ms // Enable interrupt on Timer 2, for CC[0]compare match events NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos) ; NVIC_SetPriority(TIMER2_IRQn, NRF_APP_PRIORITY_LOW); NVIC_EnableIRQ(TIMER2_IRQn); }
and this my interrupt handler function
void TIMER2_IRQHandler(void)
{ if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0) && ((NRF_TIMER2->INTENSET &TIMER_INTENSET_COMPARE0_Msk) != 0)) { NRF_TIMER2->EVENTS_COMPARE[0] = 0; //Clear compare register 0 event
NRF_TIMER2->TASKS_CLEAR = 1;
nrf_gpio_pin_toggle(19);
if (flags.start) //check the flags.start_bp
{
tmr2_counter+=1;
cur_ac_val=Monitor_AC_Signal();//read the ac sample
cur_dc_val=Monitor_DC_Signal();//read the dc sample
battery_level=Monitor_BAT_Signal();//read the battery adc signal
// and above 3 statements taking around 400us time
}
}
}