新手入门
- 积分
- 19
- 金钱
- 19
- 注册时间
- 2019-11-21
- 在线时间
- 6 小时
|
1金钱
void TIM1_PWM_Init(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(8, TIM1_COUNTERMODE_UP, 100, 0);//16mhz/800=PWM20khz
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE,
69,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET);
TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE,
69,TIM1_OCPOLARITY_LOW,TIM1_OCIDLESTATE_SET);///初始占空比69%
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);//自动预装载允许位
}
void timer_Init(void)
{
/*
TIM1_TimeBaseInit(16000, TIM1_COUNTERMODE_UP, 1000, 0); //1600分频,向上计数1000,从0开始,计时1秒
TIM1_ARRPreloadConfig(ENABLE);//是能自动重装
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE); //使能更新中断
TIM1_Cmd(ENABLE);
*/
TIM2_TimeBaseInit( TIM2_PRESCALER_16,1000);
TIM2_ARRPreloadConfig(ENABLE);//是能自动重装
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE); //使能更新中断
TIM2_Cmd(ENABLE); //启用定时器
}
//TIM2中断入口子程序
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)//tim1 11 tim2 13
{
count++;
if(count%2==0){LED1(ON);} else{LED1(OFF);}
TIM2_ClearITPendingBit(TIM2_IT_UPDATE);//清除中断标志
}
我想用定时器二计数改变定时器1PWM的占空比 发现PWM有波形 定时器二没有计数这是怎么回事
|
|