ADC12CTL0 &= ~ENC;
ADC12CTL1 = SHP+CO,NSEQ_2+ADC12SSEL_3+ADC12DIV_7;
ADC12MCTL0 = INCH_10+SREF_1+MSC;
ADC12CTL0 = SHT0_8+ADC12ON+REFON+REF2_5V;
ADC12IE = 0x0001;
_EINT();
ADC12CTL0 |= ENC;
ADC12CTL0 |= ADC12SC;
中断程序
vol=ADC12MEM[0];
vol=vol/4095*2.5;
num++;
_BIC_SR_IRQ(LPM0_bits);
通过液晶显示得num永远为1 vol=1.09XX;
感觉就是中断只进入了一次就再也没发生中断了
Ken Wang:
Hi xiaolong,
你需要配置是基于sequence的采样吗?是单次的还是多次循环的采样?
在我们的CCS里面有相关的例程,可以供你参考。
/* –COPYRIGHT–,BSD_EX * Copyright (c) 2012, 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–*///******************************************************************************// MSP-FET430P140 Demo – ADC12, Repeated Sequence of Conversions//// Description: This example shows how to perform a repeated sequence of// conversions using "repeat sequence-of-channels" mode. AVcc is used for the// reference and repeated sequence of conversions is performed on Channels A0,// A1, A2, and A3. Each conversion result is stored in ADC12MEM0, ADC12MEM1,// ADC12MEM2, and ADC12MEM3 respectively. After each sequence, the 4 conversion// results are moved to A0results[], A1results[], A2results[], and A3results[].// Test by applying voltages to channels A0 – A3. Open a watch window in // debugger and view the results. Set a breakpoint in the last line to see the // array values change sequentially.//// Note that a sequence has no restrictions on which channels are converted.// For example, a valid sequence could be A0, A3, A2, A4, A2, A1, A0, and A7.// See the MSP430x1xx User's Guide for instructions on using the ADC12.////// MSP430F149// —————–// | |// Vin0 –>|P6.0/A0 |// Vin1 –>|P6.1/A1 |// Vin2 –>|P6.2/A2 |// Vin3 –>|P6.3/A3 |// | |////// M. Mitchell// Texas Instruments Inc.// Feb 2005// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A//******************************************************************************
#include <msp430.h>
#define Num_of_Results 8
static unsigned int A0results[Num_of_Results]; // These need to be global instatic unsigned int A1results[Num_of_Results]; // this example. Otherwise, thestatic unsigned int A2results[Num_of_Results]; // compiler removes them becausestatic unsigned int A3results[Num_of_Results]; // they are not used
int main(void){ WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer P6SEL = 0x0F; // Enable A/D channel inputs ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time // to avoid overflow of results ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0 ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1 ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2 ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq. ADC12IE = 0x08; // Enable ADC12IFG.3 ADC12CTL0 |= ENC; // Enable conversions ADC12CTL0 |= ADC12SC; // Start conversion __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, Enable interrupts}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)#pragma vector=ADC12_VECTOR__interrupt void ADC12ISR (void)#elif defined(__GNUC__)void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)#else#error Compiler not supported!#endif{ static unsigned int index = 0;
A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint here}
谢谢
ken
lin xiaolong:
回复 Ken Wang:
谢谢。我调试下。
TI中文支持网



