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

	}
}

}

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

  • Hi Hung bui, Thank you somuch for ur rply, My IC Packet/variant code is QFAAGO and I am using s110_nrf51822_7.1.0_softdevice . I measured interrupt handler time its taking around 800us (around 250us for ADC + 500us algorithm ). now I removed algorithm function from timer handler , So its taking around 240us. Bt now I am getting new problem for every 20ms I am getting around 1.5ms error in timer handler and I have no idea how its coming ? I sated Connection interval time for min = 10ms and max = 75ms. and advertising interval = 40ms

  • @twinkal: How do you measure the 1.5ms error ? Could you toggle a pin and have a trace with the logic analyzer. Please be noted that since your chip is XLR2, the CPU is blocked by the radio, so you could have upto 6ms interrupt latency for the timer handler.

  • Hello,

    Thank u somuch for ur consultation , I am toggling a pin to measure time ( capturing to Pico scope and Tektronix both) ,is it a correct way to do? and one more thing from where I have to get this XLR3 chip (means from where I have to buy or in my case which is the best chip I should use ?)

    Once again thank you very much !

  • @twinkal: Yes it's a correct way. You can get XLR3 chip on our nRF51 DK or nRF51 Dongle. For example here.
    Please contact our distributors of your area for more information. The distributors list can be found on our website (at the bottom of the page).

Related