Using Breakpoints Hit Counters

Non-VS2015 Logos
This version of the documentation page applies to Visual Studio prior to VS2015 and to all versions of Atmel Studio.
Read documentation page for Visual Studio 2015 here.

What Breakpoint Hit Counters Can be Used For

Use breakpoint with so-called hit counters if you want that your breakpoint halts the execution of your program not before the program has passed it n times, or if you want the breakpoint to become effective every only n milliseconds.

Note Icon Note

After making changes to your breakpoint as shown here, you must recompile and upload your sketch in order for the changes to go into effect.

How to Create a Breakpoint With a Hit Counter

Read on the general Breakpoints documentation page on how to set breakpoints.

To set a counter for an existing breakpoint, right click the Breakpoint Indicator marker of an existing breakpoint at the left of your code and choose "Hit Count":

Hit Count Breakpoint Context Menu

Breakpoint Hit counter

Visual Micro provides breakpoint counters that are either identical to the value returned by the millis() function or are an individual counter for each breakpoint. With breakpoint counters, you can choose when and how often a breakpoint becomes effective. For example, you can tell Visual Micro to break execution only every 10th time your code passes the breakpoint or only 2 minutes after your sketch has been started.

For an instruction on how to switch between individual counters and "millis()" counters, see the "Individual breakpoint counter" section below.
Until then we assume that the Default is chosen, which is a counter that always has the value returned by the millis() function.

 

If you choose the "Hit Count..." context menu item, the following dialog appears:

Breakpoint Hit Counter

Warning 16 Note

The informational text on to of the window describes the behavior in Visual C++. Visual Micro breakpoint hit counters work with the value of the millis() function by default..
The "Current hit count" and "Reset" controls in that window do not have any meaning when using Visual Micro.


With the selection box 1, you can choose...

"break always"
The breakpoint is not affected by the counter - the default behavior
"break when the hit count is equal to"
The breakpoint is effective if the value returned by millis() is equal to the number entered
(an edit box appear when you select  this option)
"break when the hit count is a multiple of"
The breakpoint is effective if the value returned by millis() is a multiple of the number entered. In this way you can specify that the breakpoint is only hit every x milliseconds and ignored in between, even if the sketch code has passes it
(an edit box appear when you select this option)
"break when the hit count is greater than or equal to"
The breakpoint is effective if the value returned by millis() is greater or equal to the number entered. In this way you can specify that the breakpoint is not hit before a certain time has passed.
(an edit box appear when you select this option)

 

Warning 16 Note:

"break when the hit count is equal to" may be unreliable in conjunction with a millis() counter, because you often cannot predict the exact millisecond value returned by millis() when the breakpoint is passed, down to a specific millisecond. Use one of the other options instead.

When using the "break when the hit count is a multiple of", Visual Micro cares about the fact that the value of millis() won't have the exact value or multiples of it when the breakpoint is hit. Example: If the value set in the breakpoint is 250 (break every 250 milliseconds), and the breakpoint is hit after 754 ms instead of 750, the sketch will be halted anyhow.

However, this option is very useful if you use individual breakpoint counters instead of the millis() value, see the section "Individual breakpoint counter" below.


To remove any "Hit Count" condition, open the Hit Count window again and select "break always".

Individual breakpoint counter

You can use an individual counter per breakpoint instead of the millis() function. You can change this setting globally or per project.

If Visual Micro is set to "Counter" instead of "Milliseconds", then it maintains one counter per breakpoint. All counters start with a value of 0 when your sketch starts running. Each breakpoint's counter is incremented by one every time the sketch passes the breakpoint. By the settings above you can control when the breakpoint becomes effective in relation to the value of the counter.

How to change from millis() to individual counters:

  • globally, for all projects:
    Go to Tools > Options > Visual Micro > General > Micro Debug - Advanced and change the setting from "Milliseconds" to "Counter"
  • ...per project:
    Open the Project Properties Window.
    Change the "Hit Counters" setting from "Milliseconds" to "Counter".

A project specific setting -if there is any- supersedes the global setting.

Note Icon Note

The "Current hit count" and "Reset" controls in that window do not have a meaning when using Visual Micro.

 

 

Other Pages