Trying to use TIMER0_OVF_vect on attiny85


I am trying to port some example code I found at:

to the ATtiny85.

I'm using the procedure described at:

to program my attiny85 chip.

The trick is that the example code uses the TIMER1_CAPT_vect to trigger the ADC (on the arduino). This isn't available on the '85. So instead, I'd like to use TIMER0_OVF_vect.

Compiling my code gets me an error:

core.a(wiring.c.o): In function init': /home/peter/opt/arduino-1.0.5/hardware/arduino/cores/arduino/wiring.c:193: multiple definition of __vector_5'
adc2pwm_attiny85.cpp.o:/home/peter/opt/arduino-1.0.5/adc2pwm_attiny85.ino:44: first defined here

which I expect is because the arduino core uses TIMER0_OVF_vect for its own time-related functions.

What I am wondering is, since I'm not using any of the time-related functions in my code, is there a nice way (i.e. something limited to the code in my sketch) to disable the time-related functions and thereby free up the TIMER0_OVF_vect?



You are correct. TIMER0_OVF_vect is defined in your core for the interrupt used by millis().

If you define it again you get multiple definitions, followed by a linker error.

If you really need that interrupt I believe there's cores that use timer 1 for millis(), also options in the source code for your core to choose a timer. Dig around.

This core use Timer1 for millis() for Attiny85t:

My core for the Attiny85 didn't give that error, not sure where I got it.

However compiling for the Uno, I get it, but this doesn't:

  // whatever      

int main ()
    // your code here

By using main rather than setup and loop, the code that users Timer 0 is not linked, and so there is no clash. You could do something similar. Of course you have to do your own hardware initialization, and you won't have millis(), delay() etc.