本帖最后由 worldsing 于 2010-4-16 11:29 编辑
//======================================================================
void Timer_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStruct;
//------------------------------TIM2 ch2 PA1---------------------------------------
GPIO_DeInit(GPIOA);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0; //TIM2 CH2 PA0 R47(WAKEUP)
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period=400; //ARR的值
TIM_TimeBaseStructure.TIM_Prescaler=0; //PSC分频值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //采样分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM2,1,TIM_PSCReloadMode_Immediate);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Channel=TIM_Channel_1;
TIM_OCInitStructure.TIM_Pulse=200;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInit(TIM2, &TIM_OCInitStructure);
//------------------------------TIM3 ch1 PA6---------------------------------------
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6; //TIM3 CH1 R14(SPI1_MISO)
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period=400; //ARR的值
TIM_TimeBaseStructure.TIM_Prescaler=0; //PSC分频值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //采样分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM3,1,TIM_PSCReloadMode_Immediate);
TIM_ARRPreloadConfig(TIM3, ENABLE);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Channel=TIM_Channel_1;
TIM_OCInitStructure.TIM_Pulse=200;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInit(TIM3, &TIM_OCInitStructure);
//-----------------------------TIM4 ch1 PB6----------------------------------------
GPIO_DeInit(GPIOB);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6; //TIM4 CH1 PB6 TEMP_SCL(J4-22)
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStruct);
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period=400; //ARR的值
TIM_TimeBaseStructure.TIM_Prescaler=0; //PSC分频值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //采样分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM4,1,TIM_PSCReloadMode_Immediate);
TIM_ARRPreloadConfig(TIM4, ENABLE);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Channel=TIM_Channel_1;
TIM_OCInitStructure.TIM_Pulse=200;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInit(TIM4, &TIM_OCInitStructure);
//-----------------------------TIM5 ch1 PA3----------------------------------------
GPIO_DeInit(GPIOB);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_3; //TIM4 CH1 PB6
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
TIM_DeInit(TIM5);
TIM_TimeBaseStructure.TIM_Period=400; //ARR的值
TIM_TimeBaseStructure.TIM_Prescaler=0; //PSC分频值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //采样分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM5,1,TIM_PSCReloadMode_Immediate);
TIM_ARRPreloadConfig(TIM5, ENABLE);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Channel=TIM_Channel_4;
TIM_OCInitStructure.TIM_Pulse=200;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInit(TIM5, &TIM_OCInitStructure);
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM3, ENABLE);
TIM_Cmd(TIM4, ENABLE);
TIM_Cmd(TIM5, ENABLE);
}
=================================================
我把TIM2 ~ TIM5配置全一样的,结果用示波量,只有TIM2有输出,管脚用的是默认的,所有外设时钟都使能了,会不会是配置成一样的参数,会造成冲突呢? |