AnsweredAssumed Answered

PROBLEM: STM32F4 Discovery Counting External Pulses by Firmware

Question asked by W.A on Aug 14, 2015
Latest reply on Aug 17, 2015 by W.A
I am trying to use TIM4 in  external counting mode, I have managed to configure it in external counting mode, but the count I am getting in watch 1 window is random. I am using ground pin of board to give input to PB7 and I expect it should give me one increment in the count when I remove it. but it is not so, can anyone tell me what wrong in my code. (Similar problem was posted in some other thread but could not find exact solution) 
I want to get count of rising pulses from external signal: 

My Program is: 


/******************************************** */ 

/* Includes ------------------------------------------------------------------*/
#include "stm32f4_discovery.h"

TIM_ICInitTypeDef  TIM_ICInitStructure;
uint32_t aa = 0;

/* Private function prototypes -----------------------------------------------*/
void TIM_Config(void);

/* Private functions ---------------------------------------------------------*/
int main(void)
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
  /* TIM Configuration */
  while (1)

  * @brief  Configure the TIM4 Pins.
  * @param  None
  * @retval None
void TIM_Config(void)
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  /* TIM4 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
  /* GPIOB clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  /* TIM4 chennel2 configuration : PB.07 */
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Connect TIM pin to AF2 */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
     TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
  TIM_TIxExternalClockConfig(TIM4, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising, 0);


  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
void assert_failed(uint8_t* file, uint32_t line)
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  while (1)

  * @}

  * @}

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/