EFM32例程——ACMP

硬件:EFM32GG230512
工具:keil5

ACMP实验
ACMP测试,ACMP测量判断输入电压高低
输出ACM_OUT获得高低信号

初始化

/*********************************************Copyright (c)***********************************************
** File name:             	acmp.c
** Created by:				Gui              
** Version:               	V1.0.0
** Descriptions:         	ACMP测试,ACMP测量判断输入电压高低,可工作在EM0~EM3下
*********************************************************************************************************/
#include "acmp.h"

void ACMP0_IRQHandler (void){
	
    if (ACMP0->IF & ACMP_IF_EDGE) {
         ACMP0->IFC = ACMP_IFC_EDGE;
    }
}

void acmp_init(void){
	
    CMU_ClockEnable(cmuClock_ACMP0, true);
    
    ACMP_Init_TypeDef tAcmpInit = {
#if     ACMP_MODE == ACMP_CONSUME_FULL
        .fullBias                  = true,                              /* 全偏置电流开启               */
        .halfBias                  = false,                             /* 减半偏置电流关闭             */
        .biasProg                  = 15,                                /* 偏置电流配置                 */
#elif   ACMP_MODE == ACMP_CONSUME_GENERAL
        .fullBias                  = false,                             /* 全偏置电流关闭               */
        .halfBias                  = false,                             /* 减半偏置电流关闭             */
        .biasProg                  = 0,                                 /* 偏置电流配置                 */
#elif   ACMP_MODE == ACMP_CONSUME_LOW
        .fullBias                  = false,                             /* 全偏置电流关闭               */
        .halfBias                  = true,                              /* 减半偏置电流开启             */
        .biasProg                  = 0,                                 /* 偏置电流配置                 */
#endif
        .interruptOnFallingEdge    = true,                              /* 开启ACMP下降沿中断           */
        .interruptOnRisingEdge     = false,                             /* 关闭ACMP上升沿中断           */
        .warmTime                  = acmpWarmTime256,                   /* 配置ACMP预热时间             */
        .hysteresisLevel           = acmpHysteresisLevel0,              /* 配置ACMP滞回电压             */
        .inactiveValue             = 0,                                 /* 配置ACMP不可用时输出为0      */
#if     ACMP_MODE == ACMP_CONSUME_LOW
        .lowPowerReferenceEnabled  = true,                              /* 使能低功耗参考电压模式       */
#else
        .lowPowerReferenceEnabled  = false,                             /* 禁能低功耗参考电压模式       */
#endif

        .vddLevel                 = 0,                                  /* 配置VDD参考电压分压值        */
        .enable                   = true                                /* 使能ACMP                     */
    };
    ACMP_Init(ACMP0, &tAcmpInit);                                        /* 初始化ACMP                   */
    ACMP_ChannelSet(ACMP0, acmpChannel2V5, acmpChannel4);               /* 设置ACMP输入通道,PC4对应4号   */
	
	GPIO_PinModeSet(gpioPortE,13,gpioModePushPull,1);
    ACMP_GPIOSetup(ACMP0, 0, 1, 0);                                     /* 配置ACMP输出到GPIO口PE13      */
    
    while (!(ACMP0->STATUS & ACMP_STATUS_ACMPACT)) ;                    /* 等待ACMP预热完成             */
    
    ACMP_IntEnable(ACMP0, ACMP_IEN_EDGE);                               /* 使能ACMP边沿中断             */  
    NVIC_ClearPendingIRQ(ACMP0_IRQn);                                   /* 清除NVIC中ACMP挂起中断       */
    NVIC_EnableIRQ(ACMP0_IRQn);                                         /* 使能NVIC中ACMP总中断         */
}

main

/*********************************************Copyright (c)***********************************************
** File name:             	  	main.c
** Created by:					Gui              
** Version:               		V1.0.0        
** Descriptions:            	ACMP测试,ACMP测量判断输入电压高低
*********************************************************************************************************/
#include "system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_int.h"
#include "delay.h"
#include "acmp.h"
#include "bsp_led.h"

uint32_t g_chip_tick = 0;

int main(){
	
	int velue;
	
	CMU_ClockEnable(cmuClock_HFPER, true); //前置芯片设置
	CMU_ClockEnable(cmuClock_GPIO, true);
	if(SysTick_Config(SystemCoreClockGet()/1000))while(1);//1ms的systick中断
	led_init();//PD4 PD5
	acmp_init();//PC4输入 PE13输出
	
	g_chip_tick = g_rtc_rtcFreq;
	
	while(1){
		if(g_rtc_rtcFreq - g_chip_tick > 1000 || g_chip_tick > g_rtc_rtcFreq){
			velue = ACM_OUT;
			velue = velue;
		}
//		EMU_EnterEM2(false);
	}
}


你可能感兴趣的:(EFM32)