Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Programs >> TVBGone from arduino to wiring
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1273830189

Message started by bozo on 05/14/10 at 09:43:09

Title: TVBGone from arduino to wiring
Post by bozo on 05/14/10 at 09:43:09
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

Title: Re: TVBGone from arduino to wiring
Post by barragan on 05/14/10 at 13:53:24
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.







Title: Re: TVBGone from arduino to wiring
Post by bozo on 05/18/10 at 08:54:08
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

Title: Re: TVBGone from arduino to wiring
Post by barragan on 05/19/10 at 00:17:59
I'll try to work on it during the weekend so you could give it a try.

Title: Re: TVBGone from arduino to wiring
Post by barragan on 05/26/10 at 06:55:15
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



Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.