cancel
Showing results for 
Search instead for 
Did you mean: 

simple overflow timers

ebarker
Associate II
Posted on October 11, 2006 at 14:32

simple overflow timers

2 REPLIES 2
ebarker
Associate II
Posted on May 17, 2011 at 09:32

Can someone show me a code fragment that will set up a timer to fire off an interrupt every 1 ms and another timer to fire off every 10 ms.

All the timers needs to is interrupt when they roll over, the isr acknowledge the interrupt, the timer reloads, and repeat......

think of it as a couple of time keepers. no external pins needed for anything,

2 timers, 1 at 1ms, 1 at 10ms, overflow reload... no-pins

Thanks,

Posted on May 17, 2011 at 09:32

hi,

you can use the timer as follow :

TIM_StructInit(&TIM_InitStructure);

TIM_InitStructure.TIM_Mode = TIM_PWM;

TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;

TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;

TIM_InitStructure.TIM_Prescaler = 0x00;

TIM_InitStructure.TIM_Pulse_Length_1 = 0x0030;

TIM_InitStructure.TIM_Full_Period = 0x8000;

/* Initialize the Timer 2 */

TIM_Init(TIM3, &TIM_InitStructure);

/* Enable the Timer Overflow interrupt */

TIM_ITConfig(TIM3, TIM_IT_OC2, ENABLE);

/* Enable and configure the priority of the USB_LP IRQ Channel*/

VIC_Config(TIM3_ITLine, VIC_IRQ, 0);

to set the period....

void SetTimerPeriod(u32 per)

{

static unsigned int old_per=0;

if (old_per == per)

{

return;

}

old_per = per;

s_u32 *p = (s_u32*)&per;

if (p->h)

{

TIM_PrescalerConfig(TIM3, p->h & 0x00FF);

per /= p->h + 1;

}

else

{

TIM_PrescalerConfig(TIM3, p->h & 0x00FF);

}

TIM_SetPulse(TIM3, TIM_OC2_Channel, per);

}

static void irq_handler()

{

... your code

/*Clear the TIM OC2 flag */

TIM_ClearFlag(TIM3, TIM_FLAG_OC2);

}