dear all:
我写了一个ca的小程序,可是输出波形有问题。为何比较器的输出(蓝色)周期只有原正弦波(黄色)的一半呢。而且高低电平也不对。求解答
#include <msp430g2452.h>
void clk_init(void)
{
//wdt
WDTCTL = WDTPW +WDTHOLD;//SHUTDOWN WDT
//basic clock system
DCOCTL = CALDCO_8MHZ;// calibration DCO ,8MHZ,(10FC)
BCSCTL1 = CALBC1_8MHZ;// calibration bcs, 8MHZ,(10FD)
//DISABLE INT
_DINT();
}
void port_init(void)
{
//p1.0->CA0 no need to setup
P1DIR |= BIT3; //P1.3 ->CAOUT
P1SEL |= BIT3; //DATASHEET 2X52
P1SEL2 |= BIT3;
}
void ca_init(void)
{
CACTL1 = CAEX +CAREF_3+ CAON ; //CAEX, CARSEL ->Vcaref(-terminal) ; CAREF_3->~0.55V
CACTL2 = P2CA1 + CAF; //ca1 ->(+terminal) when CAEX =1;
}
int main(void)
{
clk_init();
port_init();
ca_init();
while(1)
{
;
}
}
yingjun zhu:
继续
当我更改CA的设置时,程序和波形如下。波形的周期应该是对的,可是高低电平应该翻了啊。求解答。
#include <msp430g2452.h>
void clk_init(void){ //wdt WDTCTL = WDTPW +WDTHOLD;//SHUTDOWN WDT //basic clock system DCOCTL = CALDCO_8MHZ;// calibration DCO ,8MHZ,(10FC) BCSCTL1 = CALBC1_8MHZ;// calibration bcs, 8MHZ,(10FD) //DISABLE INT _DINT();
}
void port_init(void){ //p1.0->CA0 no need to setup P1DIR |= BIT3; //P1.3 ->CAOUT P1SEL |= BIT3; //DATASHEET 2X52 P1SEL2 |= BIT3;
}
void ca_init(void){ CACTL1 = CAEX + CARSEL +CAREF_3+ CAON ; //CAEX, CARSEL ->Vcaref(+terminal) ; CAREF_3->~0.55V CACTL2 = P2CA0 + CAF; //CA0->(-terminal) when CAEX =1;CAF ->FILTER}
int main(void){ clk_init(); port_init(); ca_init(); while(1) { ; }
}
Leon Yan:
回复 yingjun zhu:
楼主,你好:
CAEX Bit 7 Comparator_A+ exchange. This bit exchanges the comparator inputs and inverts the comparator output.
所以拿掉这个位的设置,你再看看。
谢谢。