程序目的是以2000Hz频率采样思路数据,ADC采用序列通道模式,TimeB.OUT1控制。由TimeB.OUT1的频率决定ADC采样频率。现在问题是程序只响应一次中断,不知道哪儿有问题,请专家指点。
程序主要部分如下:
* XT2晶振 20MHZ
* MCLK = 20MHz,
* SMCLK =20MHZ
* ACLK =0.625MHZ,
#include <msp430x54xA.h>
unsigned int results[4];
//************************************************************#define SMCLK 20000000 //SMCLK频率
#define Hz 50 //频率
#define point 40 //采样点数
/*************************************************
函数(模块)名称:void Init_TB(void)
功能: 定时器B初始化
*************************************************/
void Init_TB(void)
{
//\************************************************************* //示波器观察
P4DIR|= BIT1; //方向选择 TB0 CCR1输出,示波器观察 0.5ms(500us)一个周期
P4SEL|= BIT1; //端口功能选择
//\************************************************************* //Setup Timer B0
TBCCR0 = SMCLK/(Hz*point);
TBCCR1 = TBCCR0/2;
TBCCTL1 = OUTMOD_3; // CCR1 set/reset mode
TBCTL = TBSSEL_2+MC_1+TBCLR; // SMCLK, Up-Mode,Timer_B clear.
//TBCTL = TBSSEL_2+MC_1;
}
/*************************************************
函数(模块)名称:void Init_ADC12(void)
功能: ADC12初始化
*************************************************/
void Init_ADC12(void)
{
P6SEL = 0x0F; // Enable A/D channel inputs
/* Initialize ADC12_A */
ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_2; // Turn on ADC12, set sampling time
ADC12CTL1 = ADC12CSTARTADD_0+ADC12SHS_3+ADC12SHP+ADC12DIV_3+ADC12SSEL_2+ADC12CONSEQ_1;
ADC12CTL2=ADC12TCOFF+ADC12RES_2;
ADC12MCTL0 = ADC12INCH_0;
ADC12MCTL1 = ADC12INCH_1;
ADC12MCTL2 = ADC12INCH_2;
ADC12MCTL3 = ADC12INCH_3+ADC12EOS;
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ADC12ENC; // Enable conversions
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // 停止看门狗
P1DIR|= BIT4; //示波器观察窗口
Init_Clk();//时钟初始化
Init_ADC12();//ADC12初始化
Init_TB();//TB初始化
__enable_interrupt();
for(;;)
{
_NOP();
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: // Vector 12: ADC12IFG3
_NOP();
results[0] = ADC12MEM0; // Move results, IFG is cleared
results[1] = ADC12MEM1; // Move results, IFG is cleared
results[2] = ADC12MEM2; // Move results, IFG is cleared
results[3] = ADC12MEM3; // Move results, IFG is cleared
P1OUT ^= BIT4;
break;
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
Peter_Zheng:
你好,程序大概看了一下, 没看到TimerB的PWM频率决定了ADC的采样频率。应该在timerB里定时去进行ADC采样更好。
Charles Wu:
回复 Peter_Zheng:
只发生一次中断是正常的啊,ADC12是序列通道单次采样,并没有再次开始采样的代码啊。
Charles Wu:
回复 Charles Wu:
也不像是漏了TimerB的中断处理函数啊,TB的初始化代码中,也没有打开TB的中断允许位啊。