将f107,tim3通道1设置为pwm2模式,tim3_ch1输出,在没有remap时 ,在PA6输出正确波形。但remap到PB4时,没有波形输出。
下面为GPIO的设置代码:
/* GPIOA clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* GPIOB clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/*** Configure GPIO to Output ***/
/* Remap TIM3 CH1 pin to PB4 */
//AFIO->MAPR |= 0x00000800; //不remap时PA6有输出,remapPB4没有输出
/*TIM3 channel 1 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;//PB4, -- TIM3 CH1 remap
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*GPIOB Configuration: TIM4 channel 3 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//PB8, -- TIM4 CH3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* TIM3 channel 1 pin (PA.06) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//PA6, signal out -- TIM3 CH1 no remap
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
下面为TIM3的设置代码:
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = Period;
TIM_OCInitStructure.TIM_Pulse = Period >>1;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* Select the TIM4 Input Trigger: ITR1 */
//TIM_SelectInputTrigger(TIM3, TIM_TS_ITR3);
/* Select the slave Mode: Gated Mode */
//TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE); |