我想测试一下MAP430F149的adc12采样速率,测出来大概在168KHZ左右,后来又测了一遍,变成了285Khz。但是改变SHT的时候采样速率都没有变化。想请教各位大神原因在哪。程序如下:
#include <msp430x14x.h>
unsigned int adc
timerFlowCnt;
unsigned int adcResults[Num_of_Results];
unsigned int adcConvTime;
unsigned int flag;
void int_clk(void)
{
unsigned char i;
BCSCTL1&= ~XT2OFF;
BCSCTL2 |=SELM1; //MCLK为8M
BCSCTL2 |=SELS + DIVS_3; //SMCLK为1M
do
{
IFG1 &= ~OFIFG;
for(i = 0; i< 100; i++)
_NOP();
}
while((IFG1 & OFIFG)!= 0);
IFG1 &= ~OFIFG;
}
void int_adc()
{
P6SEL |= 0X01;
ADC12CTL0 = ADC12ON + SHT0_2+REFON+REF2_5V+MSC; //AD采样转换时间为16倍
ADC12CTL1 = SHP; //设置采样定时器
ADC12CTL1 |= ADC12SSEL_3; //设置转换时钟
ADC12CTL1 |= CONSEQ_2; //单通道多次采样
ADC12MCTL0 |= INCH_0; //A0输出
ADC12IE = 0X01; //中断允许
ADC12CTL0 |= ENC;
}
void int_timer(void)
{
TACTL = TASSEL_2; //时钟为SMCLK
TACTL |= ID_0; //不分频
TACTL |= MC_1; //增计数模式
TACTL |= TACLR;
TACTL |= TAIE; //中断使能
TACCR0 = 49999;
}
#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A (void)
{
switch (TAIV)
{
case 2:break;
case 4 :break;
case 10 :
adcTimerFlowCnt++; //溢出标志
break;
default :break;
}
}
# pragma vector = ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index =0;
index++;
if ( index == 100 )
{
ADC12CTL0 &=~ENC; //停止ADC转换
TACTL |= MC_0; //定时器A暂停,TAR值保持不变
adcConvTime =TAR; //保存TAR值
TACTL &= ~TAIE; //禁止TA溢出中断
index =0;
}
else if ( index ==1 )
{
int_timer(); //启动定时器A开始计时
adcTimerFlowCnt =0;
}
//不启动中断嵌套,执行完后需重新使能系统中断
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
int_clk();
int_adc();
_EINT();
ADC12CTL0 |= ADC12SC;
while (1);
}
基于MSP430定时器频率测量:http://bbs.ednchina.com/BLOG_ARTICLE_3009061.HTM
MSP430内部ADC12采样时钟与转换时钟区别http://www.amobbs.com/thread-5509957-1-1.html
一周热门 更多>