MKM34Z256VLx7 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 PIN3 /* PTJ3 */
#define LED_R PIN4 /* PTJ4 */
void main(void)
{
/* initialize SIM module */
/* clock mode 2:1:1, 48MHz */
/* PORTs init */
PORT_Init (PORTJ, PORT_MODULE_LED_MODE, LED_G | LED_R);
GPIO_Init (GPIOJ, GPIO_OUT_LOGIC0_MODE, LED_G | LED_R);
/* VREF module must be initialized after SIM module */
/* Comparator module initialized */
CMP_Init (CMP2,
CMP_MODULE_EN_FILTER7_SAMPLE_PER_255_DAC_EN_CONFIG_BOTH_EDGES(32),
IN4,
/* 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 & CMP2_CALLBACK)
{
{
GPIO_Tgl (GPIOJ, LED_G);
}
{
GPIO_Tgl (GPIOJ, LED_R);
}
}
}
Toolchain support:
IAR EWARM 7.40.7KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0