This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TIMER2 NOT working properly FOR 1MS interrupt with SD enable

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

	}
}

}

Parents
  • Hi Twinkal,

    Could you let me know which chip version you are testing on ? (you can match the version of the chip with the laser marking you can read on top of it here.

    If you are using XLR2 and earlier chip, the interrupt latency is expected as described at chapter 11 in the S110 Specification v1.3. As the CPU is blocked when the radio is active, the maximum latency could get to 5960us.

    On the current version of the chip, XLR3, the CPU is not blocked if you use S110 v7.1 and set the option with sd_ble_opt_set() (please the release note of S110 v7.1.0) , the interrupt latency with our calculation is 80us average, maximum 250us in most case, and in the worst case by theory it is about 510us.

    If the latency is limited to 510us and you have your interrupt handler takes less than 490us you should be fine with the 1ms timer.

Reply
  • Hi Twinkal,

    Could you let me know which chip version you are testing on ? (you can match the version of the chip with the laser marking you can read on top of it here.

    If you are using XLR2 and earlier chip, the interrupt latency is expected as described at chapter 11 in the S110 Specification v1.3. As the CPU is blocked when the radio is active, the maximum latency could get to 5960us.

    On the current version of the chip, XLR3, the CPU is not blocked if you use S110 v7.1 and set the option with sd_ble_opt_set() (please the release note of S110 v7.1.0) , the interrupt latency with our calculation is 80us average, maximum 250us in most case, and in the worst case by theory it is about 510us.

    If the latency is limited to 510us and you have your interrupt handler takes less than 490us you should be fine with the 1ms timer.

Children
Related