在线时间0 小时
UID308716
ST金币0
蝴蝶豆0
注册时间2011-7-28
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
下面先贴出程序
void TIM4_Configuration(void)//TIM4初始化函数
{
//TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period =7199;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM4, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); /* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset); /* Select the slave Mode: Reset Mode */
TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable); /* Enable the Master/Slave Mode */
TIM_Cmd(TIM4, ENABLE); /* TIM enable counter */
TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE); /* Enable the CC2 Interrupt Request */
/*
void TIM4_IRQHandler(void)
{ if(TIM_GetITStatus(TIM4, TIM_IT_CC2) == SET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
IC1_Value = TIM_GetCapture1(TIM4);
IC2_Value = TIM_GetCapture2(TIM4);
IC3_Value=180*IC1_Value*100/7200;
}
测得的PWM的脉宽比周期正常。按照道理来说可以测量脉宽啊。
也就是应该可以测量如图INTE的高电平时间吧 不过为什么不可以呢?我用来做超声波模块的。 |
|