// MSP430G2x13/G2x53 Demo – Comp_A,
//Simple 2.2V Low Battery Detect
// Description: Two comparator_A reference generators 0.25*Vcc and ~0.55V
// are compared for a simple battery check of 2.2V. In the subroutine
// Batt_Check, a small capacitor between P2.3 and Vss is first charged
// to 0.25*Vcc and then compared to ~0.55V. If 0.25*Vcc,
// is above ~0.55V, P1.0 is toggled, else set. Batt_Check is called
// constantly in an endless loop – in an actual application, Batt_Check
// should be called infrequently to save power.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
// There is a tolerance of the Comp_A reference generator and in the
// device specific datasheet. In most applications, the tolerence of the
// reference generator is more than adequate to detect Low Battery.
//
//MSP430G2x13/G2x53
// —————–
// /|\ | XIN|-
// | | |
// —|RST XOUT|-
// | |e
// +—–|P1.1/CA1 P1.0|–>LED
// | | |
// ===.1uf| |
// | | |
// +—–|Vss
//
void Batt_Check(void);
unsigned int i;
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include <msp430g2553.h>
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
CACTL2 = P2CA4; // P1.1 = CA1
while (1) // Mainloop
{
Batt_Check();
}
}
void Batt_Check(void) {
CACTL1 = CAREF_1 + CAON; // 0.25*Vcc on P1.1, Comp. on
i = 30000; // delay
while(i>0) {
i–;
}
CACTL1 = CARSEL + CAREF_2 + CAREF_1 + CAON; // CAREF=3:0.55V on -, Comp. on
if (CACTL2 & CAOUT)
P1OUT ^= 0x01; // P1.0 toggle
else P1OUT |= 0x01; // P1.0 set
CACTL1 = 0x00; // Disable Comp_A, save power
}
这程序注释说明里面写的是P2.3与Vss有电容而图里面写的却是P1.1,而且到底应该怎么去验证这个程序?还有我不太懂"toggle"是什么意思,请专家指教。
jordge Micheal:
回复 Peter_Zheng:
谢谢您的解答~还有我不是很清楚1、用内部参考电压0.55V和0.25*VCC加上电容是怎么能够测出2.2v的电压的?这内部的基本原理我搞不清楚。2、是检测VCC的电压吗?还是检测我从P1.1输入的电压?3、如果“toggle”是使它亮,那“ P1OUT |= 0x01;/ P1.0 set”set是让它灭?
jordge Micheal:
回复 Peter_Zheng:
谢谢您的解答~还有我不是很清楚1、用内部参考电压0.55V和0.25*VCC加上电容是怎么能够测出2.2v的电压的?这内部的基本原理我搞不清楚。2、是检测VCC的电压吗?还是检测我从P1.1输入的电压?3、如果“toggle”是使它亮,那“ P1OUT |= 0x01;/ P1.0 set”set是让它灭?
jordge Micheal:
回复 Young Hu:
谢谢老师!
jordge Micheal:
回复 Young Hu:
老师您好,我还想再问一下这程序怎么用launchpad验证?我现在launchpad连着usb,已经在P1.1和VCC间加了个.1uf的电容,然后就不知道怎么测了,usb的电压是一定的,led灯始终亮着。1、而我把usb拔掉,为什么直接在VCC上加直流电压,不管电压多少,led就是不亮?2、VCC换上正弦波,led亮了,但是总感觉不是因为比较器的原因亮灭,而且幅度一旦加到4V以上,灯就不亮,为什么呢? 请老师您给出一个验证方法~~
Hardy Hu:
回复 jordge Micheal:
加到4V以上MCU有可能被烧掉,很危险,这种一般是面向电池供电的应用,建议自建一个电源,通过可调输出的LDO后加载到板子上,调节LDO的电压调节电阻,控制EVM的VCC,然后再观察现象