Go Down

Topic: Help Change timer 2 to timer 0 (Read 4 times) previous topic - next topic

williamanos

I am attempting to change this code from using timer 2 to using timer 0 so I can use it with an attiny85 that does not have timer 2.

Here is a link to the zip file containing the code: http://arcfn.com/files/IRremote.zip

I am modifying the .cpp file

When I first tried to upload this without having changed the timer I got this error:
Code: [Select]
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::mark(int)':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:3: error: 'TCCR2A' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:13: error: 'COM2B1' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::space(int)':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:3: error: 'TCCR2A' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:15: error: 'COM2B1' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: 'TIMSK2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:14: error: 'TOIE2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:3: error: 'TCCR2A' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:12: error: 'WGM20' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:3: error: 'TCCR2B' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:12: error: 'WGM22' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:25: error: 'CS20' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:211:3: error: 'OCR2A' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:212:3: error: 'OCR2B' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:224:3: error: 'TCCR2A' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: 'TCCR2B' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: 'CS22' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:230:3: error: 'CS21' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:231:3: error: 'CS20' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: 'TIMSK2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: 'TOIE2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: 'TCNT2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function 'void TIMER2_OVF_vect()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: 'TCNT2' was not declared in this scope


I went through the .cpp file and changed each one of the parts mentioned so that the 2s became 0s. Having done that I am still getting this error message:
Code: [Select]


/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: 'TIMSK0' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: 'TIMSK0' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: 'TCNT2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function 'void TIMER2_OVF_vect()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: 'TCNT2' was not declared in this scope


I don't understand! Please help.

Thanks,
Will

Nick Gammon

Have a look at the datasheet. Since there is only one timer it is TIMSK not TIMSK0. And so on for the other things.

williamanos

Thanks Nick! I have changed the TIMSK0's to TIMSK but i am still getting this error message:

Code: [Select]

/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: 'TCNT2' was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function 'void TIMER2_OVF_vect()':
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: 'TCNT2' was not declared in this scope


and yet when I search the .cpp file there is no 'TCNT2'

I had changed these to TCNT0. Need I go back and delete all of the zeros inserted at the beginning?

Thank you so much again!

williamanos

correction: there is no TCNT at all in the .cpp file

Nick Gammon

Look in IRremoteInt.h which is included by the main library:

Code: [Select]
// clock timer reset value
#define INIT_TIMER_COUNT2 (CLK - USECPERTICK*CLKSPERUSEC + CLKFUDGE)
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2

Go Up