Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Interrupts and Breakpoint (Read 8515 times)
Bryan
Junior Member
**
Offline


Posts: 58
Location: Canada
Joined: Sep 8th, 2012
Interrupts and Breakpoint
Jun 2nd, 2013 at 7:55pm
Print Post  
Hi Tim:

Is there a trick to breakpoints in interrupts. using this simple interrupt code from the web. When I place a breakpoint and a hit condition to print a message at   digitalWrite(LEDPIN, !digitalRead(LEDPIN)); it is never hit. 

Actually the debugger seems to stop as all activity on the digital pins monitor stops when a new debug session is started.

Code
Select All
// Arduino timer CTC interrupt example
// www.engblaze.com

// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>

#define LEDPIN 13

void setup()
{
    pinMode(LEDPIN, OUTPUT);

    // initialize Timer1
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B

    // set compare match register to desired timer count:
    OCR1A = 15624;
    // turn on CTC mode:
    TCCR1B |= (1 << WGM12);
    // Set CS10 and CS12 bits for 1024 prescaler:
    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);
    // enable timer compare interrupt:
    TIMSK1 |= (1 << OCIE1A);
    // enable global interrupts:
    sei();
}

void loop()
{
    // do some crazy stuff while my LED keeps blinking
}

ISR(TIMER1_COMPA_vect)
{
    digitalWrite(LEDPIN, !digitalRead(LEDPIN));
} 

« Last Edit: Jun 2nd, 2013 at 7:56pm by Bryan »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Interrupts and Breakpoint
Reply #1 - Jun 2nd, 2013 at 8:07pm
Print Post  
The debugger uses Serial, so you can only add breakpoints where you can normally add a Serial.print statement.

I don't think you can do that interrupts and even if it worked I think it would throw the timings out.

I think this is why is is recommended that an interrupt write to a global variable and that the normal loop detects the change of value and responds accordingly. I might be wrong but even a digitalWrite() is a lot in an inerrupt notification handler, this isn't a strong area for me. Sorry
  
Back to top
IP Logged
 
Bryan
Junior Member
**
Offline


Posts: 58
Location: Canada
Joined: Sep 8th, 2012
Re: Interrupts and Breakpoint
Reply #2 - Jun 3rd, 2013 at 8:15am
Print Post  
I added the following after the   digitalWrite(LEDPIN, !digitalRead(LEDPIN)); statement i ++; with a  variable declared. Same thing the breakpoint would not hit and it just seemed to stop the code unless I removed the breakpoint. Yes no doubt it would probably throw the timings out. Yes , DigitalWrite seems to be a  lot of instruction cycles, but I have seen it used a lot in Arduino interrupts so guess it must be safe. From the PCI world the idea is to get in and out of a interrupt as fast as possible and don't reference another function or take your chances.
  
Back to top
 
IP Logged
 
Dennis Hill
Junior Member
Developer
**
Offline


Posts: 20
Location: US
Joined: Mar 24th, 2013
Re: Interrupts and Breakpoint
Reply #3 - Jun 3rd, 2013 at 1:27pm
Print Post  
Hi Bryan,

I haven't gotten breakpoints to work in ISR's either. I might be wrong, but you will probably need a hardware debugger to do this. I know it can be done in the PIC world with an ICD 3 or the likes. The issue is Vm inserts serial writes and delays behind the scenes which scallops the ISR's.

I think what Tim was eluding to is similar to the snippet of code below:

Code
Select All
// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>

#define LEDPIN 13
volatile boolean flash = false;
void setup()
{
    pinMode(LEDPIN, OUTPUT);

    // initialize Timer1
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B

    // set compare match register to desired timer count:
    OCR1A = 15624;
    // turn on CTC mode:
    TCCR1B |= (1 << WGM12);
    // Set CS10 and CS12 bits for 1024 prescaler:
    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);
    // enable timer compare interrupt:
    TIMSK1 |= (1 << OCIE1A);
    // enable global interrupts:
    sei();
}

void loop()
{
    // do some crazy stuff while my LED keeps blinking
    while(1)
    {
      digitalWrite(LEDPIN, flash);
    
    }
}

ISR(TIMER1_COMPA_vect)
{
    flash = !flash;
}  



Then you can set your BP on the while(1) and inspect your variables.
The best way to handle the ISR routines is to set a volatile flag (flash) and get out.
Then poll for the change in your code.

Hope this helps,

Dennis
« Last Edit: Jun 3rd, 2013 at 1:28pm by Dennis Hill »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Interrupts and Breakpoint
Reply #4 - Jun 3rd, 2013 at 1:58pm
Print Post  
Thanks Dennis, that is a clear example

Certainly using a Serial.print in an interrupt would not be possible but as you have shown, we do not need to do so much work in an interrupt, nor should we.
  
Back to top
IP Logged
 
Bryan
Junior Member
**
Offline


Posts: 58
Location: Canada
Joined: Sep 8th, 2012
Re: Interrupts and Breakpoint
Reply #5 - Jun 3rd, 2013 at 7:44pm
Print Post  
I used to use Proteus as a debugger and it worked fine with Interrupts, but I suspect Proteus is almost a  a semi-hardware type interface that runs in software..

I agree by getting in and out of a ISR as fast as possible, although I do see a pitfall with assigning the pin output to a variable as in the example., What if in the main loop that particular piece of code is not called right away because it's doing something else, like LCD refreshs, user inputs etc.  Guess it all depends on the design and how critical the interrupt is.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint