打印
[DemoCode下载]

ML51的模拟比较器的几种应用方法

[复制链接]
767|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mintspring|  楼主 | 2019-7-26 00:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: ML51 simple GPIO toggle out demo code
//***********************************************************************************************************

#include "ML51.h"
/**
* [url=home.php?mod=space&uid=247401]@brief[/url]       ACMP interrupt subroutine
* @param       None
* [url=home.php?mod=space&uid=266161]@return[/url]      None
* [url=home.php?mod=space&uid=1543424]@Details[/url]     None
*/
void ACMP_ISR (void) interrupt 23
{
  SFRS=0;
  if ((ACMPSR&SET_BIT2)==SET_BIT2)
  {
    ACMPSR&=CLR_BIT2;
    P13 ^=1;
  }
  else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  {
    ACMPSR&=CLR_BIT0;
    P14 ^=1;
  }  
}

/**
* @brief       ACMP negative input use CRV voltage
* @param       None
* @return      None
* @details     None
*/
void main (void)
{
/* Setting Multi function pin setting for GPIO toggle
   * include gipo.c in Common for GPIO mode setting
*/  MFP_P13_GPIO;
    P13_QUASI_MODE;
    MFP_P14_GPIO;
    P14_QUASI_MODE;
  
    MFP_P23_ACMP0_P1;   
    MFP_P41_ACMP0_O;
   
/* ACMP intial
   * include acmp.c in Library for ACMP initial and interrupt setting.
*/
    VREF_Open(2);
/* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
    ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_CRV, ACMP_CTL_CRV_VREF, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
/* CRV Value = CRV source voltage * (2/12+CRV1CTL/12). so for this example = VREF/2.*/
    ACMP_CRVValue(ACMP0, 4);  
/* Initial ACMP interrupt enable, wakeup function disable.*/
    ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_DISABLE, ACMP_CTL_INT_ENABLE);
    ENABLE_GLOBAL_INTERRUPT;                //after individal setting enable interrupt must enable global interrupt.

    while(1);
}





使用特权

评论回复
沙发
mintspring|  楼主 | 2019-7-26 00:29 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: ML51 simple GPIO toggle out demo code
//***********************************************************************************************************

#include "ML51.h"
/**
* @brief       ACMP interrupt subroutine
* @param       None
* @return      None
* @details     None
*/
void ACMP_ISR (void) interrupt 23
{
  SFRS=0;
  if ((ACMPSR&SET_BIT2)==SET_BIT2)
  {
    ACMPSR&=CLR_BIT2;
    P14 ^=1;
  }
  else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  {
    ACMPSR&=CLR_BIT0;
    P14 ^=1;
  }
}

/**
* @brief       ACMP negtive input use Bandgap voltage
* @param       None
* @return      None
* @details     None
*/
void main (void)
{
/* Setting Multi function pin setting for GPIO toggle
   * include gipo.c in Common for GPIO mode setting
*/
    MFP_P13_GPIO;
    P13_QUASI_MODE;
    MFP_P14_GPIO;
    P14_QUASI_MODE;
  
    MFP_P23_ACMP0_P1;   
    MFP_P41_ACMP0_O;
    P41_QUASI_MODE;
   
/* ACMP intial
   * include acmp.c in Library for ACMP initial and interrupt setting.
*/
/* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
    ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_VBG,0, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
/* Initial ACMP interrupt enable, wakeup function disable. */
    ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_DISABLE, ACMP_CTL_INT_ENABLE);
/*To use interrupt function, must enable blobal interrupt after all setting. */
    ENABLE_GLOBAL_INTERRUPT;                     

    while(1);
}



使用特权

评论回复
板凳
mintspring|  楼主 | 2019-7-26 00:29 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: ML51 simple GPIO toggle out demo code
//***********************************************************************************************************

#include "ML51.h"
/**
* @brief       ACMP interrupt subroutine
* @param       None
* @return      None
* @details     None
*/
void ACMP_ISR (void) interrupt 23
{
  if ((ACMPSR&SET_BIT2)==SET_BIT2)
  {
    ACMPSR&=CLR_BIT2;
    SFRS = 0x00;
    P13 ^=1;
  }
  else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  {
    ACMPSR&=CLR_BIT0;
    SFRS = 0x00;
    P14 ^=1;
  }  
}


/**
* @brief       ACMP negtive input use Bandgap voltage main loop
* @param       None
* @return      None
* @details     None
*/
void main (void)
{
/* Setting Multi function pin setting for GPIO toggle
   * include gipo.c in Common for GPIO mode setting
*/  MFP_P13_GPIO;
    P13_QUASI_MODE;
  
    MFP_P23_ACMP0_P1;   
    MFP_P24_ACMP0_N0;
    MFP_P41_ACMP0_O;
   
/* ACMP intial
   * include acmp.c in Library for ACMP initial and interrupt setting.
*/
// Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1
    ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_PIN_N0,0, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
/* Initial ACMP interrupt enable, wakeup function disable.*/
    ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_ENABLE, ACMP_CTL_INT_ENABLE);
/*To use interrupt function, must enable blobal interrupt after all setting.*/
    ENABLE_GLOBAL_INTERRUPT;                     
  
    while (1)
    {
      set_PCON_PD;
      Timer3_Delay(24000000,128,100,10000);
    }

}



使用特权

评论回复
地板
mintspring|  楼主 | 2019-7-26 00:30 | 只看该作者
这个比较器非常好用,有多种使用方式,可以跟内部比较,跟外边比较,而且还可以中断。

使用特权

评论回复
5
mintspring|  楼主 | 2019-7-26 00:30 | 只看该作者
还可以输出比较结果,非常方便。

使用特权

评论回复
6
yiyigirl2014| | 2019-7-26 00:58 | 只看该作者
这个开发板多少钱

使用特权

评论回复
7
玛尼玛尼哄| | 2019-7-28 21:29 | 只看该作者
貌似比N76E 003的更多功能啊

使用特权

评论回复
8
天灵灵地灵灵| | 2019-7-28 22:16 | 只看该作者
三种用法,非常方便参考。

使用特权

评论回复
9
xixi2017| | 2019-7-28 23:15 | 只看该作者
模拟比较器还这么多使用方法。

使用特权

评论回复
10
捉虫天师| | 2019-7-28 23:30 | 只看该作者
比较器的中断经常使用。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

282

主题

4812

帖子

24

粉丝