ADC采样数据总是不对,不知道是不是设置不对,构思是这样的,定时器定时156.25us采样一个点,需要采样四组
外接晶振8M
void initTA(void) //156.25us
{
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 1247;
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
}
/*===========================================================================
扫描采样AN0-AN5共6个通道模拟信号
=============================================================================*/
void initAdc1(void)
{
ADC12CTL0 &= ~ENC;
P6SEL = BIT4 | BIT5 | BIT6 ; // Enable A/D channel inputs
ADC12CTL0 |= ADC12ON+MSC+SHT0_2; // Turn on ADC12, extend sampling time采样时间? MSC次采样和转换
ADC12CTL1 |= SHP+CONSEQ_1+ADC12SSEL_3;
ADC12MCTL0 |= SREF_0; // 模拟参考电压
ADC12MCTL4 |= INCH_4; // ref+=AVcc, channel = A4
ADC12MCTL5 |= INCH_5; // ref+=AVcc, channel = A5
ADC12MCTL6 |= INCH_6+EOS; // ref+=AVcc, channel = A6,end seq
ADC12IE=0X40;
ADC12CTL0 |= ENC; // Enable conversions
}
/*——————————————————————————
ADC采样6次后中断,读取转换结果并关闭自动采样
——————————————————————————-*/
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void) //关闭自动采样
{
// Enable conversions
sambuffh[IC][phase]=ADC12MEM4;
sambuffh[IB][phase]=ADC12MEM5;
sambuffh[IA][phase]=ADC12MEM6;
// ADC12IFG=0;
}
void main(void)
{
int i;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 &=~XT2OFF;//启动XT2时钟
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i–); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_2+SELS ; // MCLK SMCLK = XT2模式 SELM_2 + SELS
initTA();
initAdc1();
_EINT();
while(1)
{
;
}
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void) //156.25us
{
phase++;
ADC12CTL0 |= ENC+ADC12SC;
CCR0 = 1247;
}
kqian0327:
你好,
建议你参考一下TI的ADC例程。
我看完你的程序,我有几个问题
1:.你ADC输入的信号是交流还是直流?
2.不对是怎么不对?读的值和实际值有偏差还是完全不对?
XiaoChuan Li:
回复 kqian0327:
你好
1、是交流信号
2、数据如下
我之前觉得是定时器的问题。导致有部分点没有采集到,但是该了定时时间依然这样