Timer 3 interrupts issue

Hi i am trying to set up an overflow timer interrupt on Timer 3 The code is getting stuck in the interrupt routine. i am using the 2511F32 (wixel)

Here is the interrupt setting code:

{
    ......

    T3CTL |= 0xE0;                  // set prescaler to tick frequency / 128 (DIV) bits 7:5
    T3CTL |= 0x04;                  // Clear counter value (CLR - bit 2)
    T3CTL |= 0x00;                  // Timer mode set to free running (00) bits 1:0
    T3CTL |= 0x08;                  // Enable overflow interrupt (OVFIM) bit 3
    
    T3CCTL1 &= ~0x40;               // disable timer compare interrupts
    T3CCTL0 &= ~0x40;               // disable timer compare interrupts
    
    IEN1  |= 0x08;                  // Enable Timer 2 interrupts
    
    
    T3CTL |= 0x10;                  // Start the timer (START - bit 4)

    EN = 1;

    ......
}

Here’s the interrupt routine code

ISR(T3,0)
    {
        TIMIF &= ~0x07;      //   T3OVFIF Clear T3 overflow interrupt flag - bit 0
        LED_YELLOW_TOGGLE();
    }

It remains trapped in the ISR routine. There are no other interrupt flags to clear. Any ideas ?

How do you know that execution remains trapped in the ISR and on what line is it trapped?

Hello.

It looks like the problem is using the yellow led in your interrupt code. The boardService() function calls boardStartBootloaderIfNeeded(), and it will then see that the yellow LED (P2_2) is on. Because it will read P2_2 as high, it will start boardStartBootloader() and go into a boot loader state. Below is a code that toggles the red LED with an overflow timer interrupt on Timer 3. (I also noticed that you had EN = 1 in your interrupt settings code and changed it to EA = 1.)

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>

void timer3Init()
{
    T3CCTL1 = T3CCTL0 = 0;  // Disable timer compare interrupts.
    T3CTL = 0b11111100;     // Configure and start Timer 3.
    T3IE = 1;               // Enable the Timer 3 interrupt.    
    EA = 1;                 // Enable interrupts in general.
}

ISR(T3, 0)
{
    // T3IF is cleared automatically and we don't need to clear T3OVFIF.
    LED_RED_TOGGLE();
}

void main()
{
    systemInit();
    usbInit();
    timer3Init();
    while(1)
    {
        usbShowStatusWithGreenLed();
        boardService();
        usbComService();
    }
}

-Jeremy

Thank you Jeremy, that was the problem, it was entering boat loader mode, good catch ! - maybe agood idea to add this to the wixel documentation, so you dont cause this “accidents” when using that pin as I/O. This is a great controller, so many peripherals and options, you guys should promote it more, it is very capable and flexible.

Hello. I would like to add that you can use the yellow LED pin (P2_2) as an I/O line, but if you do it from an interrupt then you should avoid calling boardService().

–David

What do i lose by not calling boardservice ?

If you don’t call boardService, then app will no longer detect you shorting P2_2 to 3V3 and launch the bootloader. That shouldn’t be a big problem, because there are two other ways to get into bootloader mode: a USB command, and shorting those pins together when the board starts up. The source code of boardService is pretty simple so I would just recommend reading it:

github.com/pololu/wixel-sdk/blo … el/board.c

–David