TA的每日心情 | 慵懒 2012-10-30 14:40 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
|
#include<msp430g2553.h>
#include<math.h>
#define pi 3.141592653
unsigned char step=0;
unsigned char spwm[100];
/***************************Creat PWM tab***************************/
void Creat_PWM_tab(void)
{
unsigned char i;
float x,y;
for(i=0;i<100;i++)
{
x = 20000*sin(pi*i/100);
y = 20000*sin(pi*(i+1)/100);
spwm[i]=(unsigned char)(x+y)/2; //面积法求SPWM
}
}
/****************************delay*******************************/
void delay(unsigned char a)
{
unsigned char x,y;
for(x=a;x>0;x--)
for(y=110;y>0;y--);
}
/******************************spwm init*************************/
void spwm_init(void)
{
P1SEL |= BIT2; // Output SPWM1 From P1.2
P1DIR |= BIT2;
P1SEL |= BIT6; // Output SPWM2 From P1.6
P1DIR |= BIT6;
TA0CTL |= MC_3+TASSEL_2+ID_0; //Up/down mode,SMCLK
TA0CCTL1 |= OUTMOD_6; //model 6
TA0CCTL2 |= OUTMOD_2; //model 2
TA0CCR0 = 23330;
TA0CCR1 = 10000;
TA0CCR2 = 10000;
}
/********************************main****************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //stop watch dog timer
Creat_PWM_tab();
BCSCTL1 |= CALBC1_8MHZ_; //MCLK = 8MHZ
DCOCTL |= CALDCO_8MHZ_; //Inner DCO = 8MHZ
BCSCTL2 |= DIVS_3; //SCLK = 1MHz
spwm_init();
_EINT();
TA0CTL |= TAIE;
TA0CCTL0 |= CCIE;
// TA0CCTL1 |= CCIE;
// TA0CCTL2 |= CCIE;
// LPM1;
while(1);
}
/********************interrupt set spwm *************************/
/*
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Set_SPWM(void)
{
TA0CCR1 = spwm[step];
// TA0CCR2 = spwm[step];
if(step<99) step++;
else step=0;
}*/
上面是我的产生PWM的程序,但是引脚没有产生波形,真心求助, 望各位大牛指点!!!
|
|