Pages: 1 [2]   Go Down
Author Topic: IR Code on Attiny gives error  (Read 7687 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Robot-Worker solidarity!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok loading the blink sketch is working fine now. However still cannot load the IR code was originally trying to put on the attiny85. I get this compiler error:

Code:
/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
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 212
Posts: 13081
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The ATtiny85 processor does not have a timer 2.  Timer 0 on the ATtiny85 is very similar to the even numbered timers (like timer 2) on ATmega processors.  Changing the code to use timer 0 should work.  You may even be able to make the change with a simple search-and-replace...

TCCR2A --> TCCR0A
COM2B1 --> COM0B1
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Robot-Worker solidarity!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can find neither TCCR2A nor COM2B1 in the code or in the .h file it is referencing. I can however find these in the .cpp file in the folder with the code i downloaded. Changing just what you suggested gives me this error when running the code again:

Code:
/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: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: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



Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Robot-Worker solidarity!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the .cpp file is too large to post here but you can see it in this zip file: http://arcfn.com/files/IRremote.zip
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 212
Posts: 13081
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Changing just what you suggested gives me this error when running the code again:

Those two items are examples.  They are not a comprehensive listing.  You will have to change all of the register and bit references from timer 2 to timer 0.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Robot-Worker solidarity!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okeydoke. I'll keep track of what I change and report back after I find as many as I can.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Robot-Worker solidarity!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, here is a list of the parts I have guessed need changing. If any of these is not part of the register or bit references please point it out:
again you can get the .cpp file i am trying to fix from this zip file: http://arcfn.com/files/IRremote.zip

Code:
void IRsend::mark(int time) {
  // Sends an IR mark for the specified number of microseconds.
  // The mark output is modulated at the PWM frequency.
  TCCR2A |= _BV(COM2B1); // Enable pin 3 PWM output
  delayMicroseconds(time);
I changed only TCCR2A to TCCR0A here


Code:
/* Leave pin off for time (given in microseconds) */
void IRsend::space(int time) {
  // Sends an IR space for the specified number of microseconds.
  // A space is no output, so the PWM output is disabled.
  TCCR2A &= ~(_BV(COM2B1)); // Disable pin 3 PWM output
  delayMicroseconds(time);
I changed only TCCR2A to TCCR0A here

Code:
// Disable the Timer2 Interrupt (which is used for receiving IR)
  TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt
I only changed TIMSK2 to TIMSK0 here

Code:
// COM2A = 00: disconnect OC2A
  // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
  // WGM2 = 101: phase-correct PWM with OCRA as top
  // CS2 = 000: no prescaling
  TCCR2A = _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
I changed TCCR2A to TCCR0A and TCCR2B to TCCR0B

Code:
// The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
  OCR2A = SYSCLOCK / 2 / khz / 1000;
  OCR2B = OCR2A / 3; // 33% duty cycle
I changed both 'OCR2A's to OCR0A and OCR2B to OCR0B

Code:
// setup pulse clock timer interrupt
  TCCR2A = 0;  // normal mode
I changed TCCR2A to TCCR0A

Code:
//Prescale /8 (16M/8 = 0.5 microseconds per tick)
  // Therefore, the timer interval can range from 0.5 to 128 microseconds
  // depending on the reset value (255 to 0)
  cbi(TCCR2B,CS22);
  sbi(TCCR2B,CS21);
  cbi(TCCR2B,CS20);
I changed only the 'TCCR2B's to TCCR0B

Code:
//Timer2 Overflow Interrupt Enable
  sbi(TIMSK2,TOIE2);

  RESET_TIMER2;
I changed TIMSK2 to TIMSK0 and RESET_TIMER2 to RESET_TIMER0

Code:
ISR(TIMER2_OVF_vect)
{
  RESET_TIMER2;
I changed both 'TIMER2's to TIMER0

After doing all of this I Attempted to compile for the attiny85 and got this error:

Code:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::mark(int)’:
/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: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: ‘TIMSK0’ 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:12: error: ‘WGM20’ 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: In member function ‘void IRrecv::enableIRIn()’:
/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 __vector_5()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘RESET_TIMER0’ was not declared in this scope
Logged

Amsterdam
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I ported the IR receive and decode part of Ken Shirriff's IR library to the attiny4313. I also successfully tested this on an attiny85. There is a short write-up and the link to the code here http://ubiyubix.wordpress.com/2012/05/05/porting-the-arduino-irremote-library-to-the-attiny4313/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to do the same project, however I need to use both irsend and irreceive...I've tried changing to timer0 and timer1 to no avail. Any ideas?  I am using the Arduino as an ISP with an attiny85
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I looked at porting Ken's IR library, but it looks like it uses two timers on the 328p.  On the attiny 45/85 I don't see the same amount of timers.  Perhaps that is why ubiyubix only is using IR receive and decode.
Logged

Varese
Offline Offline
Full Member
***
Karma: 2
Posts: 215
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

is there a porting of the Ir Remote for ATtiny85?
I need to decode commands with encoding rc5.
Logged

Arduino UNO starter kit.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is there a porting of the Ir Remote for ATtiny85?
I need to decode commands with encoding rc5.

Take a look at ubiyubix's post which is about 4 posts up.
Logged

Pages: 1 [2]   Go Up
Jump to: