/* ***************************************************************************** * gpt1_timer.c * * Create and manage GPT1 timer * free running 32 bit GPT timer * input = 24 MHz / 24 = 1.0 MHz * rollover: ~ 4295 seconds = ~ 71 minutes * resolution: 1 count = 1.000 micro seconds * * 1 second = 1,000,000 counts * 0.1 second = 100,000 * 0.01 seccond = 10,000 * 1 millisecond = 1,000 */ #include "fsl_common.h" #include "fsl_gpt.h" #include "gpt1_timer.h" void gpt1_init(void) { gpt_config_t gpt1Config; GPT_GetDefaultConfig(&gpt1Config); // The default values are: // config.clockSource = kGPT_ClockSource_Periph; // config.divider = 1U; // config.enableRunInStop = true; // config.enableRunInWait = true; // config.enableRunInDoze = false; // config.enableRunInDbg = false; // config.enableFreeRun = false; // config.enableMode = true; GPT_Init(GPT1, &gpt1Config); // Set config to defaults GPT_SetClockSource(GPT1, kGPT_ClockSource_Osc); // 24 MHz GPT_SetClockDivider(GPT1, 24); // Prescaler = 24 gpt1Config.enableFreeRun = true; // Free run gpt1Config.enableMode = false; // No reset of counter GPT_StartTimer(GPT1); // Start Timer } uint32_t us_count(void) { return GPT_GetCurrentTimerCount(GPT1); } // EoF =====-----