5159|11

75

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

关于AD采集在运行一段时间数据不再更新的问题 [复制链接]

最近做了个项目出了,需要与一个串口设备进行通讯,并且采集7路AD,结果运行一段时间后,串口还在工作,AD数据却不更新了,那位大哥知道这是什么问题啊??
下面是我的程序:
#include <MSP430x14x.h> // Standard Definition Control Register
#define ADCMEM ((int*) 0x0140) // ADC12MEMx definition

void USART0_init(void); // Initialization USART1
void ADC12_init(void); // Initialization ADC12
void Port_init(void); // Initialization Port
void Data_process(void); // TCU data process

void Fill_txbuf1(void);
void Data_process(void);
void AD_start(void);

unsigned char send2TCU(unsigned char info);

unsigned char tx_buf1[50] = {0xeb, 0x90, 0x24,'E'} ;
unsigned char array_rx0[20];
unsigned char data_buf[4];
unsigned char tx1_i = 0, tx0_i = 0, rx0_i = 0;
unsigned char rx0_sign = 0;
unsigned char num = 0;
unsigned int sel=10,sign =0,tm=0;

void WDT_Stop( void )
{
WDTCTL = WDTPW +WDTHOLD; // Stop watchdog timer
}

void Clock_XT2( void )
{
unsigned int i;
P5SEL |= 0x30; //For test MCLK/SMCLK
P5DIR |= 0x30;
BCSCTL1 &= ~XT2OFF; //Select XT2--8Mhz
do
{
IFG1 &= ~OFIFG;
for (i = 0xFF; i > 0; i--);
}
while ((IFG1 & OFIFG) != 0);
BCSCTL2 |= SELM1 +SELS+DIVS1+DIVS0;
}
/*----------------------------------------------------------------------------*/
void USART0_init(void)
{
/* USART Settings:
UART function, Idle line multiprocessor Protocol,
9600 baud, 8 data bits, no parity, 1 stop bit */
UCTL0 &=~ SWRST; // reset SWRST bit
UCTL0 |= CHAR;
URCTL0 &= ~URXWIE;
UBR00 = 0xd0; //1000000/4800=208.66667(0x00d0)
UBR10 = 0x00;
UMCTL0 = 0x25; //0x75 5/8=0.6333333
UTCTL0 = SSEL1 + TXEPT; //sel SMCLK=MCLK
ME1 |= UTXE0 + URXE0; //ena××e USART1 TXD/RXD
IE1 |= URXIE0;
P3SEL |= 0x30; // Pin P3.6 used by USART module
P3DIR |= 0x10; // Pin P3.6 is output
}
/*----------------------------------------------------------------------------*/
void USART1_init(void)
{
UCTL1 &= ~SWRST;
UCTL1 |= CHAR; // 8-bit character,1 stop bit,no parity;SWRST=0;
UBR01 = 0x34;
UBR11 = 0x00;
UMCTL1 = 0x01;
UTCTL1 = SSEL1 + TXEPT; // UCLK = SMCLK
ME2 |= UTXE1 + URXE1; // Ena××e USART1 TXD/RXD
IE2 |= UTXIE1 + URXIE1 ; // Ena××e USART1 RX interrupt
P3SEL |= 0xC0; // P3.6,7 = USART1 TXD/RXD
P3DIR |= 0x40; // P3.6 output direction
}
/*---------------------------------------------------------------------------*/
void ADC12_init(void)
{
/* ADC12 Settings: */
ADC12CTL0 &= ~0x20; // Reset ENC
/* selection of reference and input */
ADC12MCTL0 = 0x10; // Ref = ××ss,Vref+;Input = A0
ADC12MCTL1 = 0x11; // Ref = ××ss,Vref+;Input = A1
ADC12MCTL2 = 0x12; // Ref = ××ss,Vref+;Input = A2
ADC12MCTL3 = 0x14; // Ref = ××ss,Vref+;Input = A4
ADC12MCTL4 = 0x15; // Ref = ××ss,Vref+;Input = A5
ADC12MCTL5 = 0x16; // Ref = ××ss,Vref+;Input = A6
ADC12MCTL6 = 0x17; // Ref = ××ss,Vref+;Input = A7
ADC12MCTL7 = 0x9A; // Ref = ××ss,Vref+;Input = A10



// ADC12MCTL3 is end of sequence
// (EOS bit is set!)
ADC12CTL1 = 0x0202; // first conv. result is stored in ADC12MEM0
// ADC12SC bit triggers Sample&Hold
// sample pulse is generated by Sampling Timer
// Clock Source: ADC12 internal oscillator
// Clock divider: 1
// conversion mode: one single sequence
ADC12CTL0 = 0x0070; // Sample&Hold Time 0
// Sample&Hold Time 1
// Multiple Sample&Hold:only one sample is taken
// reference voltage is off
// ADC12 module is switched on
// no interrupts
ADC12CTL0 |= 0x02; // ena××e conversion
}
/*-------------------------------------------------------------------*/
void TimerA_init(void)
{
TACTL = TASSEL1 + TACLR; //SMCLK 1/8
CCTL0 = CCIE; //CCR0 E_int
CCR0 = 30000; //60ms EOM
}
/*---------------------------------------------------------------------------*/
void TimerB_init(void)
{
TBCTL = TBSSEL1 + TBCLR; //SMCLK 1/8
TBCCTL0 = CCIE; //CCR0 E_int
TBCCR0 = 25000; //25ms EOM
TBCTL |= MC1+MC0;
}
/*---------------------------------------------------------------------------*/
void Port_init(void)
{
P5DIR |= 0x0f;
P5OUT &= 0xf0;
}
/*---------------------------------------------------------------------------*/
void Fill_txbuf1(void)
{
unsigned char checksum = 0;
unsigned char i;
for(i = 0;i<35;i++) checksum = checksum ^ tx_buf1[i];
tx_buf1[35] = checksum;
if(((UTCTL1&0x01)!=0) && (tx1_i==0))
{
TXBUF1 = tx_buf1[0];
P5OUT ^= BIT2;
}
}
/*---------------------------------------------------------------------------*/
void AD_process(void)
{
unsigned int data0,data1;
unsigned char data2,data3,data4,data5,data6,data7;
data0 = (unsigned int)((ADC12MEM0*2.5/4096)*400);
data1 = (unsigned int)((ADC12MEM1*2.5/4096)*400);
data2 = (unsigned char)((ADC12MEM2*2.5/4096)*100);
data4 = (unsigned char)((ADC12MEM3*2.5/4096)*100);
data5 = (unsigned char)((ADC12MEM4*2.5/4096)*100);
data6 = (unsigned char)((ADC12MEM5*2.5/4096)*100);
data7 = (unsigned char)((ADC12MEM6*2.5/4096)*120);


tx_buf1[30]=(unsigned char)(data0 & 0x00ff);
tx_buf1[31]=(unsigned char)(data0 >> 8);
tx_buf1[32]=(unsigned char)(data1 & 0x00ff);
tx_buf1[33]=(unsigned char)(data1 >> 8);
tx_buf1[26]=data2;
tx_buf1[27]=data4;
tx_buf1[28]=data5;
tx_buf1[29]=data6;
tx_buf1[34]=data7;
}
/*---------------------------------------------------------------------------*/
#pragma vector = UART1TX_VECTOR
__interrupt void usart1_tx (void)
{
if(tx1_i<35)
{
tx1_i++;
TXBUF1=tx_buf1[tx1_i];
}
else
{
tx1_i=0;
}
}
/*-------------------------------------------------------------------*/
#pragma vector = TIMERB0_VECTOR
__interrupt void TimerB0(void)
{
sel--;
switch (sel)
{
case 9 :
send2TCU(0x03);
sign=3;
break;
case 8 :
send2TCU(0x04);
sign=4;
break;
case 7 :
send2TCU(0x05);
sign =5;
break;
case 6:
send2TCU(0x06);
sign = 6;
break;
case 5:
send2TCU(0x07);
sign=7;
break;
case 4:
send2TCU(0x0a);
sign=8;
break;
case 0:
AD_start();
sel = 10;
break;
default:
break;
}
}
/*---------------------------------------------------------------------------*/
#pragma vector = TIMERA0_VECTOR
__interrupt void TimerA0(void)
{
P5OUT ^= BIT3;
tm=1;
}
/*---------------------------------------------------------------------------*/
void AD_start(void)
{
unsigned int i;
unsigned int j;
for (i=0;i<=7;i++) // generate trigger for each measurement
// this is needed because MSH bit = 0 !!!
{
ADC12CTL0 |= 0x01; // start sampling
ADC12CTL0 &=~0x01; // ADC12SC must be reset manually
// because ADC12 is active during the
// whole sequence (see bit description!)
for (j=0;j<=1000;j++); // wait loop (delay next measurement)
}

while ((ADC12CTL1&0x01)==1); // wait until AD conversion is finished
for (i=0;i<=4000;i++); // wait loop (delay between sequences)
AD_process();
Fill_txbuf1();
}
/*---------------------------------------------------------------------------*/
#pragma vector = UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
if(rx0_i==0) //First receive
{
array_rx0[0]=RXBUF0;
rx0_i++;
TACTL |= MC0; //Start TimerA 60ms
tm =0; //TimerA flag
}
else
{
if((URCTL0&0xf1)==0x0) //no error_sign_bit
{
array_rx0[rx0_i]=RXBUF0; //loop receive data
rx0_i++;
}
else
{
//rx0_i=0;
//tm=0;
}
}
}

最新回复

那个引脚搞错了?LM317是做什么的阿?我好像没用这个。  详情 回复 发表于 2008-10-21 09:10
 
点赞 关注

回复
举报

69

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
继续:
void main(void)
{
WDT_Stop();
Clock_XT2();
USART0_init();
USART1_init();
ADC12_init();
TimerA_init();
TimerB_init();
Port_init();
WDTCTL = WDTPW ; // Start watchdog timer
_EINT();

while (1)
{
WDTCTL = WDTPW +WDTCNTCL; // Reset watchdog timer
if(tm==1) //TimerA 30ms end
{
TACTL &= ~MC0; //Close TimerA
num = rx0_i;
if (num>7)Data_process();
tm = 0;
rx0_i = 0;
}
}
}
/*---------------------------------------------------------------------------*/
unsigned char send2TCU(unsigned char info)
{
TXBUF0=0x01;
while ((UTCTL0&0x01)==0);
TXBUF0=0x70;
while ((UTCTL0&0x01)==0);
TXBUF0=info;
while ((UTCTL0&0x01)==0);
TXBUF0=0x70+info;
while ((UTCTL0&0x01)==0);
TXBUF0=0x02;
while ((UTCTL0&0x01)==0);
return 0;
}
/*---------------------------------------------------------------------------*/
void Data_process(void)
{
unsigned char temp1[20],temp2[20];
unsigned char i=0 ,j=0,checksum = 0;
if((array_rx0[0]==0x01) && (array_rx0[1]==0x41))
{

for(i=0;i<num-4;i++) temp1[i] = array_rx0[i+2];
if(temp1[0]==0) for(i=0;i<num-4;i++) temp2[i] = temp1[i+1];
else for(i=0;i<num-4;i++) temp2[i] = temp1[i];
if(temp2[1]==0)
{
for(i=0;i<1;i++) temp1[i] = temp2[i];
for(i=1;i<num-4;i++) temp1[i] = temp2[i+1];
}
else for(i=0;i<num-4;i++) temp1[i] = temp2[i];
if(temp1[2]==0)
{
for(i=0;i<2;i++) temp2[i] = temp1[i];
for(i=2;i<num-4;i++) temp2[i] = temp1[i+1];
}
else for(i=0;i<num-4;i++) temp2[i] = temp1[i];
if(temp2[3]==0)
{
for(i=0;i<3;i++) temp1[i] = temp2[i];
for(i=3;i<num-4;i++) temp1[i] = temp2[i+1];
}
else for(i=0;i<num-4;i++) temp1[i] = temp2[i];
for(j=0;j<4;j++) data_buf[j] = temp1[j];
}
switch(sign)
{
case 3:
for(i=0;i<4;i++) tx_buf1[i+4] = data_buf[i];
sign=0;
break;
case 4:
for(i=0;i<4;i++) tx_buf1[i+8] = data_buf[i];
sign=0;
break;
case 5:
for(i=0;i<4;i++) tx_buf1[i+12] = data_buf[i];
sign=0;
break;
case 6:
for(i=0;i<2;i++) tx_buf1[i+16] = data_buf[i];
sign=0;
break;
case 7:
for(i=0;i<4;i++) tx_buf1[i+18] = data_buf[i];
sign=0;
break;
case 8:
for(i=0;i<4;i++) tx_buf1[i+22] = data_buf[i];
sign=0;
break;
default:
break;
}

}
完毕
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
楼主能否把面缩小点?
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

4
 
程序乱了一点。。
程序主要就是实现:先与串口设备进行通信获得串口设备的参数,然后和AD采集的数据一起用另外一个串口发送出去。TimerA用于串口通信,TimerB用于采集。
结果运行了一段时间,串口还在向外发送数据,一起打包下来的AD采集的数据却不更新了。。。
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

5
 
大侠主要帮我看看ADC12_init(),AD_process()以及AD_start()和TimerB0()的时序有没有问题。
会不会有干扰造成AD数据不更新??
因为我在测试的时候从来没有出现这种情况,而在实际应用中和其他设备接在一起就出现了这种情况。
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

6
 
你AD采用什么模式的?
 
 
 

回复

77

帖子

0

TA的资源

一粒金砂(初级)

7
 
好象ADC12ON位没处理吧
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

8
 
应该是单通道单次转换模式
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

9
 
ADC12ON开了阿,ADC12CTL0 = 0x0070;这句开的,可能没有按ADC12CTL0 |= ADC12ON写不好看。
而且一开始AD是能更新数据的,运行了20来分钟才不更新的。但是串口数据还在发送。
所以程序应该没死。
所以想不出是什么原因。。
 
 
 

回复

62

帖子

0

TA的资源

一粒金砂(初级)

10
 
LZ的D2和C2是做什么的,拿掉试试
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

11
 
仔细看,终于发现问题了,LZ的LM317引脚搞错了。
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

12
 
那个引脚搞错了?LM317是做什么的阿?我好像没用这个。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表