小弟想用430的捕获模式采集ICL7135的电压值,程序如下,但是结果一直不对,请教大侠给点儿指导
//AD采样
void AD7135(unsigned char n)
{
Choose_0_sin();
delay(50000);delay(50000);delay(50000);delay(50000);
//开关变换等待转换信号稳定,大约25ms昨右。
//如果换成100nF的电容这个延时可以小一些
UpFlag = 0;
DownFlag = 0;
OverFlow = 0;
while((UpFlag == 1)||(DownFlag == 1));//等待产生捕获完成
width = end-start-10001+65535*OverFlow;
if(n)
{
a = width;
if(~POL)//极性
a = -a;
}
else
{
c = width;
if(~POL)
c = -c;
}
Choose_90_sin();
delay(50000);delay(50000);delay(50000);delay(50000);
UpFlag = 0;
DownFlag = 0;
OverFlow = 0;
while((UpFlag == 1)||(DownFlag == 1));
width = end-start-10001+65535*OverFlow;
if(n)
{
b= width;
if(~POL)
b = -b;
}
else
{
d= width;
if(~POL)
d = -d;
}
}
#pragma vector=TIMERA1_VECTOR //==定时器A中断处理==
__interrupt void timer_a(void)
{
switch(TAIV) //==向量查询==
{ case 2: //==捕获中断==
if(CCTL1&CM0) //==捕获到上升沿==
{
CCTL1=(CCTL1&(~CM0))|CM1; //==更变设置为下降沿触发==
start=TAR; //==记录初始时间==
UpFlag = 1;
}
else if (CCTL1&CM1) //==捕获到下降沿==
{
CCTL1=(CCTL1&(~CM1))|CM0; //==更变设置为上升沿触发==
if(1 == UpFlag)
{
end=TAR; //==用start,end,overflow计算脉冲宽度==
DownFlag = 1;
}
}
break;
case 0x0a:if(1 == UpFlag)OverFlow++;
default:
break;
}
}
void init_timerA()//用捕获功能,捕获AD7135的busy线
{
TACTL = TASSEL_2+TACLR+TAIE+MC1+ID_2;
P1DIR&=~BIT2;
P1SEL = BIT2; //设置P1.2端口为功能模块使用,即:做捕获源
CCTL1 = CM_1+SCS+CAP+CCIE; //输入上升沿捕获,CCI0A为捕获信号源
}
void init_timerB()
{
TBCCTL0 = CCIE; // CCR0 interrupt enabled
TBCCR0 = 5;
TBCTL = TBSSEL_2 + MC_2; // SMCLK, contmode
//为连续模式,并且使能中断
}
此帖出自
小平头技术问答
一周热门 更多>