Is it possible to re-#define something?

http://playground.arduino.cc/Main/TimerPWMCheatsheet

At the bottom of that page, it suggests a way to keep the Milliseconds() timer functioning properly when increasing the PWM frequency of Timer 0:

For Phase-correct PWM of 31.250 kHz (prescale factor of 1)
Use these two lines in the setup function:

TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00); 
TCCR0B = _BV(CS00); 

And modify the line in the wiring.c function in the Arduino program files
hardware\arduino\cores\arduino\wiring.c :
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(1 * 510))

My question is, can I just throw that #define in my main program after my includes, possibly #undef -ing it first, and have the compiler use that new definition everywhere, or am I going to have to alter wiring.c, which I'd prefer not to do because the modification will affect other projects and will inevitably be lost and forgotten when I back up my project folder?

I'm aware there are other timers I could use, but Timer 1 is in use by the audio library, and both Timer 1 and Timer 2 share pins with the SPI interface, and I want to drive a motor controller with PWM and that means I need two PWM pins for forward and reverse control, and if I used pins from two different timers then both have to be set to the higher PWM speed, and I'm sure I'd regret that decision later if I need Timer 2 for something else.

If u need a variable.. define one

You'd need to alter the wiring.c file itself - changes to your sketch will have no effect on the compilation of wiring.c.

scswift:
My question is, can I just throw that #define in my main program after my includes, possibly #undef -ing it first, and have the compiler use that new definition everywhere, or am I going to have to alter wiring.c, which I'd prefer not to do because the modification will affect other projects and will inevitably be lost and forgotten when I back up my project folder?

Why not save the modified file under a different name, such as mywiring.c, so that it doesn't overwrite the original wiring.c and affect other projects?

Henry_Best:
Why not save the modified file under a different name, such as mywiring.c, so that it doesn't overwrite the original wiring.c and affect other projects?

How would the IDE know to use that instead of wiring.c? I would imagine if I tried to include it I would get all kinds of duplicate function/variable definition errors.

Anyway why you want to do that modification to the library? Can you do the same thing without that modification?

You could add the modified wiring.c to the sketch folder. I just ran a quick test to confirm it gets compiled and linked OK. I haven't tested making any change to the file to prove that the definitions in this copy take precedence over the ones in the standard wiring.c, but I think they probably do.

luisilva:
Anyway why you want to do that modification to the library? Can you do the same thing without that modification?

I explained why in my first post.

PeterH:
You could add the modified wiring.c to the sketch folder. I just ran a quick test to confirm it gets compiled and linked OK. I haven't tested making any change to the file to prove that the definitions in this copy take precedence over the ones in the standard wiring.c, but I think they probably do.

Thanks, I guess I'll try that.

scswift:

Henry_Best:
Why not save the modified file under a different name, such as mywiring.c, so that it doesn't overwrite the original wiring.c and affect other projects?

How would the IDE know to use that instead of wiring.c? I would imagine if I tried to include it I would get all kinds of duplicate function/variable definition errors.

How will the compiler know about the existence of the original if you just include the modified one and not the original?

Henry_Best:
How will the compiler know about the existence of the original if you just include the modified one and not the original?

Uh, the same way it always does? You don't include wiring.c or any other library when you need to use milliseconds(), it's automatically included by the IDE.

And that being the case, if I were to include "mywiring.c", "wiring.c" would still get included, I would assume. And then I would get duplicate function definition errors and the like.