AnsweredAssumed Answered

Code works with breakpoints, not without (BF518-EZ-Board, interrupt, static variable)

Question asked by ndrs on Oct 4, 2011

Hi all,

I'm currently trying to get used to the BF518's programming with Visual DSP.

For future applications i need a constant sample rate, so i decided to put all my calculations into a timer interrupt routine.

I tried to test the following code (important commands are commented red)


Header 1

#include <math.h>
#include <stdio.h>
#include <services\services.h>
#include <drivers\adi_dev.h>
#include <cdefBF518.h>

static volatile int LED1; // volatile is probably not needed if i don't touch LED1 outside the interrupt routine

int main( void )
    *pPORTH_FER    = 0;                             //set all Pins to GPIO
    *pPORTHIO_DIR  = ((1<<3) | (1<<5) | (1<<6));     // outputs
    *pPORTHIO_INEN = (1 | (1<<1));                     //Input enable

    // Enable Interrupts
     register_handler(ik_ivg12, Timer0_ISR);   



   // blinking LED1
    if (LED1 == 1) {
        LED1 = 2;
        *pPORTHIO |= (1<<3); // turn on the LED if it's off
    else {
        LED1 = 1;
        *pPORTHIO &= ~(1<<3); // turn off the LED if it's on

   // switched LED2 including overwrite of LED1
    if ((*pPORTHIO & 1) == 1) {
        *pPORTHIO |= (1<<5);
        LED1 = 1; // overwrite LED1
        *pPORTHIO &= ~(1<<5);
    *pTIMER_STATUS=1; //to acknowledge timer interrupt


PH1 is a button, PH3 and 5 are LEDs.

So what does this code do?


In debug mode with breakpoints in the ISR:

All works as it should. LED1 blinks as long as the button isn't  pressed. Pressing the button enables LED1 and 2. All events are delayed  until the next timer interrupt.


In normal mode:

LED1 turns on after the first timer event and stays on (no blinking). Pressing the button turns on LED1 and 2 after the next timer interrupt. Releasing it turns both LEDs off. LED2 stays off.


Any ideas what i'm doing wrong?