Before using TV Remote Control for controlling a device one must know on which protocol it is working.
I am having one Chinese TV with me and don't know on which protocol it is working. So here comes the use of Logic Analyzer, i checked the Output of TV Remote using TSOP1738.
Connected the TSOP1738 output to channel-0 of Logic Analyzer and capture the waveform on pressing Key-1, Key-2 and Key-3.
So here are the wave-forms.
So based on this information i figure out that this signal is using Extended-NEC protocol, which is very common, apart from this there are several other protocols used in TV remote such as Sony SIRC, Philips RC5 etc.
So first we will know something more about the NEC Protocol (though my remote has Extended NEC Protocol)
Features:
The picture above shows a typical pulse train of the NEC protocol. With this protocol the LSB is transmitted first. In this case Address $59 and Command $16 is transmitted. A message is started by a 9ms AGC burst, which was used to set the gain of the earlier IR receivers. This AGC burst is then followed by a 4.5ms space, which is then followed by the Address and Command. Address and Command are transmitted twice. The second time all bits are inverted and can be used for verification of the received message. The total transmission time is constant because every bit is repeated with its inverted length. If you're not interested in this reliability you can ignore the inverted values, or you can expand the Address and Command to 16 bits each.
If you see the waveform at the top of this page, you will find that the waveform is exactly opposite of this waveform, that is because i am using TSOP1738 and its output is low when their is a 38KHz burst and else it is high.
On Logic Analyzer the sequence for Keys are as follow: (This is Extended-NEC that's why no Address Inversion)
Key-1 = 00000000 11101111 10000000 01111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x01
Key-2 = 00000000 11101111 01000000 10111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x02
Key-2 = 00000000 11101111 11000000 00111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x03
A command is transmitted only once, even when the key on the remote control remains pressed. Every 110ms a repeat code is transmitted for as long as the key remains down. This repeat code is simply a 9ms AGC pulse followed by a 2.25ms space and a 560µs burst.
Extended NEC protocol
The NEC protocol is so widely used that soon all possible addresses were used up. By sacrificing the address redundancy the address range was extended from 256 possible values to approximately 65000 different values. This way the address range was extended from 8 bits to 16 bits without changing any other property of the protocol.
By extending the address range this way the total message time is no longer constant. It now depends on the total number of 1's and 0's in the message. If you want to keep the total message time constant you'll have to make sure the number 1's in the address field is 8 (it automatically means that the number of 0's is also 8). This will reduce the maximum number of different addresses to just about 13000.
The command redundancy is still preserved. Therefore each address can still handle 256 different commands.
Working
I am having one Chinese TV with me and don't know on which protocol it is working. So here comes the use of Logic Analyzer, i checked the Output of TV Remote using TSOP1738.
Connected the TSOP1738 output to channel-0 of Logic Analyzer and capture the waveform on pressing Key-1, Key-2 and Key-3.
So here are the wave-forms.
Key-1 Pressed on TV Remote |
Key-2 Pressed on TV Remote |
Key-3 Pressed on TV Remote |
So first we will know something more about the NEC Protocol (though my remote has Extended NEC Protocol)
Features:
- 8 bit address and 8 bit command length.
- Extended mode available, doubling the address size.
- Address and command are transmitted twice for reliability.
- Pulse distance modulation.
- Carrier frequency of 38kHz.
- Bit time of 1.125ms or 2.25ms.
Modulation
Modulation Scheme |
The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 560µs long 38kHz carrier burst (about 21 cycles). A logical "1" takes 2.25ms to transmit, while a logical "0" is only half of that, being 1.125ms.
Protocol
NEC Protocol |
If you see the waveform at the top of this page, you will find that the waveform is exactly opposite of this waveform, that is because i am using TSOP1738 and its output is low when their is a 38KHz burst and else it is high.
On Logic Analyzer the sequence for Keys are as follow: (This is Extended-NEC that's why no Address Inversion)
Key-1 = 00000000 11101111 10000000 01111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x01
Key-2 = 00000000 11101111 01000000 10111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x02
Key-2 = 00000000 11101111 11000000 00111111 as LSB is Transmitted first Address = 0xF700 and Command = 0x03
Burst Pulse for Repeat Mode |
NEC Sequence |
The NEC protocol is so widely used that soon all possible addresses were used up. By sacrificing the address redundancy the address range was extended from 256 possible values to approximately 65000 different values. This way the address range was extended from 8 bits to 16 bits without changing any other property of the protocol.
By extending the address range this way the total message time is no longer constant. It now depends on the total number of 1's and 0's in the message. If you want to keep the total message time constant you'll have to make sure the number 1's in the address field is 8 (it automatically means that the number of 0's is also 8). This will reduce the maximum number of different addresses to just about 13000.
The command redundancy is still preserved. Therefore each address can still handle 256 different commands.
Extended NEC Protocol |
Keep in mind that 256 address values of the extended protocol are invalid because they are in fact normal NEC protocol addresses. Whenever the low byte is the exact inverse of the high byte it is not a valid extended address.
So this is all about NEC Protocol, as i have to decode this protocol, that's why i need a micro-controller for that and i select PIC18F4550 (because i have PIC18F4550 development board with me and TSOP1738 is also there).
Here is the rough schematic diagram of the setup.
Schematic |
My TV Remote Controller and My PIC18F4550 Development Board
Hardware Setup |
Whenever a key is pressed on TV Remote Controller, TSOP1738 decodes it 38KHz burst and then the microcontroller decodes this signal coming from the remote. And if the signal is decoded properly then the Address and Command is displayed on the 16x2 LCD of the development board. If there is some problem in the command then 0xFF is displayed which means data not decoded properly and there is some problem.
TSOP1738 is connected to RB0 pin and my board has 8-LED's connected to PORTB of the microcontroller, so i can't use LED connected to RB0 pin and can use LED's connected to RB1 to RB7 pin. So if someone presses key-1 on the remote LED connected to RB1 pin glows, similarly on pressing key-2 on remote, LED connected to RB2 pin glows and so on, if someone press key-0 on remote, all LED's connected to PORTB will turn off.
NOTE: There is some problem with my board LED connected to RB5 that's why it doesn't glow when pressing Key-5 on remote, but if you see the video, data is displayed properly on 16x2 LCD.
This video illustrates the whole working of the project.
Download the project from GitHub Page.TSOP1738 is connected to RB0 pin and my board has 8-LED's connected to PORTB of the microcontroller, so i can't use LED connected to RB0 pin and can use LED's connected to RB1 to RB7 pin. So if someone presses key-1 on the remote LED connected to RB1 pin glows, similarly on pressing key-2 on remote, LED connected to RB2 pin glows and so on, if someone press key-0 on remote, all LED's connected to PORTB will turn off.
NOTE: There is some problem with my board LED connected to RB5 that's why it doesn't glow when pressing Key-5 on remote, but if you see the video, data is displayed properly on 16x2 LCD.
This video illustrates the whole working of the project.
Thanks for your words. :-)
ReplyDelete