Using Breakpoints Hit Counters

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

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

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

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:

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)

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.