在线时间17 小时
UID229505
ST金币0
蝴蝶豆0
注册时间2010-10-13
中级会员
- 最后登录
- 2020-6-17
|
楼主 |
发表于 2012-8-2 09:33:50
|
显示全部楼层
a0a.1 0b0c
RE:这样的硬件电路有问题吗
//====================================//
void PWM_FROM_TIM1_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
// TIM_BDTRInitTypeDef TIM1_BDTRInitStructure;
//TIM1_OC1:set PWM channel 1 duty
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_Pulse = PWM_DUTY_0_PERCENT;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
//TIM1_OC1:set PWM channel 1 duty
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = PWM_DUTY_0_PERCENT;
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
//TIM1_OC2:set PWM channel 2 duty
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = PWM_DUTY_0_PERCENT;
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
//TIM1_OC3:set PWM channel 3 duty
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = PWM_DUTY_0_PERCENT;
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
//TIM1_OC4:set PWM channel 4 duty
TIM_OC4Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = PWM_DUTY_0_PERCENT;
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
//TIM1 base counter(PWM frequency is 100Hz)
//72MHz/TIM_PRESCALER=1MHz,PWM Frequency = 1MHz / PWM_PERIOD
TIM_BaseInitStructure.TIM_Prescaler = TIM_PRESCALER-1;
TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_BaseInitStructure.TIM_Period = PWM_PERIOD-1;
TIM_BaseInitStructure.TIM_ClockDivision = 0;
TIM_BaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_BaseInitStructure);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_ClearITPendingBit(TIM1, TIM_IT_Update | TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4);
//open TIM1
TIM_Cmd(TIM1, ENABLE);
//enable TIM1_CO to enable PWM channel x(must be added)
TIM_CtrlPWMOutputs(TIM1, ENABLE);
} |
|