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

nRF52832 timer running fast

Doing development on nRF52 DK board using buttonless DFU example and SDK 17.0.2.  Running SES on Win10 and gnu compiler.

I've set up a 1 mS timer to run timing in my main loop.  I find that it runs too fast by about 0.7%.  This is unacceptable in my application.

Since the timer should be running off the crystal, it should be orders of magnitude more accurate than this. The fact that the bluetooth radio works tells me the crystal has to be about right.

Can anyone suggest what I might have missed in my setup?  I've commented out a lot of extraneous code (removed for clarity). Here's the actual code that's running.

Interestingly, I find that if I remove any of the initialization function calls that are still here, the app doesn't run.

#define mytimer NRF_TIMER2
#define Tick mytimer->EVENTS_COMPARE[0]
#pragma align 4(ADCdata)
int16_t ADCdata[24];
uint16_t ADCstate;
int16_t V1, V2, V3, V4, V5, V6;

void AppInit(void)
	{
	//set up hardware needed for application 

	/* setup timer for compare event every 1ms */
	mytimer->CC[0] = 1000ul;
	//MODE  - use default setting (timer)
	//BITMODE - use default setting (16 bits)
	//PRESCALER - use default setting (16:1 for 1 MHz)
	//INTENSET  - use default setting (no interrupts)
	mytimer->SHORTS = 1;  //SHORTCUT from COMPARE[0] to TASK_CLEAR
	mytimer->TASKS_START = 1;
	}

int main(void)
 	{
	bool		 erase_bonds;
	ret_code_t err_code;

	log_init();

	timers_init();
	
	buttons_leds_init(&erase_bonds);
	ble_stack_init();

	BLUESTREAK_BLE_INIT();

	peer_manager_init();
//	gap_params_init();
//	gatt_init();

	advertising_init();
	services_init();
//	conn_params_init();

	NRF_LOG_INFO("Buttonless DFU Application started.");

	// Start execution.
	application_timers_start();

	AppInit();	  //enable 1mS tick, ADC


	// Enter main loop.
	for (;;)
		{

		NRF_LOG_PROCESS();
		if(m_advertising.adv_mode_current == BLE_ADV_MODE_IDLE && bs_ready())
			advertising_start();


		if(Tick)
			{
			Tick = 0;
			MsCtr++;
			if(MsCtr >= 1000)
				MsCtr = 0;

			switch(MsCtr)
				{
				case 0:
					SecCtr++;
					if(SecCtr > 86399) SecCtr = 0;

					bsp_board_led_on(1);
					
					break;
				case 500:
					bsp_board_led_off(1);
					break;

				}
			}
		}
	}

Top Replies

Parents Reply Children
No Data
Related