TIM1的PWM输出时,通道3、4管用,1、2不管用。
用的是官方库的例子,新建的工程,没有配置复用的问题。请教各位遇到过这种情况吗?是什么原因呢?
[mw_shl_code=c,true]void main(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,499,0);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
/*
TIM1_OCMode = TIM1_OCMODE_PWM2
TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
TIM1_Pulse = CCR1_Val
TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
*/
TIM1_OC1Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE,2000,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET);
/*TIM1_Pulse = CCR2_Val*/
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 1500, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
/*TIM1_Pulse = CCR3_Val*/
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 2000, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
/*TIM1_Pulse = CCR4_Val*/
TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE,2000, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET);
/* TIM1 counter enable */
TIM1_Cmd(ENABLE);
/* TIM1 Main Output Enable */
TIM1_CtrlPWMOutputs(ENABLE);
while (1);
}[/mw_shl_code]
然后我又在网上搜的别人配置通道1输出的,也是不行
[mw_shl_code=c,true]void Tim1_Init()
{
/* Set the Autoreload value */
TIM1->ARRH = (uint8_t)(1000 >> 8); //2M/1000=2K
TIM1->ARRL = (uint8_t)(1000);
/* Set the Prescaler value */
TIM1->
SCRH = 0x00; //8分频 16M/8=2M
TIM1->
SCRL = 0x08;
TIM1->CCR1H = (uint8_t)(200 >> 8); // 输出脉宽
TIM1->CCR1L = (uint8_t)(200); // 输出脉宽
TIM1->CCMR1 |= 0x60; // PC1脚PWM输出,PWM模式1
TIM1->CCER1 |= 0x01; // CH1/CH2/ 关闭互补输出;高电平有效输出高;
TIM1->IER = 0x00; // 不允许产生更新事件中断
TIM1->CR1 = 0x01; //启动计数器
TIM1->BKR |= 0x80; //使能PWM输出
}
void main()
{
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
asm("sim"); // 关全局中断
Tim1_Init(); //定时器时钟配置
asm("rim"); // 开全局中断
TIM1_CCR1L = 20;
while(1)
{}
}
[/mw_shl_code]
---------------------------------
您好,我给你发了短信,希望你能回复我!因为最近我也在做STM8S003多通道ADC转换的!希望能跟你学习,能指导一下!谢谢!QQ:370854109
一周热门 更多>