工具与软件:
您好!
我需要将两个比较器用于两个不同的传感器。 如何使用比较器通道?
我在 Resource Explorer 上搜索、没有找到任何相关信息。
也许我没有足够的注意的代码片段...
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
您好!
我需要将两个比较器用于两个不同的传感器。 如何使用比较器通道?
我在 Resource Explorer 上搜索、没有找到任何相关信息。
也许我没有足够的注意的代码片段...
您好、Italo、
为了方便起见、我将复制这里。
//******************************************************************************
// MSP430G2x13/G2x53 Demo - Comp_A, Detect Threshold, Set P1.0 if P1.1 > 0.25*Vcc
//
// Description: Use Comparator_A to detect a voltage threshold.
// Using an external potentiometer, an unknown voltage is applied to P1.1.
// Comparator_A compares the unknown voltage to an internal reference
// voltage, in this example 0.25*VCC. If the unknown voltage is higher
// than 0.25*VCC, P1.0 is set, if not, P1.0 is reset.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
// MSP430G2x13/G2x53
// -----------------
// /|\ | XIN|-
// | | |
// ---|RST XOUT|-
// | | |
// R<-|P1.1/CA1 P1.0|-->LED
// | | |
// ---|VSS
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include <msp430.h>
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
CACTL1 = CARSEL + CAREF0 + CAON; // 0.25 Vcc = -comp, on
CACTL2 = P2CA4; // P1.1/CA1 = +comp
while (1) // Test comparator_A output
{
if ((CAOUT & CACTL2))
P1OUT |= 0x01; // if CAOUT set, set P1.0
else P1OUT &= ~0x01; // else reset
}
}
由于您有两个传感器、因此您需要在两个传感器通道之间来回切换。
您好!
我将尝试对两个传感器单独使用两个通道。 我的想法是切换 P2CA0、一次使用每个通道、但没有结果。
通过 在开发人员区域上设置代码片段、我执行了如下操作:
while(1)
{
__delay(500000);
CACTL2 ^= P2CA0;
}
#pragma vector = COMPARATORA_VECTOR
__interrupt void COMPA_ISR()
{
if(!(CACTL2 & CAOUT)) // Test comparator_A output
{
if(CACTL2 & P2CA0)
{
P1OUT |= BIT0;
}
else
{
P1OUT |= BIT6;
}
}
else
{
P1OUT &= ~(BIT0 | BIT6);
}
}