Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
learn:courses:unit-5:start [2017/03/24 12:58] – [Listing 7.1. Initialization of INT1] Martha | learn:courses:unit-5:start [2021/10/13 15:17] (current) – Arthur Brown | ||
---|---|---|---|
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 ===== | ===== 1. Introduction ===== | ||
Line 18: | Line 21: | ||
===== 2. Objectives: ===== | ===== 2. Objectives: ===== | ||
- | | + | |
- | | + | |
- | | + | |
Line 26: | Line 29: | ||
===== 3. Basic Knowledge: ===== | ===== 3. Basic Knowledge: ===== | ||
- | | + | |
- | | + | |
- | | + | |
Line 36: | Line 39: | ||
===== 4. Unit Equipment List ===== | ===== 4. Unit Equipment List ===== | ||
==== 4.1. Hardware ==== | ==== 4.1. Hardware ==== | ||
- | | + | |
- | | + | |
- | | + | |
In addition, we suggest the following instruments: | In addition, we suggest the following instruments: | ||
- | | + | |
==== 4.2. Software ==== | ==== 4.2. Software ==== | ||
The following programs must be installed on your development work station: | The following programs must be installed on your development work station: | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
---- | ---- | ||
===== 5. Project Takeaways ===== | ===== 5. Project Takeaways ===== | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
Line 84: | Line 87: | ||
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:// | 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.1. RPM973-H11 block diagram.// | ||
- | {{ : | + | {{ : |
//Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.// | //Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.// | ||
Line 97: | Line 100: | ||
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 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.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 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.// | //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. | 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.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.// | //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:// | 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:// | ||
Line 171: | Line 178: | ||
- | ==== 6.3. UART Hardware ==== | + | ---- |
- | The Basys MX3 processor board uses an FTDI USB to serial adaptor that interfaces directly with the PIC32MX370 UART pins, as shown in Fig. A.1, with the physical location of the UART USB connector shown in Fig. A.2. The UART_RX and UART_TX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. The result of this wiring will be discussed below in the UART Software section. When the USB cable is connected to both the PC and J10 of the Basys MX3 processor board, the PC software will automatically enumerate the connection to a COMM port. To determine which COMM port is enumerated, you will need to click on the Windows Start icon in the lower left corner followed by clicking on “Device Manager” and then on “Ports (COM & LPT).” You will then see a listing as “USB Serial Port (COM##)” where “##” is the COMM number used when you open the terminal emulation application. | + | |
- | ==== 6.4. UART Software | + | ==== Listing 7.2. INT1 ISR ==== |
- | As stated above, the UART_TX and UART_RX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. Table 6.1 shows that port F, pin 13 is mapped to U4RX using the C program statement “U4RXR | + | < |
+ | void __ISR(_EXTERNAL_1_VECTOR, IPL2SOFT) ext_int1_isr(void) | ||
+ | { | ||
+ | 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 | ||
+ | static int start_timing | ||
- | **Table 6.1. PPS mapping of PIC32 port F pin 13 to UART 4 receive adapted from [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/ | + | t1_1 = ReadCoreTimer(); |
+ | | ||
+ | { | ||
+ | t2_1 = t1_1; // Initialize previous time on reset. | ||
+ | | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | dt_1 = t1_1 - t2_1; | ||
+ | | ||
+ | t2_1 = t1_1; // Update time of last interrupt | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | </code> | ||
- | ^ Peripheral Pin ^ [pin name]R SFR ^ [pin name]R bits ^ [pin names]R Value to RPn Pin Selection | + | |
- | | INT1 | INT1R | INTR< | + | ---- |
- | | T3CK | T3CKR | T3CKR< | + | |
- | | IC1 | IC1R | IC1R< | + | The core timer increments at the rate of a count for each 1/40,000,000 seconds or 0.0025 μs per count. Referring back to the NEC characterization figures, we find that the sync period should be reported 0.0045 seconds multiplied by 40,000,000 counts per second, or approximately 180000 core timer counts. When a ONE bit is encoded, the number of core timer counts since the last interrupt is (0.0025 – 0.00056) seconds multiplied by 40,000,000 counts per second, or approximately 67000 core timer counts. When a ZERO bit is encoded, the number of core timer counts since the last interrupt is (0.00112 – 0.00056) seconds multiplied by 40,000,000 counts per second, or approximately 22400 core timer counts. Since the accuracy of the crystals used to generate the IR pulses is unknown, 2% accuracy can be assumed and still allow for adequate discrimination between symbols. Table 7.2 lists the core timer count range for the NEC protocol symbols. |
- | | $\overline{(U3CTS)}$ | + | |
- | | U4RX | + | **Table 7.2. Core timer count ranges.** |
- | | U5RX | + | ^ Symbol |
- | | $\overline{(SS2)}$ | + | | Sync |
- | | OCFA | OCFAR | OCFAR< | + | | ONE bit | 65660 | 68340 | |
+ | | Zero bit | ||
- | **Table 6.2. PPS mapping of PIC32 port F pin 12 to UART 4 transmit adapted from [[http:// | + | ==== 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. | ||
- | ^ RPn Port Pin ^ RPnR SFR ^ RPnR bits ^ RPnR Value to Peripheral | + | **Table 7.3. PIC32MX370 PPS output mapping for bit 7 of Port B.** |
+ | ^ RPn Port Pin ^ RPnR SFR ^ RPnR bits ^ RPnR Value to Peripheral | ||
| RPD9 | RPD9R | RPD9R< | | RPD9 | RPD9R | RPD9R< | ||
| RPG6 | RPG6R | RPG6R< | | RPG6 | RPG6R | RPG6R< | ||
Line 208: | Line 238: | ||
| RPE9< | | RPE9< | ||
- | - This selection | + | The 38 kHz carrier signal |
- | - This selection is only available on 100-pin General Purpose devices. | + | |
- | - This selection is not available on 64-pin General Purpose devices. | + | |
- | - This selection is not available when USBID functionality is used. | + | |
- | + | ||
- | + | ||
- | The C language “printf” function will output text to UART 4 if the “mon_putc(char c)” function, as shown in Listing B.2, is added to the project. | + | |
- | + | ||
- | Listing B.3 and B.4 show the code for sending and receiving a single character. These functions are non-blocking, | + | |
- | + | ||
- | The primitive functions provided by the code in Listing B.1 through Listing B.4 provide the building blocks of asynchronous communications | + | |
- | + | ||
- | ---- | + | |
- | + | ||
- | ===== 7. Background Information ===== | + | |
- | See the general discussion concerning computer communications discussed in Unit 4 Part 1. | + | |
- | + | ||
- | ---- | + | |
- | + | ||
- | ===== 8. References ===== | + | |
- | - [[http:// | + | |
- | - “Using the USART in Asynchronous Mode”, [[http:// | + | |
- | - “Asynchronous Communications with the PICmicro® USART”, [[http:// | + | |
- | - [[http:// | + | |
- | - __Embedded Computing and Mechatronics with the PIC32 Microcontroller__, | + | |
- | - “PIC32MX330/ | + | |
- | - “Using the USART in Asynchronous Mode”, [[http:// | + | |
- | + | ||
- | + | ||
- | ---- | + | |
- | + | ||
- | ===== Appendix A: Unit 4 Part 2 Parts Configuration ===== | + | |
- | {{ : | + | |
- | //Figure A.1. PIC32 to FT232RQR IC schematic diagram.// | + | |
- | + | ||
- | {{ : | + | |
- | //Figure A.2. Unit 4 hardware and instrumentation configuration.// | + | |
---- | ---- | ||
- | ===== Appendix B: Lab 4a and 4b UART Functions ===== | + | ==== Listing |
- | ==== Listing | + | |
< | < | ||
- | void uart_init(unsigned int baud, int parity) | + | #define IRDA_38K_IDLE |
+ | #define IRDA_38K_ON | ||
+ | #define IRDA_38KHZ_PD | ||
+ | void irda_init(void) | ||
{ | { | ||
- | // The next two statements map the PPS IO pins to the UART 4 Tx and Rx | + | int i; |
- | RPF12R | + | // IrDA Power Down Control |
- | U4RXR = 0x09; | + | TRISGCLR |
- | + | LATGCLR | |
- | | + | |
- | UARTSetDataRate(UART4, GetPeripheralClock(), | + | // Set up IrDA TX interface |
- | // Note the need to specify the UART number twice in the following statement | + | PORTSetPinsDigitalOut(IOPORT_B, BIT_7); // IR_TX |
- | UARTEnable(UART4, UART_ENABLE_FLAGS(UART_ENABLE | UART4 | UART_RX | + | RPB7R = 0b00001011; |
- | | + | // Enable OC5 for PWM operation |
- | { | + | |
- | case NO_PARITY: | + | OpenOC5((OC_ON|OC_TIMER_MODE16|OC_TIMER2_SRC|OC_PWM_FAULT_PIN_DISABLE), |
- | | + | IRDA_38K_IDLE, |
- | UART_STOP_BITS_1); | + | |
- | break; | + | // Set up IrDA RX interface |
- | case ODD_PARITY: | + | INT1R = 0b00000101; |
- | UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS | UART_PARITY_ODD |\ | + | |
- | UART_STOP_BITS_1); | + | // Set up INT1 for negative edge triggering |
- | break; | + | |
- | case EVEN_PARITY: | + | IPC1bits.INT1IP = 2; // Set Interrupt 1 for priority level 2 |
- | UARTSetLineControl(UART4, | + | IPC1bits.INT1IS = 0; // Set Interrupt 1 for sub-priority level 0 |
- | UART_STOP_BITS_1); | + | INTCONbits.INT1EP = 0; // Set for falling edge |
- | break; | + | IFS0bits.INT1IF = 0; // Clear the INT1 interrupt flag |
- | } | + | IEC0bits.INT1IE = 1; // Enable INT1 |
- | printf(" | + | } |
</ | </ | ||
- | ==== Listing B.2. C code to allow the “printf” output to be redirected to UART 4 ==== | ||
- | < | ||
- | void _mon_putc(char c) | ||
- | { | ||
- | | ||
- | | ||
- | } /* End of _mon_putc */ | ||
- | </ | ||
- | ==== Listing B.3. C Code for Sending a Single Character to UART 4 ==== | + | ---- |
- | < | + | |
- | BOOL putcU4( int ch) | + | |
- | { | + | |
- | UART_DATA c; | + | |
- | BOOL done = FALSE; | + | |
- | | + | |
- | | + | |
- | { | + | |
- | | + | |
- | done = TRUE; | + | |
- | } | + | |
- | return done; | + | |
- | } /* End of putU4 */ | + | |
- | </ | + | |
- | ==== Listing B.4. C Code for Receiving a Single Character from UART 4 ==== | + | ===== 8. References |
- | < | + | - Remote Control, [[https://en.wikipedia.org/ |
- | BOOL getcU4( char *ch) | + | - Consumer IR, [[https://en.wikipedia.org/ |
- | { | + | - Data Formats for IR Remote Control, [[http:// |
- | UART_DATA c; | + | - AN #157 Implementation of IR NEC Protocol, [[http:// |
- | BOOL done = FALSE; | + | - Remote Control with IrDA® Transceivers, |
- | if(UARTReceivedDataIsAvailable(UART4)) /* wait for new char to arrive */ | + | - SB –Projects NEC Protocol, [[http://www.sbprojects.com/ |
- | { | + | - PIC32MX330/350/ |
- | c = UARTGetData(UART4); | + | - Understanding Sony IR remote codes, LIRC files, and the Arduino library, [[http:// |
- | *ch = (c.data8bit); | + | |
- | done = TRUE; /* Return new data available flag */ | + | |
- | } | + | |
- | | + | |
- | }/* End of getU4 */ | + | |
- | </code> | + | |
- | + | ||
- | ---- | + | |
- | ===== Appendix C: Common Definitions ===== | ||
- | - UART: A Universal Asynchronous Receiver/ | ||
- | - Communications Speed: BAUD is a unit used to measure the speed of signaling or data transfer, equal to the number of pulses or bits per second, or //baud rate//. | ||
- | - Data Rate: Typical data rates are multiples of 120 BAUD to 115.2 KB. | ||
- | - Stop Bits: Only one is necessary for the receiving device. The sending device has the option of sending one or two minimum stop bits. | ||
- | - Bus Idle: This is the nominal state of the data signal when no data is being transmitted. The idle condition is a logic level 1 (or high condition). The bus idle condition is an extension of stop bits; however, the period bus idle condition may be any time duration. | ||
- | - Parity: Used for single bit error detection. | ||
- | - None – no error checking | ||
- | - Even parity refers to a parity checking mode in asynchronous communication systems in which an extra bit, called a parity bit, is set to one if there is an odd number of one bits in a one-byte data item. | ||
- | - Odd parity refers to a parity checking mode in asynchronous communication systems in which an extra bit, called a parity bit, is set to one if there is an even number of one bits in a one-byte data item. | ||
- | - Information direction: | ||
- | - Simplex – communications is one direction only | ||
- | - Full-duplex – bi-directional simultaneous asynchronous communications | ||
- | - Half-duplex – bi-directional exclusive communications. Devices can send and receive, but not simultaneously. | ||
---- | ---- | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
{{tag> | {{tag> |