cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in timer

kishore
Associate II
Posted on July 12, 2008 at 12:07

Need help in timer

4 REPLIES 4
kishore
Associate II
Posted on May 17, 2011 at 12:39

Hello Every one, i am quite new to this embedded world.

I am using STM32F103ZEval board.

My motive: to get a counter in milliseconds.

I added the ''AN2592 How to achieve 32-bit timer resolution using the link system in STM32F101xx and STM32F103xx microcontrollers'' in to the main firmware demo application.(I meant i initialized RCC,GPIO,and NVIC sections.which i took from ''InputCaptureMode'' program)

I have a empty function called ''clock_time()'' where i need to run the counter and the function is being used like this

void timer restart(struct timer *t)

{t->start = clock_time();

}

can anyone help me how to use the Timer in milli seconds

Thanks

kishore
Associate II
Posted on May 17, 2011 at 12:39

If my question is not clear please ask the specifics i will try to explain.

i am using this configuration in the main program

/*---------------------------- TIM2 Configuration ----------------------------*/

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 65535;

TIM_TimeBaseStructure.TIM_Prescaler = 0;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

TIM_PrescalerConfig(TIM2, 65535, TIM_PSCReloadMode_Update);

/* TIM2 Input Capture configuration */

TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

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 = 0;

TIM_ICInit(TIM2, &TIM_ICInitStructure);

/* Disable the TIM2 Update event */

TIM_UpdateDisableConfig(TIM2, ENABLE);

/* ----------------------TIM2 Configuration as slave for the TIM3 ----------*/

/* Select the TIM2 Input Trigger: TIM3 TRGO used as Input Trigger for TIM2*/

TIM_SelectInputTrigger(TIM2, TIM_TS_ITR2);

/* Use the External Clock as TIM2 Slave Mode */

TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_External1);

/* Enable the TIM2 Master Slave Mode */

TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

/*---------------------------- TIM3 Configuration ----------------------------*/

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 65535;

TIM_TimeBaseStructure.TIM_Prescaler = 0;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

/* TIM3: Master Configuration: Input Capture Mode */

TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

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 = 0;

TIM_ICInit(TIM3, &TIM_ICInitStructure);

/* TIM3 Configuration to reset counter after each Rising edge detected on TI1*/

TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);

TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

TIM_UpdateRequestConfig(TIM3, TIM_UpdateSource_Regular);

/* ----------------------TIM3 Configuration as Master for the TIM2 -----------*/

/* Use the TIM3 Update event as TIM3 Trigger Output(TRGO) */

TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);

/* Enable the TIM3 Master Slave Mode */

TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

/* Enable the TIM3 CC1 Interrupt */

TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

/* Enable TIM3 and TIM2 counters */

TIM_Cmd(TIM3, ENABLE);

TIM_Cmd(TIM2, ENABLE);

kishore
Associate II
Posted on May 17, 2011 at 12:39

no worries i got it

jj
Associate II
Posted on May 17, 2011 at 12:39

Hi-

Glad you persisted and ''got it.''

I (and I'm sure others) reviewed your long code listing and were ''in process'' of replying.

Would you be so good as to ''detail'' your forum as to what you did to solve the problem? This would be much more valuable and heighten your likelihood/quality of response when you have another issue...