This is a more challenging task when
applied to consumer electronics devices like a TV set.
The above technique of manipulating the TXD pin and
creating a pulse train can be applied with some minor
modifications to only some types of infrared devices.
Consumer appliances like televisions rely on carrier
waves and signal modulation to send encoded data. These
require a slightly different approach.
One very important note edgewise. When
working with custom serial or infrared signals, get
yourself an oscilloscope so that you can see the pulses
you create and check their quality, pulse width,
frequency, stability etc. This is an absolute must. For
infrared signals, get yourself (or build) an infrared
receiving/sending circuit that can be hooked up to an
oscilloscope. See the appendix for more details.
If you apply the RS232 serial pulse
shaping method on the infrared port, the results can be
disappointing. No sustainable square pulses with the
required pulse widths would be found. First of all, to
generate pulse on the infrared port, one needs to set
the UART into the infrared mode. One may also use the
SrmOpen() call instead of dealing directly with the
Using the TXD pin register bit as above
will not create a sustained Infrared pulse. It will
simply generate a spike of 1.6Us duration according to
IrDA specification. And this is more or less a “spike”
waveform, with a small flat top. So how to create a
square pulse of required duration?
The trick is to repeatedly keep the TXD
pin high (or low) as long as you require a corresponding
pulse to maintain itself (its pulse width). That is,
keep writing to the TXD register bit as long as you need
the pulse sustained. Note that the voltage polarity on
the infrared port can be inverted, meaning that clearing
the TXD pin bit can raise the voltage high to a logical
‘1’. It is sufficient to use this technique to create
infrared square pulses and pulse trains.
This is the tricky part. A consumer
device like a Sony TV uses a 40kHz carrier to carry the
encoded pulses. A carrier wave can be described easily
in relation to the diagram below:
A carrier wave oscillates at a
particular frequency and is ‘modulated’ to high or low
levels. In the above diagram, a pulse train of “101” is
shown, ‘0’ representing the absence of a signal. ‘w’ is
the wave length or pulse width of the carrier wave. The
logical ‘1’ is represented by a carrier wave width of
1ms. The durations 1ms and 1.5ms in figure 3 are purely
arbitrary, intended to highlight possible encoding
Generating a rectangular pulse of
prescribed duration is not sufficient to work with a TV
set. One has to create the above carrier signal
precisely. For e.g. a Sony TV infrared control requires
a 40Khz carrier wave. That means that a single wave will
have a w=25Us pulse width.
There are at least two ways to achieve
this. One is more or less straightforward. The other is
more interesting and challenging to do.
The key to understanding the technique
is that the IrDA pulses have a pulse width much less
than that is required by TV sets (1.6Us) and that IrDA
transmission makes use of these pulses (spikes) at
varying baud rates. The exact width or shape of a
“spike” does not matter. What matters is that the
receiving equipment in the TV set sees N number of high
and lows per second (or millisecond for that matter) -
Compute the baud rate at which the
infrared transmitter should be set to generate pulses at
the required frequency (of the carrier wave). If the
baud rate is not directly available, the DragonBall
processor has a baud rate generator which can be custom
programmed to generate most practical baud rates.
Now considering that each spike
represents a bit in IrDA transmission, construct a long
bit sequence of ‘0’s that will keep the carrier wave on
“high” for the desired period of time. This is assuming
that the polarity of the output is inverted, so that a
‘0’ results in a spike. Convert these bit strings into
bytes and write them to the infrared port using SrmXYZ()
calls. The absence of a signal may be used to construct
a logical 0.
This technique involves creating the
carrier wave manually. For this, one has to compute the
pulse width required for a single wave of the carrier
and then use the TXD pin to generate a carrier wave.
This means repeatedly setting (or clearing for inverted
polarity) the TDX register bit with timed delays in
between. When brought high, the pulse automatically
starts going down after a delay of 1.6Us. So it is
sufficient to wait until the next pulse needs to be
created and then set the TXD pin high again.
The absence of a signal will again be
used to construct a logical 0.
This technique requires precise
management of timers and/or timing counters on the
DragonBall processor. Since it is possible to keep track
of time to the order of sub-microseconds, this is not a
very difficult task.
Common Infrared Remote
Control Encoding Techniques
Some of the common encoding standards
In Pulse coded encoding, the length
of the pulse is varied to represent data.
Pulse coded signal
In Space coded encoding, the length of
the space between the pulses is varied to represent
Space coded signal
Note that these may again be sent over a
modulated carrier wave. Remote control codes databases
for most consumer devices can be found online.
Controlling a Sony
The Sony TV remote control is based on a
12-bit signal scheme sent on a 40Khz IR wave. The
encoded signal contains both address and the data. The
address is the device ID code, which determines the type
of device this signal is intended for. The device ID
code for TV is 00001.
The signal begins with a header, which
is a pulse for 4T and then a spacing for T where T is
600 microseconds. Following the header is the address
and the command, which consists of logical ones and
logical zeros. Logical ones are represented by a 2T
pulse followed by a T space. Logical zeros are
represented by a T pulse followed by a T space. The
space between transmissions is 25 ms. One may have to
repeat the pattern 4 or 5 times for the TV to recognize
Bits are transmitted low order bit
first, progressing towards high order bits.
For example the code to toggle power
would be sent as follows. The device ID for TV is 00001
and the button code for the power switch is 0010101.
Thus, the entire control word is 000010010101. To send
this command to the TV, one must first send to a 2.4 ms
start bit, and then send the bits in reverse order (i.e.
101010010000). This of course must be sent over a
carrier wave generated as mentioned in the earlier
The following code does not generate a
carrier wave. Since we have covered carrier wave
generation already, it will be sufficient to provide the
logic behind the signaling here.
/*send the start bit (header) */
raise the line to logic-1
wait 2.4 ms
lower line to logic-0
wait 0.6 ms
/*send each of the 12 bits out one at a time, low order bit first*/
for current_bit = low_order_bit to high_order_bit do begin
raise line to logic-1
if(current_bit is a 1)
wait 1.2 ms /*high duration of a 1 bit*/
wait 0.6 ms /*high duration of a 0 bit*/
lower line to logic-0
wait 0.6 ms /*low duration of all bits*/
lower line to logic-0
wait 25 ms