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.

[参考译文] MSP430FR2433:多路ADC通道采样

Guru**** 2538930 points
Other Parts Discussed in Thread: MSP430FR2433

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1088987/msp430fr2433-multiple-adc-channel-sampling

部件号:MSP430FR2433

您好,

我是MSP430系列微控制器的新产品,我正在使用MSP430FR2433开发套件的ADC。

我尝试了用于单通道ADC采样的msp430fr243x_ADC10_01.c示例,它工作得很好。

但是,当我修改该示例以对多通道ADC进行采样时(WFP 1.2 WFP 1.3)。 结果似乎非常不稳定。

欢迎您提出任何建议和建议。

1.将两个接头连接到GND针脚

我预计结果应该都是0,但有时突然跳到243。

这是日志。

254 3
"▒ 0 0

"▒0 0

"▒254 4
"▒0 0

"▒0 0

"▒254 3
"▒0 0

"▒0 0

"▒254 3
"▒0 0

"▒0 0

"▒254 3
"▒0 0

"▒0 0

"▒254 4
"▒0 0

"▒0 0

"▒254 3
"▒0 0

"▒0 0

"▒254 3

2.将两个接头连接到VCC (3V3)引脚

我预计结果应该接近255,但有时突然跳到4。

这是日志。

255 255
207 207
253 4

255 255
206 206
252 3

254 255
207 203
253 3

255 254
207 207
251 3

254 254
204 207
253 4

254 255
207 207
253 3

255 255
204 207

#include <msp430.h> 
#include <stdio.h>

unsigned char ADC_Result[2];                                    // 8-bit ADC conversion result array
int i;
void print_result_to_uart(void);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer

    P1DIR |= BIT0 | BIT1;              // P1.0 & P1.1 as LED
    P1OUT = 0x00;
    P1REN = 0x00;

    SYSCFG2 |= ADCPCTL2+ADCPCTL3;       // Select P1.2 & P1.3 A2 as ADC

    P1SEL1 &= ~(BIT4 | BIT5);       // USCI_A0 UART operation
    P1SEL0 |= BIT4 | BIT5;

    UCA0CTLW0 |= UCSWRST;           // Put USCI_A0 to software reset
    UCA0CTLW0 |= UCSSEL__SMCLK;     // Use SMCLK(1048576Hz) for baud rate calculation
    UCA0BRW = 9;                    // N = f/BR = 1048576/115200 = 9
    UCA0MCTLW = 0x0800;
    UCA0CTLW0 &= ~UCSWRST;          // Release USCI_A0 software reset

    PM5CTL0 &= ~LOCKLPM5;

    ADCCTL0 |= ADCSHT_2;                // 16 ADCCLK cycles
    ADCCTL0 |= ADCON;                   // ADC on
//    ADCCTL0 |= ADCMSC;                  // ADC multiple sample-and-conversion

    ADCCTL1 |= ADCSHP;                  // ADCCLK = MODOSC; sampling timer
    ADCCTL1 |= ADCCONSEQ_1;             // Repeat-sequence-of-channels

    ADCCTL2 |= ADCRES_0;                // Resolution 8-bit
    ADCMCTL0 |= ADCINCH_2+ADCINCH_3;    // A2 & A3 ADC input select; Vref=AVCC
    ADCIE |= ADCIE0;                    // Enable ADC conv complete interrupt
    __bis_SR_register(GIE);             // LPM0, ADC_ISR will force exit

    while(1)
    {
        i = 1;
        ADCCTL0 |= ADCENC | ADCSC;      // Sampling and conversion start
        while (i >= 0);
        print_result_to_uart();
        if (ADC_Result[0] < 0x7F)
            P1OUT &= ~BIT0;             // Clear P1.0 LED off
        else
            P1OUT |= BIT0;
        if (ADC_Result[1] < 0x7F)       // P1.3 ADC3 result
            P1OUT &= ~BIT1;             // Clear P1.1 LED off
        else
            P1OUT |= BIT1;
        __delay_cycles(1048576);
    }
}

void print_result_to_uart(void)
{
    char str[20];
    sprintf(str, "%d %d\r\n", ADC_Result[0], ADC_Result[1]);
    int j = 0;
    for (j = 0; j < sizeof(str); j++){
        UCA0TXBUF = str[j];
        __delay_cycles(100);
    }
}

#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
{
    switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
    {
        case ADCIV_ADCIFG:
            ADC_Result[i--] = ADCMEM0;
            if (i >= 0)
                ADCCTL0 |= ADCENC | ADCSC;
            break;
        default:
            break;
    }
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    >ADCMCTLS0   |= ADCINCH_2+ADCINCH_3;

    ADCINCH是一个小整数,不是位字段。 这将设置ADCINCH=(2+3)=ADCINCH_5。 在您的环境中,您可以做的最好的事情是:

    >  ADCMCTLS0 |= ADCINCH_3; //样例A3->A0

    -------------------

    CONSEQ=1总是从英寸到A0倒计时。 要获得中间的两个频道,您可以选择其中一个

    a)读取A3->A0,然后丢弃A1和A0读数。

    b)由于您一次只执行一个步骤的转换(MSC=0),您可以读取A3和A2,然后切换ENC (=0然后=1)以停止序列。 然后,下次设置ADCSC时,它将从ADCINCH开始。 [参考用户指南(SLAU445I)图21-13]

    -------------------

    主动提供:

    >   ADCCTL2 |= ADCRES_0;         //分辨率8位

    这不起任何作用,因为ADCRES_0=0。 要获得ADCRES=0 (因为它最初为=1),请尝试:

    >   ADCCTL2 &=~ADCRES_3;         //分辨率8位

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    非常感谢您的回复。 程序现在可以正常工作,您的答案 是简洁明了的。