编译器:IAR430 5.20
代码为:
#include <msp430.h>
#include "adc10.h"
#include "basictimer.h"
unsigned short tadc[2] = {0};
//A0 A1 A7
//p7.4 p7.5 p6.7
//多通道 多次采样
void init_adc10(void)
{
ADC10AE0 |= 0x03; // A1/A0, repeat multi channel
ADC10AE1 = 0;
ADC10CTL0 = ADC10SHT_2 + /*REF2_5V*/ + REFON + MSC + ADC10ON + ADC10IE; // ADC10ON, interrupt enabl 参考电压选1.5V
ADC10CTL1 = CONSEQ_3 + INCH_1; // A1/A0, repeat multi channel
ADC10DTC0 = 0; //数据传送控制寄存器0 ADC10DTC0设置为默认模式:单传送块模式,单块传送完停止
ADC10DTC1 = 2; // 4 conversions
//当多通道采样时,先采高的通道,再采低的通道。即A3的结果存储到Control_Val[0],A0的结果存储到Control_Val[3],由于A1、A2没有使能,所以在A2、A1的结果分别存储到Control_Val[1],Control_Val[2]的是不定的。存储顺数也是按照这个方式存储的。
}
void adc10(void)
{
ADC10CTL0 &= ~ENC; //ADC不使能
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ???
ADC10SA = (unsigned int)tadc;
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start ADC??,???? ADC10SC??????
close_key();
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force
open_key();
}
void close_adc10(void)
{
return;
ADC10CTL0 &= ~ENC; //ADC不使能,其他控制位必须在ENC为0时才可修改
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ???
ADC10AE0 = 0;
ADC10CTL0 = 0;
ADC10CTL1 = 0;
ADC10DTC0 = 0;
ADC10DTC1 = 0;
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) //中断响应以后,中断标志位自动清零
{
//ADC10CTL0 |= ENC + ADC10SC;
//ADC10SA = (short)(tadc);
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
问题:采样的AD值总是真实值的一半,怎么回事?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
104不算太大,不过可以改为103试一下
一周热门 更多>