Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpPrograms › TVBGone from arduino to wiring

Page Index Toggle Pages: 1
TVBGone from arduino to wiring (Read 6530 times)
05/14/10 at 09:43:09

bozo   Offline
YaBB Newbies
France

Posts: 2
*
 
Hi all,
You may know TVB-gone, a small infrared gadget which can switch off any kind of TV... An absolute must-have for the FIFA world cup, opening next month ;o)   http://www.tvbgone.com
Ken Shirriff successfully ported TVBGone to the arduino platform : http://www.arcfn.com/2009/12/tv-b-gone-for-arduino.html
the sketch is here : http://arcfn.com/files/arduino-tv-b-gone-1.zip
But this doesn't compile on my wiring board. May be it is a library issue but I don't understand exactly how it works on the wiring platform...

thank's
Fab
 
IP Logged
 
Reply #1 - 05/14/10 at 13:53:24

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi Fab, ok, looking at the code I see the code is attached to specific CPU registers specifically those regarding Timer2, I have a few questions, do you know the code well enough to port it adding #if preprocessors to add other targets?

For example I can fix the first set of errors in xmitCodeElement() by doing this:
#if defined(WIRING)
    timer2SetPrescaler(TIMER_CLK_DIV8);
#else
    TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(WGM22) | _BV(CS21);
#endif

The second set of errors in the same function I can fix using this:

#if defined(__AVR_ATmega128__) // Wiring board with atmega128 has only TCCR2
  TCCR2 = 0;
#else  // wiring board with atmega1281 and atmega1281 does have this registers
  TCCR2A = 0;
  TCCR2B = 0;
#endif

The next error is in sendAllCodes() function,
    OCR2A = freq;
    OCR2B = freq / 3; // 33% duty cycle

OCR2A does not exist in atmega128 but it does in atmega1281 and atmega2561,
but right there I don't get exactly what are you trying to do, is pin3 in arduino where the IR led should be connected one of the PWM pins of arduino?

There is a library in Wiring 0026 that uses Timer2 and can give you hints or help me to port this, please check it out a bit: http://wiring.uniandes.edu.co/source/trunk/wiring/lib/Timer2/
Also as you saw from the code Wiring has methods for programmers to set the Prescalers and other things in timers, check them here: http://wiring.uniandes.edu.co/source/trunk/wiring/core/WTimer.c?revision=726&view=markup

Which Wiring board are you using?
Let me know what do you think.






« Last Edit: 05/18/10 at 00:45:51 by barragan »  
IP Logged
 
Reply #2 - 05/18/10 at 08:54:08

bozo   Offline
YaBB Newbies
France

Posts: 2
*
 
thank's for reply,

I own an original 2004 Wiring board (atmel128)
the tvbgone sketch seems to use some specific and low level features of the atmega 328, porting it should be way over my skills ! but i'll give it a try.

thank's

Fab
 
IP Logged
 
Reply #3 - 05/19/10 at 00:17:59

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
I'll try to work on it during the weekend so you could give it a try.
 
IP Logged
 
Reply #4 - 05/26/10 at 06:55:15

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
ok, here is the fix, Please try it and let me know.

For example I can fix the first set of errors in xmitCodeElement() by doing this:
#if defined(WIRING)
    timer2SetPrescaler(TIMER_CLK_DIV8);
#else
    TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(WGM22) | _BV(CS21);
#endif

The second set of errors in the same function I can fix using this:

#if defined(__AVR_ATmega128__) // Wiring board with atmega128 has only TCCR2
  TCCR2 = 0;
#else  // wiring board with atmega1281 and atmega1281 does have this registers
  TCCR2A = 0;
  TCCR2B = 0;
#endif

Third error: inside sendAllCodes() function use this:

#if defined(__AVR_ATmega128__)
    OCR2 = freq / 3;
#else
    OCR2A = freq;
    OCR2B = freq / 3; // 33% duty cycle
#endif


 
IP Logged
 
Page Index Toggle Pages: 1