MKM34Z256VLx7 Bare Metal Software Drivers  R4.1.6
Reference Manual
LPTMR Periodic Wakeup

This example shows use of the Low-Power Timer (LPTMR) in energy saving application. The device is placed in either Very Low Power Wait (VLPW) or Very Low Power Stop (VLPS) mode most of the time. It resumes operation when LPTMR interrupt is asserted. The LPTMR is programmed to reset and assert interrupt request when value of counter (CNR) is equal to compare (CMR) and increments. Timer is controlled by internal 1 kHz low power clock and compare (CMR) is set to generate interrupt event every 8 seconds.

Source code:
/******************************************************************************
* (c) Copyright 2010-2015, Freescale Semiconductor Inc.
* ALL RIGHTS RESERVED.
******************************************************************************
* lptmrisr_test.c
******************************************************************************/
#include "drivers.h"
/* LPTMR callback function declaration */
static void lptmr_callback (void);
/* static data definition */
static volatile uint16 counter;
void main (void)
{
/* core, bus and flash clock = 1000 KHz */
/* enable clock to LPTMR on-chip peripheral */
/* enable low voltage reset detection (1.6V), disable interrupts and bandgap*/
/* enable transitions for VLPR and VLPS mode */
OSC32K_Disable (); /* disable OSC32K oscillator */
SMC_SetMode(VLPR); /* enter VLPR mode to minimize current consumption */
/* initialize LPTMR in counter reset mode */
LPTMR_InstallCallback (PRI_LVL1, lptmr_callback);
EnableInterrupts(); /* enable interrupts on global level */
LPTMR_Enable(); /* enable LPTMR (8000ms interrupt) */
while (1)
{
SMC_SetMode(VLPW); /* keep staying in VLPW mode; IDD+IDDA+IBAT=103.0uA */
SMC_SetMode(VLPS); /* keep staying in VLPS mode; IDD+IDDA+IBAT=5.7uA */
}
}
/* LPTMR interrupt - called every 8000 ms */
static void lptmr_callback (void)
{
counter++; /* increment variable; IDD+IDDA+IBAT=151uA */
arch_delay(4000000); /* wait for 4000 ms */
}
Toolchain support:
IAR EWARM 7.40.7KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0