共2条
1/1 1 跳转至页
f149,adc12 f149的adc12进行波形采样请教
问
请教大虾们了。。。
我用f149的adc12进行波形采样,使用p6.0,序列通道多次(都设成p6.0),
当调用ADC_start()时,触发定时器TA产生采样转换时序,进行采样
当调用ADC_stop()时,要求停止采样
以下程序好像不行,我触发采样ADC_start()后,好像就停不下来了ADC_stop(),advalue[500]一下子就满了。。
请大虾们看看,或者有什么错,请指正,不胜感激
#include <MSP430x14x.h>
unsigned int ADvalue[500]; //存放模数转换结果的数组
unsigned int ADindex=0; //模数转换结果的数组的实际指针
void ADC_stop(void);
void ADC12Init(void)
{
//设置TA产生采样时序,光电信号可用来引发TA启动计数MC_2
// TACTL = TASSEL_2+MC_2; // TA选用SMCLK,不分频,连续计数模式,不产生中断
TACTL = TASSEL_2+ID_3; // TA选用SMCLK,不分频,连续计数模式,不产生中断
TACCTL1 = OUTMOD_3; // CCR1 setup输出为PWM置位/复位
TACCR1 = 0xffff; // Compare value 设置ccr1的值
ADC12CTL0&=~ENC; //关闭adc12转换允许位
ADC12CTL0 = SHT0_8+SHT1_8+MSC+ADC12ON; //开adc12内核,多次采样转换,T(sample)=4*64*T(adc12clk)
ADC12CTL1 = SHS_1+SHP+CONSEQ_3; //序列转换首地址为0,采样信号源TA.out1,序列通道多次
// ADC12CTL1 = SHS_1+SHP+CONSEQ_1; //序列转换首地址为0,采样信号源TA.out1,序列通道多次
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL2 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL3 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL4 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL5 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL6 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL7 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL8 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL9 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL10 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL11 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL12 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL13 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL14 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL15 = EOS+INCH_0; // ref+=AVcc, channel = A0
ADC12IE = 0xffff; // Enable ADC12IFG.0~ADC12IFG.15
}
// ADC中断服务程序
interrupt [ADC_VECTOR] void ADC(void)
{
unsigned int ADtemp1=0; //设置16次平均值模数采样的总值初始为0
ADtemp1=ADtemp1+ADC12MEM0; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM1; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM2; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM3; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM4; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM5; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM6; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM7; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM8; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM9; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM10; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM11; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM12; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM13; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM14; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM15; // Move results, IFG is cleared
ADvalue[ADindex]=(ADtemp1/16); //求16次采样的算术平均数
if (ADindex>498)
{
ADC_stop();
ADindex=0;//ADvalue模数转换数组实际指针超过500个,重新初始化为0
}
else
ADindex=ADindex+1;
}
void ADC_start(void)
{
TACTL = TACTL+MC_2; //启动TA
_NOP();_NOP();_NOP();_NOP();
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
}
void ADC_stop(void)
{
ADC12CTL0&=~ENC; //关闭adc12转换允许位
_NOP();_NOP();_NOP();_NOP();
TACTL = TASSEL_2+ID_3; //暂停TA
} 答 1: 1。这个程序首先AD12只能进行外部8位进行变换,
2。这个程序我觉得应该采用循环存储的形式,这样你都设置为A0,有时候没等中断标志过来的时候,数据已经进行了存储。 答 2: 你为什么不采用单通道多次转换呢?同样,也可以把每16次的值存起来再求平均!!! 答 3: 请问斑竹,针对楼主的问题我提出几点问题希望得到解决:
1。楼主设置的利用定时器TIMERA1。OUT进行触发SAMPON,我不大懂,你能帮我们理解一下吗?
2。怎么停止采样啊,象楼主的帖子里利用ADC12CTL0&=~ENC.这个指令为什么不能停止采样啊,书里面不是说了可以吗? 答 4: 引用:
我用f149的adc12进行波形采样,使用p6.0,序列通道多次(都设成p6.0),
当调用ADC_start()时,触发定时器TA产生采样转换时序,进行采样
当调用ADC_stop()时,要求停止采样
以下程序好像不行,我触发采样ADC_start()后,好像就停不下来了ADC_stop(),advalue[500]一下子就满了。。
请大虾们看看,或者有什么错,请指正,不胜感激
#include <MSP430x14x.h>
unsigned int ADvalue[500]; //存放模数转换结果的数组
unsigned int ADindex=0; //模数转换结果的数组的实际指针
void ADC_stop(void);
void ADC12Init(void)
{
//设置TA产生采样时序,光电信号可用来引发TA启动计数MC_2
// TACTL = TASSEL_2+MC_2; // TA选用SMCLK,不分频,连续计数模式,不产生中断
TACTL = TASSEL_2+ID_3; // TA选用SMCLK,不分频,连续计数模式,不产生中断
TACCTL1 = OUTMOD_3; // CCR1 setup输出为PWM置位/复位
TACCR1 = 0xffff; // Compare value 设置ccr1的值
ADC12CTL0&=~ENC; //关闭adc12转换允许位
ADC12CTL0 = SHT0_8+SHT1_8+MSC+ADC12ON; //开adc12内核,多次采样转换,T(sample)=4*64*T(adc12clk)
ADC12CTL1 = SHS_1+SHP+CONSEQ_3; //序列转换首地址为0,采样信号源TA.out1,序列通道多次
// ADC12CTL1 = SHS_1+SHP+CONSEQ_1; //序列转换首地址为0,采样信号源TA.out1,序列通道多次
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL2 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL3 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL4 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL5 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL6 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL7 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL8 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL9 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL10 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL11 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL12 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL13 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL14 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL15 = EOS+INCH_0; // ref+=AVcc, channel = A0
ADC12IE = 0xffff; // Enable ADC12IFG.0~ADC12IFG.15
}
// ADC中断服务程序
interrupt [ADC_VECTOR] void ADC(void)
{
unsigned int ADtemp1=0; //设置16次平均值模数采样的总值初始为0
ADtemp1=ADtemp1+ADC12MEM0; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM1; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM2; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM3; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM4; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM5; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM6; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM7; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM8; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM9; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM10; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM11; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM12; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM13; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM14; // Move results, IFG is cleared
ADtemp1=ADtemp1+ADC12MEM15; // Move results, IFG is cleared
ADvalue[ADindex]=(ADtemp1/16); //求16次采样的算术平均数
if (ADindex>498)
{
ADC_stop();
ADindex=0;//ADvalue模数转换数组实际指针超过500个,重新初始化为0
}
else
ADindex=ADindex+1;
}
void ADC_start(void)
{
TACTL = TACTL+MC_2; //启动TA
_NOP();_NOP();_NOP();_NOP();
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
}
void ADC_stop(void)
{
ADC12CTL0&=~ENC; //关闭adc12转换允许位
_NOP();_NOP();_NOP();_NOP();
TACTL = TASSEL_2+ID_3; //暂停TA
} 答 1: 1。这个程序首先AD12只能进行外部8位进行变换,
2。这个程序我觉得应该采用循环存储的形式,这样你都设置为A0,有时候没等中断标志过来的时候,数据已经进行了存储。 答 2: 你为什么不采用单通道多次转换呢?同样,也可以把每16次的值存起来再求平均!!! 答 3: 请问斑竹,针对楼主的问题我提出几点问题希望得到解决:
1。楼主设置的利用定时器TIMERA1。OUT进行触发SAMPON,我不大懂,你能帮我们理解一下吗?
2。怎么停止采样啊,象楼主的帖子里利用ADC12CTL0&=~ENC.这个指令为什么不能停止采样啊,书里面不是说了可以吗? 答 4: 引用:
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |