msp430f149做PWM输出幅值有负的部分,怎么回事

#include"msp430x14x.h"#defineucharunsignedchar#defineuintunsignedintinta[400]=//定义400... #include "msp430x14x.h"
#define uchar unsigned char
#define uint unsigned int
int a[400]= //定义400点,用来改变占空比
{497,491,484,478,472,465,459,453,447,441,434,428,422,416,410,404,397,391,385,379,373,367,362,356,350,344,
338,333,327,321,316,310,305,299,294,288,283,278,273,267,262,257,252,247,243,238,233,228,224,219,215,211,
206,202,198,194,190,186,182,178,175,171,167,164,161,157,154,151,148,145,142,139,137,134,132,129,127,125,
123,121,119,117,115,113,112,110,109,108,107,105,104,104,103,102,101,101,101,100,100,100,100,100,100,101,
101,101,102,103,104,104,105,107,108,109,110,112,113,115,117,119,121,123,125,127,129,132,134,137,139,142,
145,148,151,154,157,161,164,167,171,175,178,182,186,190,194,198,202,206,211,215,219,224,228,233,238,243,
247,252,257,262,267,273,278,283,288,294,299,305,310,316,321,327,333,338,344,350,356,362,367,373,379,385,
391,397,404,410,416,422,428,434,441,447,453,459,465,472,478,484,491,497,503,509,516,522,528,535,541,547,
553,559,566,572,578,584,590,596,603,609,615,621,627,633,638,644,650,656,662,667,673,679,684,690,695,701,
706,712,717,722,727,733,738,743,748,753,757,762,767,772,776,781,785,789,794,798,802,806,810,814,818,822,
825,829,833,836,839,843,846,849,852,855,858,861,863,866,868,871,873,875,877,879,881,883,885,887,888,890,
891,892,893,895,896,896,897,898,899,899,899,900,900,900,900,900,900,899,899,899,898,897,896,896,895,893,
892,891,890,888,887,885,883,881,879,877,875,873,871,868,866,863,861,858,855,852,849,846,843,839,836,833,
829,825,822,818,814,810,806,802,798,794,789,785,781,776,772,767,762,757,753,748,743,738,733,727,722,717,
712,706,701,695,690,684,679,673,667,662,656,650,644,638,633,627,621,615,609,603,596,590,584,578,572,566,
559,553,547,541,535,528,522,516,509,503
};
int i = 0;

void main( void )
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
TACTL = TASSEL_2 + TACLR + MC0 + TAIE; //时钟源MCLK,清除定时器,增计数模式,开定时器A中断
TACCTL1 = OUTMOD_7; //PWM复位/置位模式
TACCR0 = 1000;
TACCR1 = a[i];
P1DIR = 0x04; //P1.2输出
P1SEL = 0x04;
_EINT();
while(1);
}

#pragma vector = TIMERA1_VECTOR //中断服务,修改TACCR1,改变占空比
__interrupt void Timer_A (void)
{
switch( TAIV )
{
case 10: if(i<=388)
{
i++;
TACCR1 = a[i];
}
else
{
i = 0;
TACCR1 = a[i];
};break;
default: break;
}
}
展开
 我来答
uw86vmt
2011-03-31 · TA获得超过741个赞
知道小有建树答主
回答量:652
采纳率:0%
帮助的人:286万
展开全部
面讲解非常详细。
你这个程序应该是可以实现的,不过相对比较复杂,要在中断中修改PWM输出控制寄存器。
我想了2种方法:
第一种:首先将TBCCR0时间设置为500us,TBCCR1、TBCCR2、TBCCR3时间分别
设置为530us,730us,930us.同时先将TB1输出方式SET/RESET(这样TB1能在500us时输出30us脉冲),TB2、TB3输出
方式设置为OUTPUT,并将相应的OUTX为设为0,这样在530us前TB2、TB3一直为低。当TB1脉冲结束时,
也就是在TBCCR1溢出中断中重新设置TB1 TB2 TB3寄存器,并且将TBCCR0增大为700us,使TB2在700us输出脉冲,TB1 TB3一直输出为低。
之后在TB2脉冲结束是再次在中断中进行配置,使TB3输出脉冲,TB1 TB2 输出为低。
这是在1ms内的设置,其他类似。具体程序怎么写你自己理解吧。

第二种:跟第一种类似,就是在其中TBX输出脉冲期间,设置暂时关闭其它两个输出(即将引进设置为非OUTPUT模式),
等待脉冲输出结束是在中断函数中进行一次寄存器配置,以使其中一个输出脉冲,另外两个输出为低。

另外: 如果你只需要完成这个功能的话完全可以用软件延时的方法实现。或TA TB配合实现。
迪凯特科技(北京)有限公司
2023-07-28 广告
单片机串口通信的原理是利用单片机的串口通信模块,通过把数据转化为一位一位的用时序方式传送数据,实现单片机与外部设备之间的数据通信。 串口通信的概念非常简单,串口按位(bit)发送和接收字节。尽管比按字节(byte)的并行通信慢,但是串口可以... 点击进入详情页
本回答由迪凯特科技(北京)有限公司提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式