You are here

Trouble with timed interrupt | Cypress Semiconductor

Trouble with timed interrupt

Summary: 11 Replies, Latest post by Bob Marlowe on 03 Nov 2016 09:07 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
support_1968351's picture
User
6 posts

I'm using the evaluation kit for PRoC BLE. I've added a timer counter on the schematic and set it up for continuous run, capture mode, interrupt on terminal count. My goal is to have a 60 Hz interrupt routine.

In my ISR, I increment a global variable and print a message on the debug port on every 60th count. I then clear the interrupt using TCPWM_ClearInterrupt().

The problem I'm experiencing is that it seems that when the interrupt flag clear is included in the ISR, it causes the timer to freeze. However, when I remove the interrupt clear, I get the debug messages much more frequently than I expect. I assume this is because the flag is never cleared and so it re-enters the ISR every time it exits. So my conclusion is that I'm pretty sure I need to clear the interrupt flag.

So my question is, why is my timer freezing when I have the interrupt clear call in the ISR? How do I fix this?

user_1377889's picture
User
9596 posts

Welcome in the forum.

"In my ISR, I increment a global variable and print a message on the debug port on every 60th count" Printing a message in the interrupt handler can cause errors: The underlying UART can use interrupts also, which may be blocked by the previous interrupt or the sending of the message takes longer than the 1/60s which would then skip a count.

I would suggest you just to set a volatile uint8 msgflag in your handler and -as you already did- remove the interrupt cause of the TCPWM. In your main - loop check the msgflag, when set, reset it and send your message.

 

Bob

support_1968351's picture
User
6 posts

I tried using a message flag as you suggested and still have the problem. :-(

user_242978793's picture
User
1031 posts

Post your code so we can check it.

support_1968351's picture
User
6 posts

I won't post all of the subroutines just to save you guys from having to read alot of extra code. I started with the "Proximity" example code so most of what's here is related to the bluetooth functionality. Here is the ISR I'm having trouble with:

CY_ISR(Update_Int)
{
    if (timecount%60 == 0)
    {
        Dbg_time = 1;
    }
    timecount++;
    
    UpdateTimer_ClearInterrupt(UpdateTimer_INTR_MASK_TC);
}

 

And here is the main body:

int main()
{
    CYBLE_API_RESULT_T apiResult;
    CYBLE_BLESS_PWR_IN_DB_T txPower;
    int8 intTxPowerLevel;
    
    CyGlobalIntEnable;

    /* Turn off all of the LEDs */
    Disconnect_LED_Write(LED_OFF);
    Advertising_LED_Write(LED_OFF);
    Alert_LED_Write(LED_OFF);

    /* Start CYBLE component and register generic event handler */
    CyBle_Start(AppCallBack);

    Turn_Int_StartEx(&Turn_Int);

    
    
    /* Register the event handler for LLS specific events */
    CyBle_LlsRegisterAttrCallback(LlsServiceAppEventHandler);

    /* Register the event handler for TPS specific events */
    CyBle_TpsRegisterAttrCallback(TpsServiceAppEventHandler);

    WDT_Start();
    
/*  BLUETOOTH STUFF REMOVED FOR POSTING!!!*/

    /* Start Clocks */
    Clock_1_Start();
    Clock_2_Start();
    DBG_PRINTF("Clocks Started.\r\n");
    /* Start Timers */
    //NP_Sig_Timer_Start();
    UpdateTimer_Start();
    DBG_PRINTF("Timers Started.\r\n");
    //NP_Sig_Int_StartEx(&NP_Sig_Int);
    Update_Int_StartEx(&Update_Int);
    UpdateTimer_SetInterrupt(UpdateTimer_INTR_MASK_TC);
    DBG_PRINTF("Interrupts Started.\r\n");
    
    while(1)
    {
        /* CyBle_ProcessEvents() allows BLE stack to process pending events */
        CyBle_ProcessEvents();
        
        if (Dbg_time == 1)
        {
            DBG_PRINTF("Timereport: second # %d.\r\n", (timecount/60));
            Dbg_time = 0;
        }

        /* To achieve low power in the device */
        LowPowerImplementation();

        if((CyBle_GetState() != CYBLE_STATE_CONNECTED) && (CyBle_GetState() != CYBLE_STATE_ADVERTISING))
        {
            /*  BLUETOOTH STUFF REMOVED FOR POSTING!!!*/
          }
        }
        else
        {
            /* Decrease Tx power level of BLE radio if button is pressed */
            if(buttonState == BUTTON_IS_PRESSED)
            {
                DBG_PRINTF("Update Counter: %ld\r\n", UpdateTimer_ReadCounter());
                //UpdateTimer_Start();
                
                /*  BLUETOOTH STUFF REMOVED FOR POSTING!!!*/

                /* Reset button state */
                buttonState = BUTTON_IS_NOT_PRESSED;
            }
        }

        HandleLeds();
    }
}

user_1377889's picture
User
9596 posts

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

 

Bob

 

support_1968351's picture
User
6 posts

here's the workspace

user_1377889's picture
User
9596 posts

Your NP_Sig_Timer fires interrupts with more than 2MHz, this will not work. Processing an interrupt (saving the registers, entering the handler, resetting the interrupt cause, restoring the registers) will take some more time. I experienced interrupt frequencies up to 1kHz without disturbing the system, especially when there are other sources for interrupts as UART interfaces etc.

 

Bob

support_1968351's picture
User
6 posts

I tried removing that other timer and it didn't help. I even tried starting a new project from scratch and I'm still having this problem. There's got to be something very basic that I'm not doing right.

user_1377889's picture
User
9596 posts

Can you again upload your actual project?

 

Bob

support_1968351's picture
User
6 posts

Here is my second attempt.

Log in to post new comments.