tom dunigan
/
k64f_rtcisr
measure RTC crystal freqeuncy against MCU crystal
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // k64f rtcisr 00002 // seconds interrupt from RTC compare micros() to check RTC frequency 00003 #include "mbed.h" 00004 00005 #define micros tmr.read_us 00006 00007 DigitalOut led(LED_RED); 00008 Timer tmr; 00009 00010 volatile static unsigned long ticks,us; 00011 static unsigned long us0=0; 00012 00013 extern "C" void RTC_Seconds_IRQHandler() { 00014 if (us0 == 0) us0 = micros(); 00015 else { 00016 ticks++; 00017 us = micros() - us0; 00018 } 00019 led = !led; // toggle led 00020 } 00021 00022 int main(){ 00023 int ppm, tprev=0; 00024 00025 tmr.start(); // for micros 00026 time(NULL); // start RTC 00027 RTC_IER = 0x10 ; //TSIE enable seconds interrupt 00028 NVIC_EnableIRQ(RTC_Seconds_IRQn); 00029 while (true) { 00030 ppm = 1000000*ticks - us; 00031 ppm = 1.e6 * ppm/ (float)us; 00032 printf("%d %d %f %d\n",ticks,ticks-tprev,us*1.e-6,ppm); 00033 wait(2.0); 00034 } 00035 }
Generated on Sat Jul 23 2022 13:20:47 by 1.7.2