california software homepagecalifornia site mapcalifornia searchIT Consultants and E-Business Solution Providers
IT Consultants and E-Business Solution Providers CompanyServicesProductsIndustry SolutionsPortfolioTechguideContactus
corporate image
TechCenter
Overview
Whitepapers
Contact Calsoft Consultant
corporate image
Palm Shaping, palm pilot
Whitepapers

Pulse Shaping on the Palm Pilot

Pulse Shaping on the Palm Pilot Download this document in MS Word format [57k Zipped] or Adobe Acrobat PDF format [53k Zipped]

Rekesh John
Joseph Prabhu
California Software Co. Ltd.
E139A First Floor,
M.G.Road,
Besant Nagar,
Chennai - 600 090 INDIA.
http://www.calsoft.co.in/

June 2001

Index

Introduction

In this article we look at low level programming of the Palm Pilot, especially its Motorola MC68EZ328 DragonBall processor, also known as DragonBall-EZ. The aim is to use the DragonBall processor to create or simulate serial transmission functionality through the infrared and serial ports. More specifically, we look at how one may implement a Palm Pilot based remote control for consumer equipments such as a TV. We also look at how to communicate with a PC or device through a serial line by directly manipulating pins to create a pulse train.

We do not propose to cover detailed serial/infrared programming details of the DragonBall EZ chip. Interested readers may use the references section to get to Motorola documentation on the processor.

Back to Index

The UART

The UART (Universal Asynchronous Receiver Transmitter) is key to serial and infrared operations. Programming the UART built into the DragonBall processor is not a difficult task. Motorola technical support is also very cooperative when it comes to answering questions related to this processor.

The UART controls both the serial and infrared interfaces and have registers with which one can directly work to set up and operate these interfaces. A number of these registers will be used to manipulate the transmission line to generate pulses.

The UART has two modes of operation – NRZ and IrDA.

The Non-Return to Zero (NRZ) mode is usually associated with RS-232. Each character is transmitted with a start bit at the beginning and a stop bit at the end. Data bits are transmitted least significant bit first and each bit is presented for a full bit time.


NRZASCII "A" character with odd parity

Infra-red (IrDA) mode instead of transmitting ones and zeros for a full bit time, zeros are transmitted as 3/16 bit time pulses and ones remain low.


IRDA ASCII "A" character with odd parity

Back to Index

The UART Receiver

The UART module receives data through the RXD (Receive Data Signal) pin. In NRZ mode, standard NRZ data is expected. In IrDA mode, a pulse of at least 1.0 micro sec is expected for each zero bit received.

Before beginning to receive data, a port is to be opened either in serial mode or IrDA mode. A preferred baud rate is also specified while opening the port.

The data can then be read by repeatedly sampling the RXD pin. The RXD pin multiplexed with Parallel Port E register's bit 4 (PE4). The address for the Port E data register (PEDATA) is FFFFF421. Before doing this, the associated SELx (SEL4) has to be set and the DIRx (DIR4) has to be configured as input (must be low). The address of Port E select register (PESEL) is FFFFF423 and that of Port E direction register (PEDIR) is FFFFF420.

Back to Index

The UART Transmitter

The UART module transmits data through the TXD (Transmit Data Signal) pin. While the UART is in NRZ mode, normal data is output with “marks” transmitted as logic high and “spaces” transmitted as logic low. In IrDA mode, this pin, which is a 1.6 mciro sec pulse, is out put for each “zero” bit that is transmitted.

Before transmitting data, a port is to be opened. This is done using the Serial Manager call SrmOpen (). The port can either be opened in serial mode or IrDA mode depending upon the type of signals to be transmitted. A preferred baud rate is also specified while opening the port.

Data can be transmitted by setting or clearing the TXD pin according to the bit pattern required. The TXD pin is multiplexed with Parallel Port E register's bit 5 (PE5). The address for the Port E data register is FFFFF421. Since MC68EZ328 uses memory mapped registers, the Port E data register can be read by setting a pointer to the correct memory location and loading the value.

Setting and clearing this pin according to the required bit pattern generate pulses for the codes controlling the TV. Before doing this, the associated SELx (SEL5) has to be set and the DIRx (DIR5) has to be configured as output (must be high).

Back to Index

Shaping pulses for RS232 serial transmission

As mentioned above, the TXD pin is multiplexed with Parallel Port E register’s bit 5 (PE5). By manipulating the TXD pin, one can create any arbitrary pulse train. Setting and clearing the TXD bit has the effect of setting the voltages on the transmit line high and low. For the Rs232 serial line, the output voltage stays at its level until the register bit value is changed.

The DragonBall MC68EZ328 processor uses a memory mapped I/O architecture. Therefore the registers mentioned above are accessible directly through memory read/write operations. For example, the port E data register is located at address 0xFFFFF421, the direction register at 0xFFFFF420 and the selection register at 0xFFFFF423.

To communicate with a PC for example, one has to choose a baud rate, number of data bits (8,7), parity setting (odd, even etc), number of stop bits (1,2). The baud rate choice affects the width of the pulses. The others affect the number of pulses as well as reflect parity bits. Once the settings are chosen, data can be transmitted by setting and clearing the TXD pin as required to create the pulse train for each byte/character.

For example to transmit the character “A” at 9600 baud, 8 bits, odd parity, 1 stop bit, as in igure 1, one could do the following:

The ASCII value for “A” is 65 and its bit pattern is 01000001. Refer Fig. 1 for the bit pattern.After adding the Start bit, parity and the stop bits, the bit pattern to transmit “A” is 01000001011. Note that in the above bit pattern, the least significant is transmitted first i.e. Bit 0 is transmitted after the start bit.

The following is the pseudo code for transmitting character “A” using the TXD pin.

arrCharA[] = “01000001”; //bit pattern for char A (ASCII = 65) begin SET_BIT (portESelect, TXD_LINE); //Set bit 5 of Parallel Port E Select register SET_BIT (portEDir, TXD_LINE); //Set bit 5 of Parallel Port E Dir register //start bit lower line to logic-0 // Clear bit 5 of Parallel Port E Data register Delay(); //time for which the bit is to be set/cleared //Transmit Char “A” low order bit first for current_bit = low_order_bit to high_order_bit do begin if(current_bit is a 1) raise line to logic-1 // Set bit 5 of data register Delay(); else lower line to logic-0 // Clear bit 5 of data register Delay(); end if end for //parity bit if (parity required) raise/lower line to reflect parity Delay(); end if //1 stop bit raise line to logic-1 Delay(); CLEAR_BIT (portESelect, TXD_LINE); //Clear bit 5 of Parallel Port E Select register CLEAR_BIT (portEDir, TXD_LINE); //Clear bit 5 of Parallel Port E Dir register end

Note that the UART needs to be initialized for serial transmission. This can be done by directly manipulating registers. Or one may choose to call routines like SrmOpen() on the PalmPilot.

The Delay() routine is not difficult to create. The timer registers may be used to measure time in microseconds. The default timer counter increments every 0.18 Us. At 9600 baud (i.e. 9600 bits/second), or 1 bit in 104 micro seconds, that is approximately 578 counter increments for the duration of a single bit.

Some details of timer management will be covered next.

Back to Index

Timers

The DragonBall has a 16-bit general-purpose timer. The timer mechanism is mainly driven by the following set of registers:

  • Timer Control Register (TCTL) (FFFF600)
  • Timer Compare Register (TCMP) (FFFF640)
  • Timer Counter Register (TCN) (FFFF608)
  • Timer Status Register (TSTAT) (FFFF60A)

The Timer counter register is a counter that is refreshed every 0.18 microsecs and it can be read anytime without disturbing the current count. The address of the Timer counter register is FFFFF608. The Timer compare register contains a value that is compared with the running counter. A compare event is generated when the counter matches the value in this register. The default value in the compare register is 0xD7E4 (55268), which results in an interrupt being generated every 10 milliseconds.

The Timer status register indicates the timer’s status. When a compare event occurs a bit in the status register set.

The timer can be configured for free run or restart mode. In restart mode, once the compare value is reached, the counter resets to 0x0000. In free run mode, the compare function operates the same as it does in restart mode, but the counter continues counting without resetting to 0x0000. However, the counter rolls over to 0x0000 on reaching 0xFFFF.

These timer registers provide a fairly accurate way of keeping track of time to the order of microseconds.

Back to Index

Why use serial pulse shaping ?

Manipulating serial pulse trains can be useful when your device or PDA needs to talk to another device through protocols that are not RS232 compliant. For example, there may not be any associated parity or start bits. The pulse widths may not be the same across all bits. The timing between pulses might be different. There may not be handshakes as used in RS232. Even the TXD pin may not be the pin used to transmit(!). One can use other pins too and manipulate them directly through registers.

The same applies when inspecting signals coming into the system (receiving signals).

Back to Index

Infrared Remote Control Pulse Shaping

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.

Back to Index

Simple pulse shaping

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 registers.

Back to Index

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.

Carrier-wave pulse shaping

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:


Modulated signal

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 schemes.

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) - consistently.

Back to Index

Technique 1

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.

Back to Index

Technique 2

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.

Back to Index

Common Infrared Remote Control Encoding Techniques

Some of the common encoding standards are:

  • Pulse coded
  • Space coded

Back to Index

Pulse coded

In Pulse coded encoding, the length of the pulse is varied to represent data.


Pulse coded signal

Back to Index

Space coded

In Space coded encoding, the length of the space between the pulses is varied to represent data.


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.

Back to Index

Controlling a Sony TV

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 the command.

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 sections.

Back to Index

Pseudo Code

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.

begin /*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*/ else wait 0.6 ms /*high duration of a 0 bit*/ end if lower line to logic-0 wait 0.6 ms /*low duration of all bits*/ end for lower line to logic-0 wait 25 ms end

Back to Index

Conclusion

Infrared and serial interface signals from a PDA form a powerful means of controlling and communicating with all kinds of devices. We have provided here a basis for working with such signals and creating powerful applications that may be run from a Palm Pilot. The techniques may be applied to other PDAs, laptops and PCs based on different microprocessors and UARTs, again using the same principles. We’ll be describing a version for Windows CE hand held devices in the near future. Such kind of applications need not be restricted to infrared, but may also extend to RF (Radio Frequency) as well, with proper interface hardware. An example would be a Palm Pilot or Windows CE based RF signal generator or detector used for inventory tracking. We expect such uses of hand held devices to become widespread in the next few years.

Back to Index

References

Back to Index

Appendix A

Observing RS232 signals on an Oscilloscope

The pulses can be observed using an oscilloscope. Connect the Gnd from the oscilloscope to Signal Gnd in the RS232 pin. The Signal Gnd in RS232 is pin 5. Then signals in Pin 2 “Received Data” and Pin 3 “Transmit Data” may now be observed.


Rs232 9 pin diagram

Observing IR signals through an oscilloscope


IR receiver/transmitter circuit

To observe signals that are transmitted through IR, one requires a circuit having an IR receiver. A sample circuit that we implemented is shown in figure 5, borrowed from the Internet (see references). One can connect the Gnd from the oscilloscope to the Gnd in the circuit, tap the detector circuit and observe the signals from the receiver. One may need to cover up the transmitting diode when working with the photo diode to prevent chance interference. Point your infrared source at the photo diode and observe the signals on the oscilloscope.

Back to Index

For More Information

Calsoft helps companies develop software products & applications using state of the art technologies & tools. Visit http://www.calsoft.co.in for more information on California Software Pvt Ltd.

Pulse Shaping on the Palm Pilot Download this document in MS Word format [57k Zipped] or Adobe Acrobat PDF format [53k Zipped]

Back to Top

PulseShaping on the Palm Pilot

PulseShaping
Any third party logos and tradenames referred to are the trademarks of the respective companies