TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430I2041: ADC的位数问题

Part Number:MSP430I2041

根据数据手册的描述 ADC为24位,但是提供的demo程序接收转换结果是16位的,而且查看ADC的数据寄存器也是16位的

Susan Yang:

您是可以使用24bit的,但是由于没有24bit的数据,所以您需要使用 32bit的long

请参考下面的代码

/* --COPYRIGHT--,BSD_EX* Copyright (c) 2013, 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--*/
//******************************************************************************
//MSP430i20xx Demo - SD24, Continuous Conversion on a Single Channel
//
//Description: This program uses the SD24 module to perform continuous
//conversions on a single channel. A SD24 interrupt occurs when a conversion
//has completed.
//
//Test by applying voltages to the input channel and setting a breakpoint
//at the indicated line. Run program until it reaches the breakpoint, then use
//the debugger's watch window to view the conversion results.
//
//Results (upper 16 bits only) are stored in the array "results"
//
//ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
//* Ensure low_level_init.c is included when building/running this example *
//
//Notes: For minimum Vcc required for SD24 module - see datasheet
//100nF cap btw Vref and AVss is recommended when using 1.2V ref
//
//MSP430i20xx
//-----------------
///|\||
//| ||
//--|RST|
//||
//Vin1+ -->|A0.0+VREF |---+
//Vin1- -->|A0.0-||
//||-+- 100nF
//||-+-
//|||
//|AVss |---+
//
//T. Witt
//Texas Instruments, Inc
//September 2013
//Built with Code Composer Studio v5.5
//******************************************************************************
#include "msp430.h"/* Array to store SD24 conversion results */
volatile int j, index = 0;
volatile unsigned long sum = 0;
unsigned long results[100];// Final results from running average/* Defines */
#define SW_OVER_SAMPLING_FACTOR16/* Main Function */
void main(void) {WDTCTL = WDTPW | WDTHOLD;// Stop WDTSD24CTL = SD24REFS;// Internal refSD24INCTL0 = SD24GAIN_1;// Set gain on Channel 0SD24CCTL0 |= SD24IE;// Enable interrupt, OSR = 256 (default)__delay_cycles(3200);// Delay ~200us for 1.2V ref to settleSD24CCTL0 |= SD24SC;// Set bit to start conversion__bis_SR_register(GIE);// Enable interruptswhile(1) {// Loop endlessly, SET BREAKPOINT or PAUSE HERE}
}#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD24_VECTOR
__interrupt void SD24_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void)
#else
#error Compiler not supported!
#endif
{long temp = 0;switch (__even_in_range(SD24IV,SD24IV_SD24MEM3)) {case SD24IV_NONE: break;case SD24IV_SD24OVIFG: break;case SD24IV_SD24MEM0:// Capture ADC dataSD24CCTL0 &= ~SD24LSBACC;// Clear LSBACC bittemp = SD24MEM0;// Read upper 16 bits of SD24MEM0SD24CCTL0 |= SD24LSBACC;// Set LSBACC bittemp = temp*256 + (SD24MEM0&0xff);// Read lower 16 bits of SD24MEM0, combine with upper bits// Perform software oversamplingsum+= temp;// Add result to running sumj++;if(j >= SW_OVER_SAMPLING_FACTOR) {// Calculate and store averageresults[index++] = sum/SW_OVER_SAMPLING_FACTOR;sum = 0;j = 0;}if(index >=100) {index=0;}break;case SD24IV_SD24MEM1: break;case SD24IV_SD24MEM2: break;case SD24IV_SD24MEM3: break;default: break;}
}

,

?? ?:

非常感谢

,

Susan Yang:

很高兴能帮到您!

赞(0)
未经允许不得转载:TI中文支持网 » MSP430I2041: ADC的位数问题
分享到: 更多 (0)