Hi CW2 - not really sure what's different but I went in with a clear head tonight and was able to get TIM2 to work just fine?!?!?!?
Could you please show your code for TIM2? There are more differences between TIM2 and TIM4 (16 bit vs. 8 bit, prescaler range, interrupt vector etc.).
Anyway, here is my code:
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALER_128, 0x7D); /* Each tick should be a MS */
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
TIM2_Cmd(ENABLE);
With a 16MHz clock this should yield a 1ms period (which I've verified on my scope).
Then since I've configured the interrupt to fire via the timer Update
TIM2_IT_UPDATE, the following interrupt handler gets called every 1MS
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
/*Do something interesting*/
}
Of course as Matt said, somewhere in your code you need to enable interrupts:
enableInterrupts();
And since I'm using the standard libraries the files must be added to your project:
stm8s_tim2.h
stm8s_tim2.c
I still need to grok using different channels, especially on TIM1, but getting this timer working moves the ball down the field a little further.
Kevin...
Kevin D. Wolf
Windows Phone Development MVP
President Software Logistics, LLC
Tampa, FL