怎么用msp430F5529的定时器产生PWM波形
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
利用中断就可以啊。
可以通过交替改变初始值的方式,也就是说,中断后,写入高电平时间对应的初值,再中断后,写入低电平时间对应的初值,如此循环。
如果是驱动电机的话,PWM频率建议到5至10kHz,不要太高也不要太低。
写中断服务程序:
void TIMER0_INT() interrupt 1{
TH0=;
TL0=;
if(++time==percent)
{
port_pwm=0;
}else if(time==100){
time=0;
port_pwm=1;
}
}
port_pwm为自己定义的端口, 如:sbit port_pwm=P1^0;
改变percent的值就能改变占空比;percent>100的话,输出恒为高电平。