中级会员
 
- 积分
- 362
- 金钱
- 362
- 注册时间
- 2014-7-8
- 在线时间
- 10 小时
|
发表于 2014-8-15 15:19:12
|
显示全部楼层
我建意你不要呼叫那麼上層的API , 我用 F207 做的 20K , 你可以照這方式改回你要的, 反正有示波器很容易看的
void F20K_GPIO_Config(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect TIM2 pins to AF2 */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_TIM2);
}
void F20K_init(void){
UINT16  rescalerValue = 0;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//
F20K_GPIO_Config();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
PrescalerValue =(UINT16) ((RCC_Clocks.SYSCLK_Frequency /2) / 20000000) - 1;
//debug("## TIM2  rescale >>%d\r\n",PrescalerValue);
TIM_TimeBaseStructure.TIM_Period = 2000; //100uSec @25n 1Count
TIM_TimeBaseStructure.TIM_Prescaler =  rescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
//
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 1000;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_Cmd(TIM2, ENABLE);
} |
|