MSP430如何测试ADC12采样速率
时间:10-02
整理:3721RD
点击:
我想测试一下MAP430F149的adc12采样速率,测出来大概在168KHZ左右,后来又测了一遍,变成了285Khz。但是改变SHT的时候采样速率都没有变化。想请教各位大神原因在哪。程序如下:
#include <msp430x14x.h>
unsigned int adcTimerFlowCnt;
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);
}
#include <msp430x14x.h>
unsigned int adcTimerFlowCnt;
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
ADC12CLK 的功能是为 ADC12 提供转换时钟。ADC12CLK 的最小和最大时钟分别近似为 500kHz和 6.5MHz。最快的完全转换周期为 17 个时钟周期(转换为 13 个时钟周期,采样保持为 4 个时钟周期)。6.5MHz/17 = 382ksps.ADC12 的时钟周期不能小于ADC12CLK 的最小周期,但在软件控制下可以使采样一直处于开启状态。