Constantin
Well-known member
Silly Question re: a higher-resolution micros() function
Hi guys,
You may or may not have followed my travails in the TXCO hilarity thread and I'm wondering whether a higher-resolution version of micros() may help resolve remaining errors in the compensation function. My computer hunted down the following in the Teensy core that presumably figures out what micros() is.
Naturally, I managed to first mistakenly look into the original Teensy core, which explains the assembly language I found. Looking in the correct directory (i.e. teensy3), the computer found the following
In teensy3/core_pins.h:
and in teensy3/pins_teensy.c:
where in Teensy3/kinetis.h:
I wonder if anyone here has the experience to suggest a way to achieve a function that can measure time down to 1/10th of a micro-second. If not, no worries. Time to curl up with the reference manual... Have a great and happy new year everyone!
Hi guys,
You may or may not have followed my travails in the TXCO hilarity thread and I'm wondering whether a higher-resolution version of micros() may help resolve remaining errors in the compensation function. My computer hunted down the following in the Teensy core that presumably figures out what micros() is.
Naturally, I managed to first mistakenly look into the original Teensy core, which explains the assembly language I found. Looking in the correct directory (i.e. teensy3), the computer found the following
In teensy3/core_pins.h:
Code:
uint32_t micros(void);
and in teensy3/pins_teensy.c:
Code:
uint32_t micros(void)
{
uint32_t count, current, istatus;
__disable_irq();
current = SYST_CVR;
count = systick_millis_count;
istatus = SCB_ICSR; // bit 26 indicates if systick exception pending
__enable_irq();
//systick_current = current;
//systick_count = count;
//systick_istatus = istatus & SCB_ICSR_PENDSTSET ? 1 : 0;
if ((istatus & SCB_ICSR_PENDSTSET) && current > 50) count++;
current = ((F_CPU / 1000) - 1) - current;
return count * 1000 + current / (F_CPU / 1000000);
}
where in Teensy3/kinetis.h:
Code:
// System Control Space (SCS), ARMv7 ref manual, B3.2, page 708
#define SCB_ICSR_PENDSTSET ((uint32_t)0x04000000)
#define SCB_ICSR (*(volatile uint32_t *)0xE000ED04) // Interrupt Control and State
#define SYST_CVR (*(volatile uint32_t *)0xE000E018) // SysTick Current Value
I wonder if anyone here has the experience to suggest a way to achieve a function that can measure time down to 1/10th of a micro-second. If not, no worries. Time to curl up with the reference manual... Have a great and happy new year everyone!
Last edited: