2007-09-02 09:25 PM
Problem with Timer and VIC. Interruption launched only one time.
2011-05-17 12:46 AM
Hello,
I try to use timer to produce interrupt each x µs. To do that, I configure first of all the VIC to enable interrupt from TMR0 with IRQ interrupt, the priority is 0 (most important). Then I configure the TMR0 with a certain frequency (the value is not important for me), I enable interruption on overflow and I launch it. When I enable the timer, it is initialized with FFFC so several instrution further there is interruption, the program go in the interrupt function, clear the timer flag, and then wait in main program. After, when the timer overflows, the timer flag is set, but the program don't go to the interrupt function, and I don't understand why. I verify registers with simulator and there are ok. ISR register bit 4 is set when there is interrupt, VCir has the good value (select TMR0 interrupt and enable), VIC0_VA0R has the good value (adresse of the interrupt function). The only problem is that the VIC0_VAR register stay at 0. The first time it take the value of VIC0_VA0R, but not the other time. I don't understant why this register stay at 0. Here my code : main :Code:
// SCU Configuration SCU_APBPeriphClockConfig(__TIM01, ENABLE); // Enable the __TIM01 Clock SCU_AHBPeriphClockConfig(__VIC,ENABLE); // Enable the __VIC Clock // VIC Configuration VIC_DeInit(); // Reset values VIC_ITCmd(TIM0_ITLine, ENABLE); // Active interrupt from Timer VIC_Config(TIM0_ITLine, VIC_IRQ, 0); // Configure for generate IRQ // Timer Configuration TIM_DeInit(TIM0); // Reset values TIM_StructInit (&TIM_InitStruct); // Initialize structure TIM_InitStruct.TIM_Clock_Source = TIM_CLK_APB; // Source clock is internal TIM_InitStruct.TIM_Prescaler = 0x0F; // Prescaler of 16 TIM_ITConfig(TIM0, TIM_IT_TO, ENABLE); // Active Interrupt on overflow TIM_Init(TIM0, &TIM_InitStruct); // Initialize Timer 0 TIM_CounterCmd(TIM0, TIM_START); // Enable Timer 0 while(1); interruption program :Code:
void TIM0_IRQHandler(void) { u32 VAR = VIC0->VAR; // Get VAR value TIM_ClearFlag(TIM0, TIM_FLAG_TO); // Reset flag VIC0->VAR = VAR; // Update priority (cf p110 of UM0388) } The reading and writing of VAR register is a little strange for me, I don't understand very well why we must do that, but it is noted in the reference manual that we must do that to update the priority hardware). I try with and without do it, and the result is the same. If somebody can help me, thank you very much.2011-05-17 12:46 AM
excuse, I missed an line feed. There is the starting of counter :
Code:
// Timer Configuration TIM_DeInit(TIM0); // Reset values TIM_StructInit (&TIM_InitStruct); // Initialize structure TIM_InitStruct.TIM_Clock_Source = TIM_CLK_APB; // Source clock is internal TIM_InitStruct.TIM_Prescaler = 0x0F; // Prescaler of 16 TIM_ITConfig(TIM0, TIM_IT_TO, ENABLE); // Active Interrupt on overflow TIM_Init(TIM0, &TIM_InitStruct); // Initialize Timer 0 TIM_CounterCmd(TIM0, TIM_START); // Enable Timer 0 Sorry2011-05-17 12:46 AM
Hello French_JL,
Please find attached a timer example using an Overflow interrupt. You can verify that each time the counter overflows an interrupt is generated and the variable ''a'' is incremented. With best regards, mirou2011-05-17 12:46 AM
Hello mirou,
I have tested your project, and indeed it work well. But If I create a new project, and I add the C and H file, the project doesn't work anymore. Si I think it is maybe linked about project option or startup but I don't find the difference between them. With my project, the program return to ResetHandler after the first interruption was handled, so the program begin again all the time. Regards, JL