咨询stm32f103c8 使用TIM1 的 T1_1N和 T1_2N输入捕捉功能,CCR1 CCR2读数为0,是否有现成程序给个参考,我的设置如下: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Period = PERCENT100; //周期0~FFFF TIM_TimeBaseStructure.TIM_Prescaler = PWM_Prescaler; //时钟分频 TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分割 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//模式 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);//基本初始化 TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;//选择通道 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge; // TIM_ICPolarity_Rising;//上升沿 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//通道方向选择 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//每次检测到捕获输入就触发一次捕获 TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//选择通道 TIM_ICInit(TIM1, &TIM_ICInitStructure); // TIM_PWMIConfig(TIM1, &TIM_ICInitStructure); /* Select the TIM2 Input Trigger: TI2FP2 */ // TIM_SelectInputTrigger(TIM1, TIM_TS_TI2FP2); /* Select the slave Mode: Reset Mode */ // TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset); /* Enable the Master/Slave Mode */ // TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); TIM_Cmd(TIM1, ENABLE); TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE); TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE); |
回复:咨询stm32f103c8 使用TIM1
TIM.rar
2014-10-10 17:08 上传
点击文件名下载附件
262.91 KB, 下载次数: 7
RE:咨询stm32f103c8 使用TIM1
RE:咨询stm32f103c8 使用TIM1