2011-09-28 09:33 AM
hi, dear Frs.
now i want use the TIM1 ch1,ch2 to decode rf decoded . which is rf encode is diphase coded. i use the PA8 use rf data stream input pin. rf datarate is 9.6k. now i step steps is as belows:static void GPIO_Configuration(void)
{GPIO_InitTypeDef GPIO_InitStructure;
/*GPIOA Configuration: TIM1 channel 1&2 as alternate function push-pull */ /*GPIOA pin8/9 as general input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);
}
static void NVIC_Configuration(void)
{ NVIC_InitTypeDef NVIC_InitStructure;/* Enable the TIM1 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);
}static void RF_TIM1Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1||RCC_APB2Periph_GPIOA, ENABLE);
GPIO_Configuration();TIM_DeInit(TIM1);
/* ----------------------------------------------------------------------- TIM1 Configuration:capture 40--200us signals with different duty cycles: TIM1CLK = 72 MHz, Prescaler = 0x0, TIM3 counter clock = 72MHz TIM1 ARR Register = 72 => TIM1 Frequency = TIM1 counter clock/(ARR + 1) TIM1 Frequency = 1us(1MHZ).----------------------------------------------------------------------- */ /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 72; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1,&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 = 2; TIM_ICInit(TIM1,&TIM_ICInitStructure);TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;TIM_ICInit(TIM1,&TIM_ICInitStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_CC1||TIM_FLAG_CC2);
TIM_ITConfig(TIM1,TIM_IT_CC1||TIM_IT_CC2,ENABLE);
NVIC_Configuration(); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_CCxCmd(TIM1,TIM_Channel_1||TIM_Channel_2,ENABLE); TIM_Cmd(TIM1, ENABLE);}
but the can not enter the TIM1 cc1 intterupt isr. i check the NVIC. the #tim1-input-capture2011-09-28 10:25 AM
Observations :
TIM_TimeBaseStructure.TIM_Prescaler = 72; This needs to be 71 (ie N-1) to do what you want. ie get 1 MHz from 72 MHz RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1||RCC_APB2Periph_GPIOA, ENABLE); You keep using '||' throughout your code, where the single '|' OR is supposed to be used.