Timer compare interrupt flags
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2009-06-16 11:06 PM
Posted on June 17, 2009 at 08:06
Timer compare interrupt flags
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2011-05-17 4:15 AM
Posted on May 17, 2011 at 13:15
Hello everyone.
I've got timer 2 in a STM32F103VB setup for generating a 1ms interrupt and it works just fine: void Init(void) { RCC_APB1ENR_bit.TIM2EN = 1; // Enable clock to timer 2 RCC_APB1RSTR_bit.TIM2RST = 1; // Reset timer 2 RCC_APB1RSTR_bit.TIM2RST = 0; // Release reset on timer 2 TIM2_PSC = 71; // 72MHZ / (71 + 1) = 1MHz = 1us TIM2_ARR = 999; // 1us / 999+1 = 1ms period time TIM2_DIER_bit.UIE = 1; // Turn on timer 2 update event interrupt SETENA0_bit.SETENA28 = 1; // Enable timer 2 interrupt TIM2_CR1_bit.CEN = 1; // Timer 2 Enable } void TIM2_IRQHandler(void) { TIM2_SR = 0; } Now, as the counter is ticking along in 1us/step I thought I might be able to use the compare interrupt flags for delaying in microseconds. But the first thing I notice is that every time I enter the current interrupt routine (in TIM2_SR) CCxIF are all set along with UIF. Changing TIM2_CCRx to values > TIM2_ARR does not change this behaviour, the flags are still set every time I enter the interrupt. TIM2_CCMR1 and TIM2_CCMR2 are both 0x0000, which I interpret as frozen output compare mode. In this mode CCxIF in TIM2_SR would be set when TIM2_CNT == TIM2_CCRx, which shouldn't happen as they are > TIM2_ARR... Could anyone help me out and let me know where I'm wrong or how to get CCxIF working?