430 f5229
这是TA初始化
void PWM_Init(void)
{
P2SEL |= 0x10; //0x10=0001 0000 选中P2.4引脚为TA2模式
P2DIR |= 0x10; //P2.4引脚选为输出模式
P2OUT |= 0x10; //P2.4引脚为输出为高电平
TA2CTL |= 0x0210; //0000 0010 0001 0000 = 0x0210 设置时钟SMCLK,并选择计时器模式为增计数模式
TA2CCTL1 = 0x00E0; //0000 0000 1110 0000 = 0x00E0设置输出模式为模式7
}
这是PWM输出(SPWM)
void PWM_output_init(uint16_t temp)
{
Dogs102x6_clearScreen();
Dogs102x6_stringDraw(1, 0, "start output!", DOGS102x6_DRAW_NORMAL);
//Fre_sin = temp;
uint16_t Voltage,ADC12_data;
double double_PI=6.283185307; //2π
uint32_t Fre_clk = 25000000; //时钟频率25MHz
uint16_t Fre_carry; //载波频率
uint16_t mod_rat=0.8; //调制比
Fre_carry = Bobbi * Fre_sin; //计算载波频率
TA2CCR0 = Fre_clk / Fre_carry;
for(temp_globle=0;temp_globle<Bobbi;temp_globle++)
{
mask_ccr1[temp_globle] = (Fre_clk/(4*Bobbi*Fre_sin)*(1-(mod_rat*sin(double_PI/Bobbi*(temp_globle+0.25))+mod_rat*sin(double_PI/Bobbi*(temp_globle+0.75)))/2));
}
TA2CCR1 = mask_ccr1[0];
temp_globle=1;
while (!(buttonsPressed & BUTTON_S2)) //S2按键按下退出程序
{
if(temp_globle==359)
{
//ADC12_data=ADC12_cap();
//Voltage = 36*(ADC12_data/4096.0);
//mod_rat=pid(Voltage);
for(temp_globle=0;temp_globle<Bobbi;temp_globle++)
{
mask_ccr1[temp_globle] = (Fre_clk/(4*Bobbi*Fre_sin)*(1-(mod_rat*sin(double_PI/Bobbi*(temp_globle+0.25))+mod_rat*sin(double_PI/Bobbi*(temp_globle+0.75)))/2));
}
temp_globle=0;
}
}
}
中断服务程序
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
TA2CCR1 = mask_ccr1[temp_globle];
temp_globle++;
//Dogs102x6_clearScreen();
}
发现程序执行的时不会触发中断服务程序
而且把p2.4引脚接到示波器看到的是正弦波,毛刺很多,Vpp 5v,感觉杂波
求大神帮忙解答!谢谢!
|