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.

[参考译文] MSP430FR5994:ADC_12 RDYIFG 标志问题和不同 ADCMTL 寄存器和 CTADRT ADDRX 位的签名

Guru**** 2539330 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1084329/msp430fr5994-adc_12-rdyifg-flag-issue-and-siginificance-of-diffrent-adcmctl-registers-and-cstart-addrx-bit

部件号:MSP430FR5994

嗨,社区,

最近几天,我一直在尝试配置 ADC 来测量电池电量。 所以我在这里使用参考电压发生器作为 ADC 的参考。我们知道,在参考局部缓冲器稳定下来之前,我们无法启动 ADC。 所以我想有两种方法可以做到这一点  

1.在 REFCTL 中使用 REFGENRDY 位

2.使用 ADCRDYIFG 中断

 由于我在非常电源相关的应用中工作,所以我采用了 ADC 就绪中断。但是,尽管我启用了该中断并以正确的方式设置了大部分内容(我认为) ,但 ADCRDY 中断未被触发。还有一个术语称为样本触发器(这可以帮助 ADCRDYIFG) 但我不知道如何设置信号

2.我也不能用多个 ADCMTL 寄存器 CSTADDRX 位来总结。这两个寄存器之间的连接是什么。

因此,请您对我的错误和我的问题发表看法。

/* --COPYRIGHT--,BSD_EX
 * Copyright (c) 2015, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *******************************************************************************
 *
 *                       MSP430 CODE EXAMPLE DISCLAIMER
 *
 * MSP430 code examples are self-contained low-level programs that typically
 * demonstrate a single peripheral function or device feature in a highly
 * concise manner. For this the code may rely on the device's power-on default
 * register values and settings such as the clock configuration and care must
 * be taken when combining code from several examples to avoid potential side
 * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
 * for an API functional library-approach to peripheral configuration.
 *
 * --/COPYRIGHT--*/
//******************************************************************************
//  MSP430FR5x9x Demo - ADC12, Sample A1, AVcc Ref, Set P1.0 if A1 > 0.5*AVcc
//
//   Description: A single sample is made on A1 with reference to AVcc.
//   Software sets ADC12SC to start sample and conversion - ADC12SC
//   automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
//   and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
//   conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
//   reti. If A1 > 0.5*AVcc, P1.0 set, else reset. The full, correct handling of
//   and ADC12 interrupt is shown as well.
//
//
//                MSP430FR5994
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//        >---|P1.1/A1      P1.0|-->LED
//
//   William Goh
//   Texas Instruments Inc.
//   October 2015
//   Built with IAR Embedded Workbench V6.30 & Code Composer Studio V6.1
//******************************************************************************
#include <msp430.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop WDT

    // GPIO Setup
    P1OUT &= ~BIT0;                         // Clear LED to start
    P1DIR |= BIT0;                          // Set P1.0/LED to output
    P1SEL1 |= BIT2;                         // Configure P1.1 for ADC
    P1SEL0 |= BIT2;


    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    // Configure Ref voltage generator
    REFCTL0 |=REFVSEL_3|REFON;
    // Configure ADC12
    ADC12CTL0 = ADC12SHT0_2 | ADC12ON;      // Sampling time, S&H=16, ADC12 on
    ADC12CTL1 = ADC12SHP;                   // Use sampling timer
    ADC12CTL2 |= ADC12RES_2;                // 12-bit conversion results
    ADC12MCTL1|= ADC12INCH_2|ADC12VRSEL_1;              // A1 ADC input select; Vref=AVCC
    ADC12IER0 |= ADC12IE0;                  // Enable ADC conv complete interrupt
    ADC12IER2 |=ADC12RDYIE;
    __enable_interrupt();
    while (1)
    {
        while(!(REFCTL0 & REFGENRDY));          // Wait for reference generator
        __delay_cycles(5000);
        ADC12CTL0 |= ADC12ENC
                  | ADC12SC;    // Start sampling/conversion

        __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit
        __no_operation();                   // For debugger
    }
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_B_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_B_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
    switch(__even_in_range(ADC12IV, ADC12IV__ADC12RDYIFG))
    {
        case ADC12IV__NONE:        __no_operation(); break;   // Vector  0:  No interrupt
        case ADC12IV__ADC12OVIFG:  __no_operation(); break;   // Vector  2:  ADC12MEMx Overflow
        case ADC12IV__ADC12TOVIFG: __no_operation(); break;   // Vector  4:  Conversion time overflow
        case ADC12IV__ADC12HIIFG:  __no_operation(); break;   // Vector  6:  ADC12BHI
        case ADC12IV__ADC12LOIFG:  __no_operation(); break;   // Vector  8:  ADC12BLO
        case ADC12IV__ADC12INIFG:  __no_operation(); break;   // Vector 10:  ADC12BIN
        case ADC12IV__ADC12IFG0:            // Vector 12:  ADC12MEM0 Interrupt
            if (ADC12MEM0 >= 0x7ff)         // ADC12MEM0 = A1 > 0.5AVcc?
                P1OUT |= BIT0;              // P1.0 = 1
            else
                P1OUT &= ~BIT0;             // P1.0 = 0
                // Exit from LPM0 and continue executing main
                __bic_SR_register_on_exit(LPM0_bits);
            __no_operation(); break;
        case ADC12IV__ADC12IFG1:   __no_operation(); break;   // Vector 14:  ADC12MEM1
        case ADC12IV__ADC12IFG2:   __no_operation(); break;   // Vector 16:  ADC12MEM2
        case ADC12IV__ADC12IFG3:   __no_operation(); break;   // Vector 18:  ADC12MEM3
        case ADC12IV__ADC12IFG4:   __no_operation(); break;   // Vector 20:  ADC12MEM4
        case ADC12IV__ADC12IFG5:   __no_operation(); break;   // Vector 22:  ADC12MEM5
        case ADC12IV__ADC12IFG6:   __no_operation(); break;   // Vector 24:  ADC12MEM6
        case ADC12IV__ADC12IFG7:   __no_operation(); break;   // Vector 26:  ADC12MEM7
        case ADC12IV__ADC12IFG8:   __no_operation(); break;   // Vector 28:  ADC12MEM8
        case ADC12IV__ADC12IFG9:   __no_operation(); break;   // Vector 30:  ADC12MEM9
        case ADC12IV__ADC12IFG10:  __no_operation(); break;   // Vector 32:  ADC12MEM10
        case ADC12IV__ADC12IFG11:  __no_operation(); break;   // Vector 34:  ADC12MEM11
        case ADC12IV__ADC12IFG12:  __no_operation(); break;   // Vector 36:  ADC12MEM12
        case ADC12IV__ADC12IFG13:  __no_operation(); break;   // Vector 38:  ADC12MEM13
        case ADC12IV__ADC12IFG14:  __no_operation(); break;   // Vector 40:  ADC12MEM14
        case ADC12IV__ADC12IFG15:  __no_operation(); break;   // Vector 42:  ADC12MEM15
        case ADC12IV__ADC12IFG16:  __no_operation(); break;   // Vector 44:  ADC12MEM16
        case ADC12IV__ADC12IFG17:  __no_operation(); break;   // Vector 46:  ADC12MEM17
        case ADC12IV__ADC12IFG18:  __no_operation(); break;   // Vector 48:  ADC12MEM18
        case ADC12IV__ADC12IFG19:  __no_operation(); break;   // Vector 50:  ADC12MEM19
        case ADC12IV__ADC12IFG20:  __no_operation(); break;   // Vector 52:  ADC12MEM20
        case ADC12IV__ADC12IFG21:  __no_operation(); break;   // Vector 54:  ADC12MEM21
        case ADC12IV__ADC12IFG22:  __no_operation(); break;   // Vector 56:  ADC12MEM22
        case ADC12IV__ADC12IFG23:  __no_operation(); break;   // Vector 58:  ADC12MEM23
        case ADC12IV__ADC12IFG24:  __no_operation(); break;   // Vector 60:  ADC12MEM24
        case ADC12IV__ADC12IFG25:  __no_operation(); break;   // Vector 62:  ADC12MEM25
        case ADC12IV__ADC12IFG26:  __no_operation(); break;   // Vector 64:  ADC12MEM26
        case ADC12IV__ADC12IFG27:  __no_operation(); break;   // Vector 66:  ADC12MEM27
        case ADC12IV__ADC12IFG28:  __no_operation(); break;   // Vector 68:  ADC12MEM28
        case ADC12IV__ADC12IFG29:  __no_operation(); break;   // Vector 70:  ADC12MEM29
        case ADC12IV__ADC12IFG30:  __no_operation(); break;   // Vector 72:  ADC12MEM30
        case ADC12IV__ADC12IFG31:  __no_operation(); break;   // Vector 74:  ADC12MEM31
        case ADC12IV__ADC12RDYIFG:
            ADC12CTL0 |= ADC12ENC | ADC12SC;    // Start sampling/conversion
            __no_operation();
            break;   // Vector 76:  ADC12RDY
        default: __no_operation(); break;
    }
}

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

    我将从(2)开始,因为我认为这正是您现在所遇到的:

    2)如果 CSTARDAD=n,则第一个(或唯一的)转换引用 ADC12MCTLn/memN。 [参考用户指南(SLAU367P)第34.2.7]节。 在该程序中,CSTARDAD=0 (和 CONSEQ=0),因此转换将以 ADC12MCTL0/MEM0开始/结束(不进一步)。 您已经设置了 ADC12MCTL1/MEM1,但它们不会被使用。

    使用 CSTARTADD 是一种不同寻常的做法,但在某些情况下,这种做法很有用。

    1) RDYIFG 是指 ADC12“本地”缓冲区(图34-1中的 BUF_INT)。 只有当它使用 VRSEL=1的 MCTLn (实际上是奇数)时,它才会触发,这种情况由于(2)而没有发生。 (如果您在此程序中设置了 CSTARDAD=1,您将看到它。)

    在实践中,当您使用 SHP=1 [参考 UG 第34.2.6.2和34.2.4]条时,这一切都是自动的。 参考缓冲区将根据需要启动和停止,它将比 您的代码更快(持续时间更短)。

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

    布鲁斯给出了一个很好的答案,我不需要在那里添加任何附加注释。

    但是,我注意到您正在配置 ADC12MCTL1,但 ISR 正在读取 ADC12MEM0。 我认为这不是有意的。 ADC 可以采样32个不同的通道。 每个通道都可以通过 ADC12MCTLx 进行配置(其中 x 是0-31的通道编号)。 ADC 将样本写入与通道(ADC12MEMx)相关的寄存器中。 默认情况下,ADC 设置为“单通道,单转换”模式(通过 ADC12CONSEQx 设置),这意味着 ADC 将仅对 ADC12CSTARTADD 中指定的1个通道进行采样。 完成后,请等待重新启用/重新触发。 目前,您的代码正在配置通道1,但正在采样/读取通道0。

    希望这能有所帮助。

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

    感谢布鲁斯的建议

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

    感谢大家提出的建议