I'm implementing some code and I am not using millis() and micros() which take advantage of the existing Timer1 Overflow ISR in Wiring.C file.
I need to implement a different routine. Is there a smart way via code to override or reroute to my new ISR? Meaning without deleting or commenting things out in the Wiring.C file. I don't want to fuss with the core files, I just want my own routine on top.
For reference:
Here' the compile error I'm getting when I use my ISR:
core.a(wiring.c.o): In function __vector_4': C:\Users\Me\Documents\Arduino\hardware\tiny\cores\tiny/wiring.c:78: multiple definition of __vector_4'
Digging that up leads to : ISR(MILLISTIMER_OVF_vect)
There is a second core called "tinyNoMillis" which solves this problem by having a version of the core which removes all of the millis() related timer code.
Alternatively for any core, if you add this to your sketch:
int main (void) {
sei();
setup();
for (;;) {
loop();
}
return 0;
}
This will remove all of the millis() stuff, though it will also stop the analogRead(), analogWrite() and tone() functions working.
You can get the analogRead() functionality working again by doing the following:
#if F_CPU == 16000000
// 16 MHz / 128 = 125 KHz
#define ADC_ARDUINO_PRESCALER B111
#elif F_CPU == 12000000
// 12 MHz / 64 ~= 125 KHz
#define ADC_ARDUINO_PRESCALER B110
#elif F_CPU == 8000000
// 8 MHz / 64 = 125 KHz
#define ADC_ARDUINO_PRESCALER B110
#elif F_CPU == 1000000
// 1 MHz / 8 = 125 KHz
#define ADC_ARDUINO_PRESCALER B011
#elif F_CPU == 128000
// 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
#define ADC_ARDUINO_PRESCALER B000
#else
#error Add an entry for the selected processor speed.
#endif
int main (void) {
sei();
// This code will only run once, after each powerup or reset of board
// set a2d prescale factor
ADCSRA = (ADCSRA & ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))) | (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
// enable a2d conversions
ADCSRA |= _BV(ADEN);
setup();
for (;;) {
loop();
}
return 0;
}
Thanks! I'm aware of this option, but maybe you can quickly answer this for me...will this affect the USI clock stuff if I move millis to Timer0?? I'm using USI for for I2C communication.
I solved this problem by installing David Mellis's ATtiny core on GitHub instead of Google Attiny Cores. This core included ATtiny 24 45 85, 14 44 84...