学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-7-11
|
本帖最后由 ypc_ly 于 2015-7-13 17:22 编辑
我用TIM2输出四组PWM波,没有设置重映射,用了默认的PINA0、1、2、3来产生。但是只输出了三组,只有PINA0、1、2有输出,并且分别对应了Tim2的通道1、2、4 。不知道为什么通道三没有用到,而且PINA3也没有输出PWM波。向大神们讨教一下这个是什么原因照成的?我又把TIM2换成了4,结果还是一样,
- #include "bsp_pwm_output.h"
- #include "stm32f10x_it.h"
- volatile u32 time0=900;
- volatile u32 time1=900;
- volatile u32 time2=900;
- volatile u32 time3=900;
- /**
- * @brief ÅäÖÃTIM3¸′óÃêä3öPWMê±óÃμ½μÄI/O
- * @param ÎT
- * @retval ÎT
- */
- static void TIM2_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //open tim2 clock
-
- /* GPIOA and GPIOB clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
-
- //GPIO_PinRemapConfig(GPIO_PartialRemap1_TIM2, ENABLE); //重映射
- /*GPIOA Configuration: TIM2 channel 3 as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9 ;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
-
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /*GPIOA Configuration: TIM2 channel 2,3 and 15 as alternate function push-pull */
-
-
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- static void TIM2_Mode_Config(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- /* PWMDÅoÅμçƽìø±äÖμ */
- u16 CCR1_Val = time0;
- u16 CCR2_Val = time1;
- u16 CCR3_Val = time2;
- u16 CCR4_Val = time3;
-
-
- /* -----------------------------------------------------------------------
- TIM3 Channel1 duty cycle = (TIM2_CCR1/ TIM3_ARR+1)* 100% = 50%
- TIM3 Channel2 duty cycle = (TIM2_CCR2/ TIM3_ARR+1)* 100% = 37.5%
- TIM3 Channel3 duty cycle = (TIM2_CCR3/ TIM3_ARR+1)* 100% = 25%
- TIM3 Channel4 duty cycle = (TIM2_CCR4/ TIM3_ARR+1)* 100% = 12.5%
- ----------------------------------------------------------------------- */
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 999; //预装值
- TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //设置时钟系数
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
- /* PWM1 Mode configuration: Channel1 */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择模式一
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //跳变值
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OC1Init(TIM4, &TIM_OCInitStructure); //使能通道一
- TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
- /* PWM1 Mode configuration: Channel2 */
-
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
- TIM_OC2Init(TIM4, &TIM_OCInitStructure);
- TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
- // /* PWM1 Mode configuration: Channel3 */
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
- TIM_OC3Init(TIM4, &TIM_OCInitStructure);
- TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
-
-
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
- TIM_OC3Init(TIM4, &TIM_OCInitStructure);
- TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
-
- TIM_ARRPreloadConfig(TIM4, ENABLE);
- /* TIM2 enable counter */
- TIM_Cmd(TIM4, ENABLE);
- }
- void TIM2_PWM_Init(void)
- {
- TIM2_GPIO_Config();
- TIM2_Mode_Config();
- }
- void TIM2_2 (void)
- {TIM2_Mode_Config(); }
复制代码
|
|