setcounter() function problem


i am facing a problem with the setcounter and getcounter functions,
i have setup the counter to count up at rising edges;
whenever a rising edge is detected i am getting sometimes 2 and sometimes 3 increments instead of 1 which is a bit weird.

appreciate any help.

What is connected to the input pin?

Is it a button that could be generating multiple edges when you press it, due to debounce?

If you put a logic probe or scope on the input pin, what do you see/capture when you’re reading 2 or 3 increments? There might actually be 2 or 3 edges in there if you don’t have any hardware to debounce the button.