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.

[参考译文] MSP430FR6989:ADC 问题

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1375249/msp430fr6989-adc-problem

器件型号:MSP430FR6989

工具与软件:

您好!  

我使用 MSP430FR6989开发板。 我设置了 P9.0至 P9.7的引脚、并且我想通过使用中断来获取这些值。 即使在调试时分别连接了引脚 GND 和3V3电压引脚、我得到的结果也介于700和890之间。 任何引脚上都没有变化。 我在这里共享测试代码。 我曾尝试更改基准电压(例如内部1.2V 或2V)、但仍未获得逻辑结果。 任何帮助都将受到赞赏。

此致。

#include <msp430.h>
#include <stdint.h>

volatile uint16_t adc_values[8]; 
volatile uint8_t adc_index = 0;  

void led_config();
void led_on();
void led_off();


void main(void) {
    WDTCTL = WDTPW + WDTHOLD;
    PM5CTL0 &= ~LOCKLPM5;


    ADC12CTL0 = ADC12SHT0_3 | ADC12ON;
    ADC12CTL1 = ADC12SHP | ADC12CONSEQ_1;   
    ADC12CTL2 = ADC12RES_2; 
    ADC12MCTL0 |= ADC12INCH_0 | ADC12VRSEL_0; 
    ADC12MCTL1 |= ADC12INCH_1 | ADC12VRSEL_0; 
    ADC12MCTL2 |= ADC12INCH_2 | ADC12VRSEL_0; 
    ADC12MCTL3 |= ADC12INCH_3 | ADC12VRSEL_0; 
    ADC12MCTL4 |= ADC12INCH_4 | ADC12VRSEL_0; 
    ADC12MCTL5 |= ADC12INCH_5 | ADC12VRSEL_0;
    ADC12MCTL6 |= ADC12INCH_6 | ADC12VRSEL_0;
    ADC12MCTL7 |= ADC12INCH_7 | ADC12VRSEL_0; 

    P9SEL0 |= 0xFF;
    P9SEL1 |= 0xFF;

    ADC12IER0 |= ADC12IE0 | ADC12IE1 | ADC12IE2 | ADC12IE3 | ADC12IE4 | ADC12IE5 | ADC12IE6 | ADC12IE7 ;

    while(1) {

        ADC12CTL0 |= ADC12SC | ADC12ENC;   // ADC örnekleme ve dönüşümü başlat
        __delay_cycles(2000);
       __bis_SR_register(GIE);

    }
}




#pragma vector=ADC12_VECTOR
__interrupt void ADC_ISR(void) {
    switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
    {
        case ADC12IV_ADC12IFG0:
            adc_values[0] = ADC12MEM0;
            break;
        case ADC12IV_ADC12IFG1:
            adc_values[1] = ADC12MEM1;
            break;
        case ADC12IV_ADC12IFG2:
            adc_values[2] = ADC12MEM2;
            break;
        case ADC12IV_ADC12IFG3:
            adc_values[3] = ADC12MEM3;
            break;
        case ADC12IV_ADC12IFG4:
            adc_values[4] = ADC12MEM4;
            break;
        case ADC12IV_ADC12IFG5:
            adc_values[5] = ADC12MEM5;
            break;
        case ADC12IV_ADC12IFG6:
            adc_values[6] = ADC12MEM6;
            break;
        case ADC12IV_ADC12IFG7:
            adc_values[7] = ADC12MEM7;
            break;

    }
}

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

    您在检查前运行了多长时间?

    1) 1)如果 ADC12MSC = 0、则每个 ADC12SC 触发器只能得到一个转换。

    2) 2)在 ADC12MCTL7:ADC12EOS=0时、它将在循环返回到 ADC12MCTL0之前循环遍历所有32个通道。

    3) 3) ADC12MEMn 寄存器在复位后未定义;然后我经常看到它们的随机数。

    我怀疑您想要:

    > ADC12CTL0 = ADC12SHT0_3 | ADC12ON | ADC12MSC; // CONSEQ=1 in a burst

    > ADC12MCTL7 |= ADC12INCH_7 | ADC12VRSEL_0 | ADC12EOS;//突发的最终通道

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

    您好!

    感谢您的快速回复。 我不确定调试时的运行时间有多长、但我想已经足够了。 我无法理解你说的 ADC12MEMn 寄存器未定义是什么意思。 您能详细解释一下吗? 最好在代码片段中引用它。

    我降低了采样时间速率、并将通道7设置为最后一个 转换通道。 我还添加了 ADC12MSC 寄存器、用于进行更多转换。 我仍然获得相同的结果。  

    您可以检查下面的更新。

    此致。

     

    #include <msp430.h>
    #include <stdint.h>
    
    volatile uint16_t adc_values[8]; 
    volatile uint8_t adc_index = 0;  
    
    void led_config();
    void led_on();
    void led_off();
    
    
    void main(void) {
        WDTCTL = WDTPW + WDTHOLD;
        PM5CTL0 &= ~LOCKLPM5;
    
    
        ADC12CTL0 = ADC12SHT0_2 | ADC12MSC | ADC12ON;
        ADC12CTL1 = ADC12SHP | ADC12CONSEQ_1;   
        ADC12CTL2 = ADC12RES_2;
        ADC12CTL3 = ADC12CSTARTADD_0;
        ADC12MCTL0 |= ADC12INCH_0 | ADC12VRSEL_0; 
        ADC12MCTL1 |= ADC12INCH_1 | ADC12VRSEL_0; 
        ADC12MCTL2 |= ADC12INCH_2 | ADC12VRSEL_0; 
        ADC12MCTL3 |= ADC12INCH_3 | ADC12VRSEL_0; 
        ADC12MCTL4 |= ADC12INCH_4 | ADC12VRSEL_0; 
        ADC12MCTL5 |= ADC12INCH_5 | ADC12VRSEL_0;
        ADC12MCTL6 |= ADC12INCH_6 | ADC12VRSEL_0;
        ADC12MCTL7 |= ADC12INCH_7 | ADC12VRSEL_0 | ADC12EOS; 
    
        P9SEL0 |= 0xFF;
        P9SEL1 |= 0xFF;
    
        ADC12IER0 |= ADC12IE0 | ADC12IE1 | ADC12IE2 | ADC12IE3 | ADC12IE4 | ADC12IE5 | ADC12IE6 | ADC12IE7 ;
        ADC12CTL0 |= ADC12ENC;
        
        while(1) {
    
            ADC12CTL0 |= ADC12SC | ADC12ENC;   // ADC örnekleme ve dönüşümü başlat
            __delay_cycles(2000);
           __bis_SR_register(GIE);
    
        }
    }
    
    
    
    
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC_ISR(void) {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
            case ADC12IV_ADC12IFG0:
                adc_values[0] = ADC12MEM0;
                break;
            case ADC12IV_ADC12IFG1:
                adc_values[1] = ADC12MEM1;
                break;
            case ADC12IV_ADC12IFG2:
                adc_values[2] = ADC12MEM2;
                break;
            case ADC12IV_ADC12IFG3:
                adc_values[3] = ADC12MEM3;
                break;
            case ADC12IV_ADC12IFG4:
                adc_values[4] = ADC12MEM4;
                break;
            case ADC12IV_ADC12IFG5:
                adc_values[5] = ADC12MEM5;
                break;
            case ADC12IV_ADC12IFG6:
                adc_values[6] = ADC12MEM6;
                break;
            case ADC12IV_ADC12IFG7:
                adc_values[7] = ADC12MEM7;
                break;
    
        }
    }

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

    使用 INCH_0到 INCH_7选择 A0到 A7。 您将端口9设置为 ADC 功能、但这些引脚连接到 A8和 A15。

    通常、当我使用 ADC 中断时、我仅为序列中的最后一个启用中断。 数据仍将在 ADC12MEMx 寄存器中、并且浪费的中断进入和退出时间更少。

    抛弃 delay_cycles、启用低功耗模式、并在 ISR 中退出低功耗模式。 您不必计算周期数即可确保2000个周期足以供 ADC 转换8个通道。

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

    您好!

    感谢您的答复。 我错过了该端口号的内容。 如您所说、它可以连接到 A8和 A15、最终我能够测量逻辑方面的内容。 它根据 ADC12VRSEL_0 (即3V3)进行工作。 但是、我想测量2V 的内部基准电压。 以下是我的代码。  

    能否分享一下有关使用内部基准电压的知识?  

    提前感谢。

    #include <msp430.h>
    #include <stdint.h>
    
    volatile uint16_t adc_values[8]; // ADC değerlerini saklayacak dizi
    volatile uint8_t adc_index = 0;  // ADC dizisi indeksi
    
    
    void main(void) {
    
        WDTCTL = WDTPW + WDTHOLD;
        PM5CTL0 &= ~LOCKLPM5;
    
        P9SEL0 |= 0xFF;
        P9SEL1 |= 0xFF;
    
    
        ADC12CTL0 = ADC12SHT0_2 | ADC12MSC | ADC12ON; 
        ADC12CTL1 = ADC12SHP | ADC12CONSEQ_1;                     
        ADC12CTL2 = ADC12RES_2; 
        ADC12CTL3 = ADC12CSTARTADD_0;
        ADC12MCTL0 |= ADC12INCH_8 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL1 |= ADC12INCH_9 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL2 |= ADC12INCH_10 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL3 |= ADC12INCH_11 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL4 |= ADC12INCH_12 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL5 |= ADC12INCH_13 ;// A1 ADC input select; Vref=AVCC
        ADC12MCTL6 |= ADC12INCH_14 ; // A1 ADC input select; Vref=AVCC
        ADC12MCTL7 |= ADC12INCH_15 | ADC12EOS; // A1 ADC input select; Vref=AVCC
    
    
        while(REFCTL0 &REFGENBUSY);
        REFCTL0 |= REFVSEL_1 | REFON;
        while(!(REFCTL0 &REFGENRDY));
    
        ADC12IER0 |= ADC12IE7;
        
        ADC12CTL0 |= ADC12ENC;
    
    
        while(1) {
            ADC12CTL0 |= ADC12SC | ADC12ENC;   // ADC örnekleme ve dönüşümü başlat
           __bis_SR_register(LPM0_bits | GIE);
    
        }
    }
    
    
    
    
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC_ISR(void) {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
    
            case ADC12IV_ADC12IFG7:
                adc_values[0] = ADC12MEM0;
                adc_values[1] = ADC12MEM1;
                adc_values[2] = ADC12MEM2;
                adc_values[3] = ADC12MEM3;
                adc_values[4] = ADC12MEM4;
                adc_values[5] = ADC12MEM5;
                adc_values[6] = ADC12MEM6;
                adc_values[7] = ADC12MEM7;
                __bic_SR_register_on_exit(LPM0_bits);
                break;
    
        }
    
    }
    
    
    

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

    您好!

    我添加了电压基准选择、它很有效。 这是代码的最后一个版本。  

    感谢您的帮助。

    #include <msp430.h>
    #include <stdint.h>
    
    volatile uint16_t adc_values[8]; // ADC değerlerini saklayacak dizi
    volatile uint8_t adc_index = 0;  // ADC dizisi indeksi
    
    
    void main(void) {
    
        WDTCTL = WDTPW + WDTHOLD;
        PM5CTL0 &= ~LOCKLPM5;
    
        P9SEL0 |= 0xFF;
        P9SEL1 |= 0xFF;
    
    
        ADC12CTL0 = ADC12SHT0_2 | ADC12MSC | ADC12ON; 
        ADC12CTL1 = ADC12SHP | ADC12CONSEQ_1;                     
        ADC12CTL2 = ADC12RES_2; 
        ADC12CTL3 = ADC12CSTARTADD_0;
        ADC12MCTL0 |= ADC12INCH_8 | ADC12VRSEL_1 ; 
        ADC12MCTL1 |= ADC12INCH_9 | ADC12VRSEL_1; 
        ADC12MCTL2 |= ADC12INCH_10 | ADC12VRSEL_1 ; 
        ADC12MCTL3 |= ADC12INCH_11 | ADC12VRSEL_1 ;
        ADC12MCTL4 |= ADC12INCH_12 | ADC12VRSEL_1 ; 
        ADC12MCTL5 |= ADC12INCH_13 | ADC12VRSEL_1 ;
        ADC12MCTL6 |= ADC12INCH_14 | ADC12VRSEL_1 ;
        ADC12MCTL7 |= ADC12INCH_15 | ADC12VRSEL_1 | ADC12EOS; 
    
    
        while(REFCTL0 &REFGENBUSY);
        REFCTL0 |= REFVSEL_1 | REFON;
        while(!(REFCTL0 &REFGENRDY));
    
        ADC12IER0 |= ADC12IE7;
        
        ADC12CTL0 |= ADC12ENC;
    
    
        while(1) {
            ADC12CTL0 |= ADC12SC | ADC12ENC;   // ADC örnekleme ve dönüşümü başlat
           __bis_SR_register(LPM0_bits | GIE);
    
        }
    }
    
    
    
    
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC_ISR(void) {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
    
            case ADC12IV_ADC12IFG7:
                adc_values[0] = ADC12MEM0;
                adc_values[1] = ADC12MEM1;
                adc_values[2] = ADC12MEM2;
                adc_values[3] = ADC12MEM3;
                adc_values[4] = ADC12MEM4;
                adc_values[5] = ADC12MEM5;
                adc_values[6] = ADC12MEM6;
                adc_values[7] = ADC12MEM7;
                __bic_SR_register_on_exit(LPM0_bits);
                break;
    
        }
    
    }