Question
incrementation of a timer by an input signal
Posted on May 09, 2012 at 17:18
hi,
i'm trying ton increment a timer in timing mode at each rising of a signal which arrive on an other pin here my code : RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); /*Configuration de la pin1 du portA(arriver du signal detection de traverse)*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); /* timing Mode configuration */ TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStruct.TIM_Pulse = CCR1Val; TIM_OC1Init(TIM4, &TIM_OCInitStruct); /*timer2 chanel 2 pin PA1*/ TIM_ICInitStruct.TIM_Channel = TIM_Channel_2; TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStruct.TIM_ICFilter = 0x0; TIM_ICInit(TIM2, &TIM_ICInitStruct); /*enable the TIM counter*/ TIM_Cmd(TIM4, ENABLE); /*Configures the External clock Mode1: le compteur compte à chaque front montant d'une horloge externe ici l'entrée sur laquel il y à le signal qui detecte les traverses*/ TIM_ETRClockMode1Config(TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted,0x00); while (1){ sprintf(str,''%u'',TIM4->CNT); LCD_GLASS_DisplayString( (unsigned char *) str ); } but it doesn't work and i don't know why i think it is the function which Configures the External clock in Mode1 could you help me please !!