本文摘录于:https://blog.csdn.net/freeape/article/details/47008033只是做学习备份之用,绝无抄袭之意,有疑惑请联系本人!
代码上要使用TIME1输出3路PWM,代码如下:
void timer1_init(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(0x0000, TIM1_COUNTERMODE_UP, 1600, 0x00);//16000000/160=10000=10K
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,400, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,800, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,1200, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
}
但是不知道为什么怎么通道1和通道2都没有输出,只有通道3有输出:
经过从从百度多方查看终于看到这篇文章:https://blog.csdn.net/freeape/article/details/47008033
这你要配置AFR0,经过了解要用stvp进行Option Byte的修改:https://download.csdn.net/download/rui22/12885187
操作成功过后可以读回配置看看是否成功:
经过配置后通道1和通道2终于有PWM输出了: