This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Arm LPC2138 Timer Vic Problem with Disable

I have a problem with Timers and the VIC on an Arm LPC2138.
I have two timers that run fine, both are programmed thru the VIC and are IRQ. In the main program loop, I need to disable one of the Interrupts (Timer0) in order to reset a variable that is updated in the timer Interrupt.
When I disable timer0 in the VIC, the program runs but the interrupts don't fire.
ie: Case (1)

unsigned char hw_msec(void)
        {
        static unsigned char milli_count = 0;
        VICIntEnClr |= (1 << 4); // Disable Time 0 in Vic
        milli_count = uiGlobalTimerMs;
        if(milli_count)
        {
        uiGlobalTimerMs = 0;
        }
        VICIntEnable |= (1 << 4); // Re-Enable Timner 0
        return milli_count;
        }


However it works when I disable all IRQs, but I would prefer not to have to do that: Case (2)

unsigned char hw_msec(void)
        {
        static unsigned char milli_count = 0;
        milli_count = uiGlobalTimerMs;
        if(milli_count)
                {
                hw_irq_disable();
                uiGlobalTimerMs = 0;
                hw_irq_enable();
                }
        return milli_count;
        }


I have stopped the program in Case (1) at Line: VICIntEnClr |= (1 << 4); and the VICIntEnable is correct (0x00000030) (Timer 1 is also enabled). After stepping over VICIntEnClr, it correctly goes to (0x00000020) and after re-enabling it returns to (0x00000030). The VICVectAddr4 & 5 are both valid and the Timers are enabled (T1TCR = 1) Any Ideas would be greatly appriciated.

Parents
  • Seem to have found a solution to this problem, however, it would be nicer to know what is actrually going on.
    By turning off the actual timer, the interrupts are working again.
    Could it be that spurious interrupts generated while disabling Timer 0 in the VIC were cauing the problem? Surely I should be able to just turn of the IRQ and turn it back on again?

            T0TCR = 0;
            VICIntEnClr |= VIC_BIT(VIC_TIMER0);
    ..... Do Stuff........
            VICIntEnable |= VIC_BIT(VIC_TIMER0);
            T0TCR = 1;
    

Reply
  • Seem to have found a solution to this problem, however, it would be nicer to know what is actrually going on.
    By turning off the actual timer, the interrupts are working again.
    Could it be that spurious interrupts generated while disabling Timer 0 in the VIC were cauing the problem? Surely I should be able to just turn of the IRQ and turn it back on again?

            T0TCR = 0;
            VICIntEnClr |= VIC_BIT(VIC_TIMER0);
    ..... Do Stuff........
            VICIntEnable |= VIC_BIT(VIC_TIMER0);
            T0TCR = 1;
    

Children
No data