Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| learn:courses:unit-5:start [2017/03/20 19:56] – created Martha | learn:courses:unit-5:start [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Unit 5: IrDA Communications Protocols ====== | ====== Unit 5: IrDA Communications Protocols ====== | ||
| + | [[{}/ | ||
| + | [[{}/ | ||
| + | |||
| === Unit 5 Lab === | === Unit 5 Lab === | ||
| - | * [[https:// | + | * [[/ |
| === Download This Document === | === Download This Document === | ||
| - | * {{ : | + | {{ : |
| + | |||
| + | ===== 1. Introduction ===== | ||
| + | This unit demonstrates how to use interrupts and the core timer to decode two IrDA protocols, in an effort to teach approaches for decoding different IrDA protocols used for remote device control. The IrDA is an implementation of wireless serial communications capable of simplex as well as half-duplex operation. | ||
| + | |||
| + | I have encountered no fewer than 100 IrDA encoding protocols using pulse modulated infrared beams of light. Of the four IR remote control units I have found around my home, no two use the same encoding scheme. With so many existing IrDA protocols used for remote control devices, I present a method for decoding and encoding the NEC protocol that can be used on different schemes. I have verified this methodology for decoding the Pulse Length (also called Pulse Distance Modulated) protocol. Lab 5 will challenge you to follow the methodology presented to develop an interface for an IrDA remote control device of your own choosing. | ||
| + | |||
| + | Some silicon devices will decode NED encoded IrDA to 9600 Baud UART outputs, such as the [[http:// | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 2. Objectives: ===== | ||
| + | - Identify the IrDA protocol by capturing the bit stream on the IR_RX pin using the Analog Discovery 2. | ||
| + | - Develop a C function that executes an algorithm to decode the IrDA bit stream. | ||
| + | - Display the received codes on the LCD and send to the UART communications port. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 3. Basic Knowledge: ===== | ||
| + | - How to configure I/O pins on a Microchip® PIC32 PPS microprocessor. | ||
| + | - How to configure the Analog Discovery 2 to display logic traces. | ||
| + | - How to implement the design process for embedded processor based systems. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | ===== 4. Unit Equipment List ===== | ||
| + | ==== 4.1. Hardware ==== | ||
| + | - [[https:// | ||
| + | - [[https:// | ||
| + | - Ordered List ItemWorkstation computer running Windows 10 or higher, MAC OS, or Linux | ||
| + | |||
| + | In addition, we suggest the following instruments: | ||
| + | - [[https:// | ||
| + | |||
| + | ==== 4.2. Software ==== | ||
| + | The following programs must be installed on your development work station: | ||
| + | - [[http:// | ||
| + | - [[http:// | ||
| + | - [[http:// | ||
| + | - [[https:// | ||
| + | - [[http:// | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 5. Project Takeaways ===== | ||
| + | - Understanding of the basics of IrDA protocols. | ||
| + | - Using instrumentation to characterize data streams. | ||
| + | - Use processor external interrupts to decode signal timing patterns. | ||
| + | - Approaches to using state machines to process data. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 6. Fundamental Concepts ===== | ||
| + | ==== 6.1. IrDA Concepts ==== | ||
| + | It is reported that 99% of all consumer electronics use IrDA remote controllers.((“What is infrared? | ||
| + | |||
| + | IrDA communications has two major applications: | ||
| + | |||
| + | **Table 6.1. IrDA vs. Bluetooth features comparison.**(([[http:// | ||
| + | ^ ^ IrDA-Data | ||
| + | | Physical Media | Infrared | ||
| + | | Communications Range | Up to at least 1m | 10cm to 100m | | ||
| + | | Connection Type, Direction | ||
| + | | Maximum Data Rate | 4Mbps (16Mbps on the way) | 1Mbps (aggregate) | ||
| + | | Security | ||
| + | | Approximate Cost | under $2 | under $5 | | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 7. Background Information ===== | ||
| + | ==== 7.1. IrDA Physical Layer ==== | ||
| + | The Basys MX3 platform is equipped with a Rohm RPM973-H11 infrared communications module that provides the digital interface, as shown in Fig. 7.1. The three microprocessor control pins shown in Fig. 7.2 are the IR_TX, IR_RX, and the IR_PDOWN. The Rohm RPM973-H11 is in a low power mode whenever the IR_PDOWN control signal is in the high state. The IR_PDOWN must be in a low state to transmit or receive infrared signals. Both IR_TX and IR_RX are [[https:// | ||
| + | |||
| + | {{ : | ||
| + | //Figure 7.1. RPM973-H11 block diagram.// | ||
| + | |||
| + | {{ : | ||
| + | //Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.// | ||
| + | |||
| + | Reference 3 lists 21 modulation protocols used for remote control devices. This reference also lists standard carrier frequencies used by these devices. In addition to different kinds of coding and different carrier frequencies, | ||
| + | |||
| + | ==== 7.2. Characterization of the NEC IrDA Protocol ==== | ||
| + | The NEC protocol will be characterized to illustrate the methodology of discovering the protocol used by an IrDA remote controller. The general procedure is to capture logic analyzer traces and match the data profile to an existing IrDA protocol. This is commonly referred to as reverse engineering. | ||
| + | |||
| + | Figure 7.3 shows that the IR LED modulation for a 38 kHz carrier is determined as the inverse of the period between LED pulses. The LED is only on for about 2.4 μs out of the 26.3 μs carrier frequency period. The duty cycle of the LED is less than 10% resulting in lower power consumption. | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | //Figure 7.3. IrDA 38 kHz carrier signal.// | ||
| + | |||
| + | Figure 7.4 shows a complete IrDA message using the NEC protocol. The signal is low whenever an infrared light is detected. The NEC protocol message contains 32 bits organized in eight bit bytes sent with LSB first. After a 9 ms leader and a 4.5 ms gap, a 560 μs bit marker signals the start of the LSB of the first data byte, as shown in Fig. 7.5. | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | //Figure 7.4. Screen capture of a NEC IrDA control message.// | ||
| + | |||
| + | Figures 7.5 and 7.6 show expanded views of portions of the NEC IrDA protocol, showing the sync followed by three of the 24 data bits. Note that the differentiation between a ONE bit and a ZERO bit is the length of the gap following each 560 μs period of 38 kHz modulated infrared pulses. The last byte contains 9 pulse bursts to allow the last bit to be framed correctly. | ||
| + | |||
| + | {{ : | ||
| + | //Figure 7.5. Details of the message leader and first three data bits.// | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | //Figure 7.6. 38 kHz pulse burst timing representing two ZERO bits and a ONE bit.// | ||
| + | |||
| + | |||
| + | Figures in Reference 4 are reproduced below to illustrate the timing of the NEC protocol. The encoding of an NEC protocol message in Fig. 7.7 shows that the entire packet consists of two bytes of data: the address byte and the command byte. Each byte is followed by its [[https:// | ||
| + | |||
| + | {{ : | ||
| + | //Figure 7.7. NEC encoded IrDA message.// | ||
| + | |||
| + | If the key on the remote control unit is held depressed for longer than 110 ms, a repeat code is continuously sent that contains no address or command data, as illustrated in Fig. 7.8. | ||
| + | |||
| + | {{ : | ||
| + | //Figure 7.8. Timing diagram of a repeated NEC encoded IrDA message.// | ||
| + | |||
| + | |||
| + | ==== 7.3. Decoding the NEC IrDA Protocol with the PIC32MX370 Processor ==== | ||
| + | From the previous discussion, it is obvious that the PIC32 UART is not suitable for implementing the IrDA NEC remote control protocol. My investigation of internet documents has not produced any meaningful information as to how to implement this design. From my 30 years of microprocessor design experience, I have concluded that there are two possible approaches: application of digital signal processing concepts, namely Fast Fourier Transforms (FFT), or edge timing using PIC32 Input Compare capability or external interrupts. Interestingly, | ||
| + | |||
| + | The modulation and demodulation of the IrDA signal involves binary coding of the 38 kHz carrier signal. As shown above, the bit value information for the NEC protocol is contained in the period length between the 38 kHz IR beam oscillations. | ||
| + | |||
| + | My approach is to first map the PPS input of the IR_RX signal on Port B pin 6 to the external interrupt INT1 as shown in Table 7.1 below. The INT1 is configured to generate an interrupt on the falling (negative) edge of the IR_RX signal using the initialization code shown in Listing 7.1. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Listing 7.1. Initialization of INT1 ==== | ||
| + | < | ||
| + | // Set up IrDA RX interface | ||
| + | INT1R = 0b00000101; | ||
| + | // Set up INT1 for negative edge triggering | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | **Table 7.1. Table 12-1 from the PIC32MX370 datasheet for the PPS Input Pin Selection for the PIC32MX370 Processor.** | ||
| + | ^ Peripheral Pin ^ [pin name]R SFR ^ [pin name]R bits ^ [pin name]R Value to RPn Pin Selection | ||
| + | | INT1 | INT1R | INT1R< | ||
| + | | T3CK | T3CKR | T3CKR< | ||
| + | | IC1 | IC1R | IC1R< | ||
| + | | $\overline{(U3CTS)}$ | ||
| + | | U4RX | U4RXR | U4RXR< | ||
| + | | U5RX | U5RXR | U5RXR< | ||
| + | | $\overline{(SS2)}$ | ||
| + | | OCFA | OCFAR | OCFAR< | ||
| + | |||
| + | - This selection is not available on 64-pin USB devices. | ||
| + | - This selection is only available on 100-pin General Purpose devices. | ||
| + | - This selection is not available on 64-pin USB and General Purpose devices. | ||
| + | - This selection is not available when USBID functionality is used. | ||
| + | |||
| + | When the interrupt occurs, the value of the core timer operating at 40 MHz is captured. The previous core timer value is subtracted from the present core timer value to determine the period between interrupts. If this period is approximately 560 μs, a 38 kHz signal is present. The actual IR pulse length is of little concern provided it is sufficiently long to generate a processor interrupt. For our characterization case, the actual measured IR beam pulse width is 2.377 μs. | ||
| + | |||
| + | Listing 7.2 shows the C code implementing the INT1 ISR. The time between interrupts contains the needed information, | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Listing 7.2. INT1 ISR ==== | ||
| + | < | ||
| + | void __ISR(_EXTERNAL_1_VECTOR, | ||
| + | { | ||
| + | unsigned long t1_1; // Current time of interrupt | ||
| + | static unsigned long t2_1; // Time of previous interrupt | ||
| + | unsigned long dt_1; // Time interval between edges | ||
| + | unsigned int bitCount = 0; // Number of decoded bits | ||
| + | static int start_timing = 0; // Time capture buffer has been initialized. | ||
| + | |||
| + | t1_1 = ReadCoreTimer(); | ||
| + | | ||
| + | { | ||
| + | t2_1 = t1_1; // Initialize previous time on reset. | ||
| + | | ||
| + | } | ||
| + | | ||
| + | { | ||
| + | dt_1 = t1_1 - t2_1; // Compute time interval | ||
| + | | ||
| + | t2_1 = t1_1; // Update time of last interrupt | ||
| + | } | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | The core timer increments at the rate of a count for each 1/ | ||
| + | |||
| + | **Table 7.2. Core timer count ranges.** | ||
| + | ^ Symbol | ||
| + | | Sync | 176400 | ||
| + | | ONE bit | 65660 | 68340 | | ||
| + | | Zero bit | 21952 | 22848 | | ||
| + | |||
| + | |||
| + | ==== 7.4. Encoding the NEC IrDA Protocol with the PIC32MX370 Processor ==== | ||
| + | In order to encode an IrDA for the NEC protocol, the 38 kHz modulated bit stream must be generated. I chose to generate the 38 kHz pulsed signal using the PWM output of the PIC32 processor. Table 7.3 is a copy from the PIC32MX370 data sheet showing the PPS mapping of OC5 to Port B bit 7, which is connected to the IR_TX signal line. Listing 7.3 is the code for the IrDA initialization. | ||
| + | |||
| + | **Table 7.3. PIC32MX370 PPS output mapping for bit 7 of Port B.** | ||
| + | ^ RPn Port Pin ^ RPnR SFR ^ RPnR bits ^ RPnR Value to Peripheral Selection | ||
| + | | RPD9 | RPD9R | RPD9R< | ||
| + | | RPG6 | RPG6R | RPG6R< | ||
| + | | RPB8 | RPB8R | RPB8R< | ||
| + | | RPB15 | RPB15R | ||
| + | | RPD4 | RPD4R | RPD4R< | ||
| + | | RPB0 | RPB0R | RPB0R< | ||
| + | | RPE3 | RPE3R | RPE3R< | ||
| + | | RPB7 | RPB7R | RPB7R< | ||
| + | | RPB2 | RPB2R | RPB2R< | ||
| + | | RPF12< | ||
| + | | RPD12< | ||
| + | | RPF8< | ||
| + | | RPC3< | ||
| + | | RPE9< | ||
| + | |||
| + | The 38 kHz carrier signal is generated by setting the Timer 2 counter register equal to the PBCLOCK divided by 38000. The PWM output is turned off by setting the OC5 reset time greater than the Timer 2 period. The 9% duty cycle 38 kHz signal is turned on by setting the OC5 reset time to the product of 0.09 times the Timer 2 period. Generating the NEC sync signal and encoding the one’s and zero’s is just a matter of turning the PWM on and off for the specific duration, as specified by Reference 3. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Listing 7.3. IrDA Initialization ==== | ||
| + | < | ||
| + | #define IRDA_38K_IDLE | ||
| + | #define IRDA_38K_ON | ||
| + | #define IRDA_38KHZ_PD | ||
| + | void irda_init(void) | ||
| + | { | ||
| + | int i; | ||
| + | // IrDA Power Down Control | ||
| + | | ||
| + | | ||
| + | |||
| + | // Set up IrDA TX interface | ||
| + | | ||
| + | RPB7R = 0b00001011; | ||
| + | // Enable OC5 for PWM operation | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | // Set up IrDA RX interface | ||
| + | INT1R = 0b00000101; | ||
| + | | ||
| + | // Set up INT1 for negative edge triggering | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 8. References ===== | ||
| + | - Remote Control, [[https:// | ||
| + | - Consumer IR, [[https:// | ||
| + | - Data Formats for IR Remote Control, [[http:// | ||
| + | - AN #157 Implementation of IR NEC Protocol, [[http:// | ||
| + | - Remote Control with IrDA® Transceivers, | ||
| + | - SB –Projects NEC Protocol, [[http:// | ||
| + | - PIC32MX330/ | ||
| + | - Understanding Sony IR remote codes, LIRC files, and the Arduino library, [[http:// | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | [[{}/ | ||
| + | [[{}/ | ||
| + | [[{}/ | ||
| + | [[{}/ | ||
| + | |||
| + | {{tag> | ||

