MKMxxZxxACxx5 Bare Metal Software Drivers  R4.1.6
Reference Manual
CMP Example

This example shows typical use of the Comparator (CMP) module.

Source code:
/******************************************************************************
* (c) Copyright 2010-2015, Freescale Semiconductor Inc.
* ALL RIGHTS RESERVED.
******************************************************************************
* cmp_test.c
******************************************************************************/
#include "drivers.h"
/* CMP callback declarations */
void cmp_callback (CMP_CALLBACK_SRC module, CMP_CALLBACK_TYPE type);
/* LEDs definition */
#define LED_G PIN5 /* PTE5 */
#define LED_R PIN1 /* PTF1 */
void main(void)
{
/* initialize SIM module */
/* clock mode 2:1:1, 48MHz */
/* PORTs init */
/* VREF module must be initialized after SIM module */
/* Comparator module initialized */
CMP_Init (CMP0,
CMP_MODULE_EN_FILTER7_SAMPLE_PER_255_DAC_EN_CONFIG_BOTH_EDGES(32),
IN0,
/* enable interrupts on global level */
/* main loop */
while(1);
}
/* CMP callbacks definitions */
void cmp_callback (CMP_CALLBACK_SRC module, CMP_CALLBACK_TYPE type)
{
if (module & CMP0_CALLBACK)
{
{
GPIO_Tgl (GPIOE, LED_G);
}
{
GPIO_Tgl (GPIOF, LED_R);
}
}
}
Toolchain support:
IAR EWARM 7.40.7CodeWarrior 10.6KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0