我用的STM32F100C8T6B 中的TIM15来产生PWM,IO口重定义到PB14(TIM15_CH1),PB15(TIM15_CH2),但没有PWM输出,但如果不用重定义功能,就是PA2和PA3,却有PWM输出,请教各位,这是怎么回事,初始化程序如下:
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) ;
RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2
RCC_ADCCLKConfig(RCC_PCLK2_Div6); // ADCCLK = PCLK2/6
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_3); // ʱÖÓ9±¶Æµ(8MHz * 3 = 24MHz)
RCC_PLLCmd(ENABLE); // ʱÖÓËøÏà»·ÉúЧ
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) ;
// Ñ¡ÔñËøÏ໷ʱÖÓÔ´
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != 0x08) ;
SYSTICK_Init();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 | RCC_APB1Periph_USART3 | RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
JtagDisable();
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 18000;
TIM_TimeBaseStructure.TIM_Prescaler = 1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init(TIM15, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM15, TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC2Init(TIM15, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM15, TIM_OCPreload_Enable);
// TIM_ARRPreloadConfig(TIM15, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_TIM15, ENABLE);
TIM_CtrlPWMOutputs(TIM15, ENABLE);
TIM_Cmd(TIM15, ENABLE);
TIM15->CCR1 = 8000;
TIM15->CCR2 = 8000;
GPIO_InitStructure.GPIO_Pin = (1 << 14)|(1 << 15);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
|