Optimized digitalWrite() function and disable PWM

I'm trying to optimize my led matrix display.

First I downloaded a library that implements digitalWriteFast() function and I replaced all my pinMode() and digitalWrite() to pinModeFast() and digitalWriteFast() on my led matrix class(only on this class)... The code worked perfectly and much more faster than before. My buttons code continues to use the pinMode() and digitalWrite() functions.

So, I applied this patch(the v3 on the last comment):
http://code.google.com/p/arduino/issues/detail?id=140

And, my buttons(that is plugged on PWM pins) are getting pressed at random times(often). If you read the issue you'll see this comment:

If anyone really needs the extra speed gained by not disabling PWM on the pin, they could always call bitWrite(*digitalPinToPortReg(P), digitalPinToBit(P), (V)) directly. Which means we wouldn't need a separate digitalWriteFast() or equivalent, right?

So I ask, how do I disable PWM on some pins?

Does your Sketch ever turn on PWM (call analogWrite)?

no... only pinMode(3,INPUT) on setup and digitalRead(3) on loop to check if button is HIGH!

Then why are you concerned about turning off PWM?

Bacause after I patched my arduino core my buttons became crazy. It gets pressed without nobody pressing it.

I'm thinking that it's a PWM problem that the guy told at the issue(I quoted him)!

There is simply no possibility that PWM is causing your buttons to be pressed randomly.

There are three things that could be causing the problem...

  1. A bug in Álvaro Lopes' patch. If this is the same patch being merged into the core, this is very unlikely to be the problem.

  2. A bug in your code.

  3. A problem with the way you've wired your buttons

Let's start with #3. Are your buttons wired with a pull-up or a pull-down resistor?

I'm using a pull-down resistor.

It's wired this way:
Ground -> Resistor -> Button -> VCC
|
PIN

I assume you meant to draw the PIN on the Resistor side of the Button.

What size resistor?

yes it's in the resistor side.

the resistor is 10k

Now for #2. Post your Sketch. Please use code tags (click the # button to insert the tags into the edit window).

The code is hosted on bitbucket.

I think is easier to you check the code there. If you want I can post the code here.
Buttons.cpp
https://bitbucket.org/trunet/trunetclock/src/a4ded538a701/Buttons.cpp
Buttons.h
https://bitbucket.org/trunet/trunetclock/src/a4ded538a701/Buttons.h

The setupButtons() is called on setup() and checkButtons() is called on loop().

Thanks.

Some general comments...

Why are these in the header file?

// last time the respective button was pressed; used for debouncing;
extern volatile unsigned long timeBtnMenu;
extern volatile unsigned long timeBtnSet;
extern volatile unsigned long timeBtnPlus;

Why are they volatile?

Do NOT use abs. It is not necessary and may cause problems...

  if ([glow]abs[/glow](millis() - timeBtnMenu) < BOUNCE_TIME_BUTTON)  return;

But none of those things explain the problem you're seeing.

Thanks for the comments, I'll change when possible.

I'm assuming the core patch is bringing unexpected results. I hope that some core developer take a look at it.