TIM1_DeInit()
//设置死区时间10/16=0.6us
TIM1_BDTRConfig(TIM1_OSSISTATE_ENABLE,TIM1_LOCKLEVEL_OFF,10,TIM1_BREAK_DISABLE,
TIM1_BREAKPOLARITY_LOW,TIM1_AUTOMATICOUTPUT_DISABLE)
//设置PWM频率10K
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 100*16, 0) //100us 10K
//PWM极性设置相同,则输出为互补,否则为同步信号。
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET)
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET)
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET)
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE)
TIM1_ARRPreloadConfig(ENABLE)
TIM1_Cmd(ENABLE)
TIM1_CtrlPWMOutputs(ENABLE)
不知道你问题解决了没。你给的信息太少了 ,首先你要告诉我两个片子都是哪个乱渗引脚。
不过这个问题很有可能是因为你选用的TIM通道是复用引脚 ,要通过修改“选项字节”来启动引脚复用功哪陪嫌能。在STVP这李手个软件中可以修改。
排查方法,你可以先试试IO输出是否正常(PS:不要想着一个系列的程序移植到到另一个系列 就可以运行)
TIM1->EGR=0x01//初始化TIM1 TIM1时基初橘此始化TIM1->EGR|=0x20//重新初始化TIM1
TIM1->PSCRH=0 //预分频 设置PWM频率
TIM1->PSCRL=0
TIM1->ARRH=0x0F//设定重装载值
TIM1->ARRL=0x9F
TIM1->CR1=0x80//边沿世伍郑对齐,向上计搜颂数,带缓冲
TIM1->RCR=0x01//重复计数器
TIM1->CCMR2=0x68//PWM模式1 通道2PWM输出
TIM1->CCER1=0x10//高电平有效,开启输出
TIM1->CCR2H=1//设置占空比
TIM1->CCR2L=0
TIM1->BKR=0x80//主使能
TIM1->CR1|=0x01//计数使能
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)