本帖最后由 liu510706140 于 2021-5-12 17:47 编辑
多路PWM输出的范例没有找到修改占空比的函数,新建修改占空比的函数,多次调试测试可行。
主函数如下,程序看附件
int main(void)
{
/* Sys Init */
Sys_Config();
while (1)
{
IWDG_ReloadCounter();//喂狗
PWM_TMR1_Channel1(Key_count*100);
PWM_TMR1_Channel2(Key_count*100);
PWM_TMR1_Channel3(Key_count*100);
PWM_TMR1_Channel4(Key_count*100);
PWM_TMR3_Channel1(Key_count*100);
PWM_TMR3_Channel2(Key_count*100);
PWM_TMR3_Channel3(Key_count*100);
PWM_TMR3_Channel4(Key_count*100);
delay_ms(1000);//延时1秒
Key_count++;
if(Key_count>10)Key_count=0;
}
}
//输出周期=1000 占空比=500-1=50%
void PWM_TMR1_Channel1(unsigned short int PulseValue)
{
TMR1->CC1 = PulseValue;
}
void PWM_TMR1_Channel2(unsigned short int PulseValue)
{
TMR1->CC2 = PulseValue;
}
void PWM_TMR1_Channel3(unsigned short int PulseValue)
{
TMR1->CC3 = PulseValue;
}
void PWM_TMR1_Channel4(unsigned short int PulseValue)
{
TMR1->CC4 = PulseValue;
}
void PWM_TMR3_Channel1(unsigned short int PulseValue)
{
TMR3->CC1 = PulseValue;
}
void PWM_TMR3_Channel2(unsigned short int PulseValue)
{
TMR3->CC2 = PulseValue;
}
void PWM_TMR3_Channel3(unsigned short int PulseValue)
{
TMR3->CC3 = PulseValue;
}
void PWM_TMR3_Channel4(unsigned short int PulseValue)
{
TMR3->CC4 = PulseValue;
}
|