Using Breakpoints Hit Counters

VS2019 Logo
This version of the documentation page applies only to Visual Studio 2017/2019
Read documentation page for other VS versions and Atmel Studio here.

What Breakpoint 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.

In the configuration window for your breakpoint, explained on the above mentioned page, you will have the following choices:

Breakpoint Vs15 Settings Popup Conditions Mode Combo

A: Read on this page dedicated to Conditional breakpoints..

B: Is covered here on this page.

C: Filters cannot be used with Visual Micro, they are reserved for development using Visual Studio alone.

B Breakpoint Hit Counters


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.

Visual Micro provides breakpoint counters that are either controlled by the value returned by the millis() function, or are that individual counters for each breakpoint.

For an instruction on how to switch between individual counters and "millis()" counters, see the "Individual Breakpoint Counters" 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.

After choosing "Hit Count" in the combo box shown above, the breakpoint settings window will look like this, and will offer a combo box with three options: "=", "Is a multiple of", and ">=":

Breakpoint Vs15 Settings Popup Hit Count With Combo


With the selection box, you can choose...

1: "="
The breakpoint is effective if the value returned by millis() is equal to the number entered in the  exp  field.
2: "Is a multiple of"
The breakpoint is effective if the value returned by millis() is a multiple of the number entered in the  exp  field. 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.
3: ">="
The breakpoint is effective if the value returned by millis() is greater or equal to the number entered in the  exp  field. In this way you can specify that the breakpoint is not hit before a certain time has passed.


Warning 16 Note:

 "=" (1) 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 "Is a multiple of", (2), 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, uncheck the Breakpoint Vs15 Conditions Check Box box.

Individual Breakpoint Counters

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:
    In the menu, 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.