Categories

Site Sponsors

Who's Online

  • 0 Members.
  • 11 Guests.

External WDTV Remote Control Power Switch – Part II

4,725 views
NECMessageFrame

Welcome back, schemers!

If you’re just arriving, then here’s a little background on the current project:  We’re creating a remote-controlled relay board to switch on and off power to the Western Digital WDTV.  In part one of the project, we designed and built a printed circuit board containing the hardware for the project.  In this part, we will discuss the source code for the PIC micro that acts as the brains of the operation.

The WDTV remote uses the NEC infrared protocol at 38kHz to transmit commands to the WDTV.  This 38kHz stream of blinks is demodulated by the IR receiver to a relatively slow serial datastream which is then piped to the PIC.  An example of an NEC datastream is shown below, and was borrowed from here, FYI.  There’s a billion different pages on the NEC IR protocol, but this one is kind of nice because all the timings are shown as well as clear differentiation between 1 and 0 states.

Fig 1 – Annotated Example of NEC IR Format

One thing to remember is that the output of the IR module is open-collector.  So when you see a logic high in the above waveform, the PIC is actually going to be reading a 0.  We’ll refer to this state as MARK, and to the inactive state as SPACE to avoid confusion.

To start out with, our code can simply loop away idly, looking for the input pin to drop from 5v (space) to 0v (mark).  At that point, we’re interested.  We will first check this leading pulse to make sure it’s about 9mS long, give or take about 10-20% to account for timing variations in the PIC internal oscillator as well as whatever crappy osc is used in the actual remote.  If the data stays at mark for 9mS and then goes to space for 4.5mS – we’ve got data!

The NEC stream consists of 4 8-bit bytes.  Well, two bytes actually – but they are repeated in normal and inverse mode so it’s best to just read in all 32 bits and then do our deciphering internally.  The first two bytes are the device (address) and it’s inverse, and the next two are the command and it’s inverse.

A bit is represented by one mark pulse and one space pulse, and the duration of the space pulse determines whether the bit is a 1 or a 0.  Specifically, 565uS of mark followed by 565uS of space signifies a 0.  And 565uS of mark followed by 1.685mS of space signifies a 1.  So really, once we’re convinced that we’ve got data all we need to do is measure 32 space pulses and set the corresponding bits in our data reg high and low.

That’s pretty simple, so NEC must now complicate matters.  If a button is held down on the remote the main command will be sent once, followed by a “repeat” command sent every 109mS.  This repeat command consists of the same 9mS of mark used as a start pulse followed by 2.25mS of space and a single 565uS mark.

Fig 2 – NEC Protocol in Repeat

So here’s the (software) scheme.

  1. Sit around waiting for the start sequence
  2. Decode 32 bits of data
  3. If it’s a power cmd, then turn on WDTV if it’s off.  Go back to #1
  4. If WDTV is on and we receive a power command, flag that we now need to wait for 10 repeats.  Go back to #1
  5. If WDTV is on and we’re repeating, watch for 10 repeats and then turn off WDTV.
  6. If some other command comes in, clear our “repeat” counter and start the whole thing over

Continued on Next Page                        Jump to Page 2

External WDTV Remote Control Power Switch – Part I

10,078 views
WDTV

Today’s project is external power control for the Western Digital WDTV.  Today we will design the circuit and generate the PCB using positive photoresist process.  Tomorrow we will develop the software for controlling the device.

The WDTV is a digital media player for all your (legally-downloaded, of course) media files.  And it’s fantastic!  It can play all the 7337est formats like MKV in full motion 1080i with nary a stutter.  It’s got HDMI output and a teeny tiny remote control, and coupled with a TB or so of storage, it’s a one-stop shop for watching all those MKV and divx home videos that you recorded in HD in 1959.

Fig 1 – The Majestic WDTV

Uh Huh.  Well at least the manufacturers (WD) found a good way to leverage themselves into the “internet” video realm a little deeper.  They must have surveyed buyers of their gigantic HDD’s and found that most users were filling them up with umm, err, “home movies” and “original audio recordings”.  I for example, have over 4000 hours of my own beat poetry and interpretive dance vids on mine.  You should come by and watch for a month or two!

Long story short, they realized that connecting one’s PC to one’s TV just to play said avi files was totally l4m3!  So they built a tiny linux box to suck data from a USB drive and blast HDMI out the other side, all for $99.  Freakin brilliant.  It works a treat, and with the genius of B-RAD, has been hacked as the day is long.

But it has one diabolically annoying (and inefficient) trait – it never powers down!  Pressing the power button just turns off the LED’s – redonkulous!  I’m guessing there are some pretty good design compromises that went along with this, namely:

  • You’d have to remember to cache the “paused” locations for all the in-progress videos.  Woo, really tough stuff.
  • It takes an ass-long time to boot up.  Hide your uglies through trickery, consumers are stupid!

Both fair reasons to skimp on a real power down mode, but it causes some problems of it’s own.

  • Wasted power.  The thing is always on, dissipating it’s 9W or so of electricity.  At that rate, the earth will be a crumbled shell in 40 billion years!!!  hehe
  • The real problem – It never disables it’s HDMI output, so automatic HDMI switches go to WDTV land and NEVER COME BACK!  Now you have to get off your lazy ass and go switch the HDMI swapper manually.  Horrors!

So we’ve decided to post a little EXTERNAL power swapper for the WDTV.  Or any other low-voltage device that you may want to control via an IR remote control.

Truth be told, a guy named Dex did this a long time ago.  And it’s an awesome hack.  But it requires busting open the box and splicing into it’s guts.  Which we usually support, condone, and lobby for till we’re blue in the face!  But in this case it’s a bit less of a pain in the ass to do it externally, and you get a bit more flexibility in unplugging the thing if you decide that you never want to power down your WDTV ever again.  And perhaps you could even reuse this little IR relay board for some upcoming Halloween prank or something!

And the biggest reason of all: It gave us an excuse to use our brand new liquid positive photoresist!  Yay!   This first part of the tutorial will deal with the circuit, and the construction and assembly of the PCB.  Part II will deal with the software for decoding the WDTV’s Remote Control IR stream and doing the power up/down sequencing.  Here’s a pic of the finished monstrosity, sans micro.

Fig 2 – IR Controlled Relay Board for WDTV Power Switching

Continue to Next Page Jump to Page 2