cancel
Showing results for 
Search instead for 
Did you mean: 

Urgent! How to create a 10ms timer?

eli_k
Associate
Posted on May 18, 2007 at 12:36

Urgent! How to create a 10ms timer?

3 REPLIES 3
eli_k
Associate
Posted on May 16, 2007 at 12:55

Hi,

I am trying to create a 10 ms timer on the STR712 Microcontroller.

I would like a timer overflow every 10 ms. exactly.

I succeeded doing so, but without accuracy. i reached 10.8ms with the following code:

============================================

TIM_Init(TIM0);// TIM0 configuration

TIM_PrescalerConfig(TIM0, 6 );

TIM_ClockSourceConfig(TIM0, TIM_INTERNAL);

TIM_ITConfig(TIM0, TIM_TO_IT, ENABLE);

TIM_CounterConfig(TIM0, TIM_START);

============================================

Does someone know how to create a timer with accuracy? Does someone have a code for doing so?

Thanks for the help!

Elra

kleshov
Associate II
Posted on May 16, 2007 at 17:35

You can use the pulse width modulation mode of the timer. Consult the reference manual for details.

Regards,

- mike

neuner
Associate II
Posted on May 18, 2007 at 12:36

Hi Elra,

I have a 1ms timer for a STR710 maybe it also works for your 712 (is it the same library for both micros ?) => change Reload value and Prescaler should work to setup your 10ms.

void TimerInstall( void )

{

/* configure priority of timer IRQ */

EIC_IRQChannelPriorityConfig(T1TIMI_IRQChannel, USR_IRQ_PRIORITY_TIM1);

/* enables global IRQ handling of EIC */

EIC_IRQConfig(ENABLE);

/* Enable Timer IRQ in interrupt controller */

EIC_IRQChannelConfig(T1TIMI_IRQChannel, ENABLE);

/* Initialize the Timer 1 registers to reset values */

TIM_Init ( TIM1 );

/* Configure the Timer 1 Prescaler */

TIM_PrescalerConfig ( TIM1, 0x00 );

/* Enable the Output Compare interrupt for the Timer 1 */

TIM_ITConfig ( TIM1, TIM_OCA_IT, ENABLE );

/* configure and enable Timer 1 */

TIM_OCMPModeConfig ( TIM1, TIM_CHANNEL_A, 0xFFFF, TIM_TIMING, TIM_HIGH );

}

--------

void T1TIMI_IRQHandler(void)

{

/*Clear the TIM1 interrupt flag Bit 14 OCFA */

TIM_FlagClear(TIM1, TIM_OCFA);

/* set next time to generate an interrupt */

/* to achieve 1ms at 24Mhz input frequency */

/* the value is set to 24000 ticks */

TIM1->OCAR += 24000;

}

-------------

Regards

Andreas