AnsweredAssumed Answered

STM32F2 Counting pulses using ETR and generating one pulse at max speed

Question asked by lopez.pedro.001 on Feb 27, 2015
Latest reply on Feb 28, 2015 by lopez.pedro.001

To start i'm using STM32F207

I have a 15Mhz signal (that sometimes is enabled and sometimes it is not) connected to TIM3 ETR. I just want to count pulses and generate a pulse after few of this clocks (from 1 to 16 configured by software).

To try it, I have set the TIM3 ETR (PD2 pin) as clock for TIMER 3, and it works (it starts counting). The code used is:

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  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_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_TIM3);  

  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);
  TIM_ETRClockMode2Config(TIM3,TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
  TIM_TIxExternalClockConfig (TIM3, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Falling, 0) ;

This is working ok as I said. Now I want to make a pulse faster than TIM3 clock if possible. Configuring TIM3 to count up from 0 to the current count limit

  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;        
  TIM_TimeBaseStructure.TIM_CounterMode   = TIM_CounterMode_Up;  
  TIM_TimeBaseStructure.TIM_Period        = 3;            //Count limit
  TIM_TimeBaseStructure.TIM_Prescaler     = 0;                   
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);                

And now I have to set the output. I would like a pulse, so i tried the One-Pulse thing, but it is not working or not working as I wished. I have tried with PWM1/2 and Toggle. It counts right, but toggle is not ok since it generates a "clock divider", and pwm generates pulses at speed of the clock and thats not ok.

I would need a small delay between the detection of the counting event and the rising of the output. This is what i tried:

  TIM_OCInitTypeDef       TIM3_OC; 
  TIM3_OC.TIM_OCMode      = TIM_OCMode_PWM1;             
  TIM3_OC.TIM_OutputState = TIM_OutputState_Enable;      
  TIM3_OC.TIM_OCPolarity  = TIM_OCPolarity_High;         
  TIM3_OC.TIM_Pulse       = 1;                           
  TIM_OC3Init(TIM3, &TIM3_OC);                           
  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);      
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

In the image attached I explain what to I get and what do I need. 

I have seen a card done by another company using STM32F207, and same pins (PD2 clk input, PC7 pulse output and PC8 pulse output). Any idea or help would be welcomed.

Thanks in advance