I am using an Arduino Leonardo (ATMEGA32U4) and need to use timer0 for pwm. Since by default in the wiring.c file the functions micros() and millis() use timer0, i decided that since timer1 isn't being used, i could set up timer1 exactly how timer0 is set up for the micros() and millis() functions and modify their code so that it all uses timer1 instead of timer0.
I think in theory this should work. I read the datasheet and timer1, while being a 16-bit timer, can run in an 8-bit fast pwm mode (which is what timer0 is set up for). So i modified the wiring.c to do as above: adjusted the prescaler to match the original for timer0 (f/64) and put the timer1 into fast-pwm 8-bit mode.
I modified any functions in wiring.c that used any register from timer0 and changed them to use the corresponding registers in timer1.
However, the problem is that it seems like i did everything right, but when i try to run a simple program that calls Serial.println("hello world"), it is messed up. The output instead shows a repeated 'h' character to the serial console. I'm not really sure whats wrong and wondering if anyone can help.
Here is a link to a pastebin containing my re-written wiring.c file that essentially moves all the functionality from timer0 to timer1: