request application time for micros() or interrupt function with timer nRF Connect / timer0, interrupt, alarm

Hello,

I changed saadc.zip for my application needs 

nrfx_saadc - buildconf. error PPI_CHEN / DPPIC_CHEN 

and would like to plot the incoming serial data from ADC as asked in 

Provide data from .c file to .py file VS Code - matplotlib.pyplot 

For time evaluation I would like to have some arduino style millis() or micros() function, or even application time like app_timer_cnt_get(). Unfortunately this function isnt available in nrf connect sdk.

I used counter/alarm example and insert              CONFIG_COUNTER_TIMER1=y             to prj.conf.

Now whats confusing me is the now_usec output in the serial monitor. The code is

static void test_counter_interrupt_fn1(const struct device *counter_dev,
				      uint8_t chan_id, uint32_t ticks,
				      void *user_data)
{
	struct counter_alarm_cfg *config = user_data;
	uint32_t now_ticks;
	uint64_t now_usec;
	int now_sec;
	int err;

	err = counter_get_value(counter_dev, &now_ticks);
	if (err) {
		printk("Failed to read counter value (err %d)", err);
		return;
	}

	now_usec = counter_ticks_to_us(counter_dev, now_ticks);
	// printk("now_usec = ");
	// printk(now_usec);
	// printk("\n");
	now_sec = (int)(now_usec / USEC_PER_SEC);
	//now_usec = (int)now_usec;
	printk("!!! Alarm 1 !!!\n");
	printk("Now usec: %u\n", now_usec);
	printk("Now sec: %u\n", now_sec);

	/* Set a new alarm with a double length duration */
	//config->ticks = config->ticks;	// * 2U;

	// printk("Set alarm in %u sec (%u ticks)\n",
	//        (uint32_t)(counter_ticks_to_us(counter_dev,
	// 				   config->ticks) / USEC_PER_SEC),
	//        config->ticks);

	err = counter_set_channel_alarm(counter_dev, ALARM_CHANNEL_ID,
					user_data);
	if (err != 0) {
		printk("Alarm could not be set\n");
	}
}

When I set the channel alarm I get the output "Set alarm in 2 sec (32 000 000 ticks), but every 2 sec interrupt in the code above outputs

Now usec: 536870968

Now sec: 2

or 

Now usec: 536870968

Now sec: 4

Is there a more convenient way to get the application time or to measure passed timer for evaluate the time step between two ADC samples? 

Like arduino code

if( (millis() - prevTime) >= DELAYTIME  ) {
    prevTime = millis();
    //do smthg
}

Thank you in advance for any help,
Christoph
Parents Reply Children
Related