关于STM32103ZE管脚用PWM输出得疑惑void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure
关于STM32103ZE管脚用PWM输出得疑惑
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/********* PA 6 7 ******************************/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用
GPIOA6_Out=1; GPIOA7_Out=1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;//TIM3_CH2,TIM3_CH3
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void Timer_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM2->CR1 &= 0xfffe;
TIM3->CR1 &= 0xfffe;
///PWM,输出的引脚是 TIM3_CH2
TIM_TimeBaseStructure.TIM_Period = 60000;
TIM_TimeBaseStructure.TIM_Prescaler = 11;//72/12=6
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3 , &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; //翻转模式
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//使能比较匹配输出极性
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //设置比较匹配输出极性
TIM_OCInitStructure.TIM_Pulse = 30000; //比较值
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //
TIM_OC2PreloadConfig(TIM3 , TIM_OCPreload_Enable); //使能 比较预装载寄存器
TIM_ARRPreloadConfig(TIM3, ENABLE);//使能预装载寄存器
TIM3->CR1 &= 0x3fe; // 失能 TIM 计数器
TIM3->CR2 = 0x60; // MMS[2:0] = 110 oc2匹配上发出触发信号
/////////////// TIM2 /////
TIM_TimeBaseStructure.TIM_Period = 100;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2 , &TIM_TimeBaseStructure);
TIM2->SMCR = 0x0000; //禁用从模式的情况进行从模式配置
TIM2->SMCR |= 0x020;// TS[2:0]=010 TIM2触发源选择:TIM3的TRGI
TIM2->SMCR |= 0x007;// 使能从模式SMS[2:0]=111 使用内部触发 TRGI 即外部时钟1模式
TIM2->CNT = 0x00;
TIM3->CNT = 0x00;
TIM2->SR = 0x00;
TIM3->SR = 0x00;
TIM2->EGR =0x00;
TIM3->EGR =0x00;
TIM_ITConfig(TIM2, TIM_IT_Update,ENABLE); //使能TIM2 更新中断
TIM_ITConfig(TIM3, TIM_IT_Update,DISABLE); //失能TIM3 更新中断
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM3, ENABLE); //DISABLE ENABLE
}
我的疑惑是 PWM输出脚TIM3_CH2 有方波出来却无法驱动后端光耦发脉冲。
但是TIM3_CH2,用做普通I/O功能的时候却可以自己编一段仿PWM输出来驱动光耦发脉冲。
我怀疑:一:PWM输出的驱动能力没有普通IO的强。
二:我的PWM输出配置有问题,请各位大大帮我看一下我的配置代码。
[解决办法]没用过这个,你简单的加个上拉看看能不能驱动后端光耦