cancel
Showing results for 
Search instead for 
Did you mean: 

Timer using external clock nr 2

ullmann
Associate
Posted on June 22, 2012 at 12:56

  I'm using a STM32F103RBT6.

Basicly I want to clock TIM1 (it should work on this frequency because of the Fmax from APB2) external with an 25.5 Mhz signal and use the Update_IRQ. Thats all.

I can start TIM1 and use the Update Interrupt with this code:

  TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

  TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBase_InitStructure.TIM_Period = 10000;

  TIM_TimeBase_InitStructure.TIM_Prescaler = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBase_InitStructure);

  //space to add code for clock switching

  TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

  TIM_Cmd(TIM1, ENABLE);

and my ISR:

void TIM1_UP_IRQHandler(void)

{

  USB_SEND_TEST();

  TIM_ClearITPendingBit(TIM1, TIM_IT_Update);

}

this is working well ... but now I like to change the TIM1 internal clock to an external clock like it done here :  

https://my.st.com//public/STe2ecommunities/mcu/Lists/STM32Discovery/Timer%20using%20external%20clock

I have init the GPIO PB14 with clock on and as floating input. I can read the GPIO and I see it changing like i change the input in hardware.

I tried to put this code (and a quite variants of it) insite my TIM1 init but this is not function...

  // External Trigger set to External Clock, Mode 1

  TIM_ETRClockMode1Config (TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);

  // Input Trigger selection 

  TIM_TIxExternalClockConfig (TIM1, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising, 0) ;

  //TIM_SelectInputTrigger (TIM1, TIM_TS_TI2FP2);

  // Slave Mode selection: Trigger Mode 

  TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_External1);

Or should I use external clock mode 2 better? It is very importent that the STM32 do not lose any edges even on high frequency. 

In the application I like to use the STM32F105xx MCU.

#stm32vldiscovery-timer-external
3 REPLIES 3
Posted on June 22, 2012 at 15:29

I'm pretty sure PB14 TIM1_CH2N is not an input source for the timer, it's a negated output.

Review fig 52, pg 284

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf

Pick an input source, and be aware that there is a synchronizer circuit in front of it, which exhibits nyquist limitations wrt to TIMCLK.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ullmann
Associate
Posted on June 22, 2012 at 16:29

Thank you! The ''N'' makes the difference. Now its working.

What does the synchronizer circuit in front of die TIMCLK mean for the nyquist limitation? Is it a bad idea to use 25.5MHz from external to drive the clock?

I know there are some other problems to solve but can I belive that the external clock is correct counted?

Should I use better a STM32F205 | F207 device?
Posted on June 22, 2012 at 17:58

As the signal is pulled into the synchronous digital domain there is a circuit that conditions the signal so that it's use won't violate setup and hold times of down stream flip-flops.

It's a sampling circuit, so it's going to introduce phase jitter on inputs as the signals beat wrt each other. You will also see aliasing effects, and frequency reversal, as you pass the N/2 point.

Measuring ANY two independent clock sources is always going to demonstrate drift/bias wrt each other. You can reduce that with TCXO, OCXO and atomic clock source of increasing accuracy/precision, crystals will also age with use. The temperature and PLL stability will also impact your results.

Using a STM32F2 (120 MHz) and STM32F4 (168 MHz) will provide you with finer granularity measurements. The use of 32-bit timers might also permit longer sampling periods.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..