各位大神:
你们好,我现在正在使用MSP430FR6972芯片,今天写了一个定时器触发AD采样的程序,用TB0CCR1来触发AD12来进行单次序列采样,采通道2,3,15的数据,目前情况是定时器可以触发AD采样,能进入AD中断,但是从通道中采出来的值不正确,且均一直为0,不知问题何在,求各位帮忙,小弟不胜感激!驱动程序如下
void ADC12_B_init ( )
{
ADC12CTL0 &= ~ADC12ENC; //使 AD 模块处于初始状态
ADC12CTL0 |= ADC12ON + ADC12MSC + ADC12SHT0_4 + ADC12SHT1_4; // 采样AD使能,采样通道保持时钟
ADC12CTL1 |= ADC12SHP + ADC12CONSEQ1 + ADC12SHS_3; //脉冲序列采样,TB0CCR1触发
ADC12CTL2 |= ADC12RES2; //分辨率 12位
ADC12CTL3 |= ADC12CSTARTADD_2; //Starting Memory Add
ADC12CTL0 |= ADC12ENC; // Start sampling/conversion
ADC12MCTL2 = ADC12INCH1 + ADC12VRSEL2 ; // 通道号2,参考电压2.5v
ADC12MCTL3 = ADC12INCH0 + ADC12INCH1 + ADC12VRSEL2 ; // 通道号3,参考电压2.5v
ADC12MCTL15 = ADC12INCH0+ ADC12INCH1 + ADC12INCH2 + ADC12INCH3 + ADC12VRSEL2 + ADC12EOS;// 通道号15,参考电压2.5v 结束
ADC12IER0 = ADC12IE15 ;//通道中断 */
}
void Timer_B_initUpMode ( )
{
TB0CTL |= TASSEL__SMCLK + TBCLR + TIMER_B_UP_MODE;
TB0CCTL0 &=(~CCIE);
TB0CCR0 = 250;
TB0CCR1 = 240;
TB0CCTL1 |= 0x0060;//output mod set/reset
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR ( void )
{
SampleData.fAI[0][cy_index] = ADC12MEM2;
SampleData.fAI[1][cy_index] = ADC12MEM3;
SampleData.fAI[2][cy_index] = ADC12MEM15;
cy_index++;
if ( cy_index >= AD_OneDataSize )
{
cy_index = 0;
}
}
灰小子:
ADC12MCTLx那几个寄存器不是这样用的,建议先参考官网例程