Tutorial
Microcontroller 8051 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You can see the 14 bits of the RC-5 system above. The RED bits are level "ON", while Blue are "OFF". The first two bits, #1 and #2, are called ACG calibration. They are "ON" level, and serve to calibrate the IR Receivers Auto Gain Control. In the Philips remotes, the bit #3 is the CHECK bit, every time you press a key at the remote, even pressing repeatedly the same key, this bit flips state. This feature is interesting. Suppose you pressed number "1" at the remote (trying to select channel 15 at TV) and holding it for 2 seconds, then your other hand just blocks the InfraRed signal. The TV would receive two trains of pulses, generated by your hand breaking a long train in two. Other systems would understand transmission of two keys "1" selecting channel "11", but this do not happens in the Philips system. This bit flips state every time you press a key, so blocking the signal with your hand doesn't change this bit, so the TV will understand that still the same key pressed. To select channel "11" you should press key "1" really twice. The next 5 bits, #4 to #8,
are used for SYSTEM ADDRESS, or to identify which kind of device should
execute the COMMAND bits. For example, TV set uses ADDRESS ZERO.
Bit #8 is the Less Significant Bit.
The next 6 bits, #9 to #14, are used for COMMAND information to the device selected at the ADDRESS bits. Bit #14 is the LESS SIGNIFICANT BIT, and it is last transmitted. For example, STOP key uses
COMMAND #54 (36h in hexadecimal), bits #9, #10, #12 and #13 should be
ON, bits #11 and #14 should be OFF.
This system can
be automated if using the chips:
DECODING WITH A MICROCONTROLLER To receive this signal using a microcontroller, follows the timing from the figure 7 above. Note that the Infrared Receiver invert the bit signal, low level means bit ON. During inactivity (no Infrared present) the output of the Infrared receiver is UP (bit zero). You can connect the IR receiver output to any input port pin or interrupt pin of your microcontroller, and keep polling it or prepare the interrupt routine to trigger your reading after the first low level sensed. When you press a key at the remote, it transmits the train of pulses, and your microcontroller will receive bit #1 first. It will be sensed right after the middle of the bit when it changes from high to low level to means bit "1". This is the first time that your microcontroller will "see" the incoming IR signal. You don't need to decode those first two bits, not even the CHK bit (except if you want to control as the TV do and described above), so you can skip those 3 bits and start to receive the ADDRESS bits. To do that, you need to skip 2.75 bits time, and you will be exactly at the middle of the right level of the first ADDRESS bit to be read (non inverted level).
Figure 8 So, upon sensing the first low level, your software should wait 4.752 milliseconds and then start to read the next 11 bits spaced 1.728ms each. The first 5 bits are Address and the next 6 bits are Command, logic correct level, LOW = 0, HIGH = 1. To make sure your software is waiting the correct timing, you need to use a dual channel oscilloscope, and this procedure to adjust your software: At your bit reading routine use an available microcontroller port pin and generate a fast pulse UP and DOWN, then use one scope channel to display this pulse, and the other scope channel to show the incoming signal from the receiver. Press and hold key number ZERO at the remote, and sync the scope to show a complete wave form, don't worry with timing. The fast 11 pulses should always be in place of those RED down arrows at the figure 8 above. It means that the "bit reading" software routine will reading exactly in the middle of the correct bit level. Your software will need to have two timing delays, the first to wait 4.752ms and the second to wait 1.728ms. Adjust the timing loop from the 4.752ms until the first fast pulse happens exactly as indicated above. Then adjust the 1.728 ms timing delay in such way that the last fast pulse (#11) bit reading happens exactly at the middle of the low part of the last bit (#14). Check all other bits and fast pulses, they should be all matching ok. Small errors would be accepted since the reading would be happening in the middle of the bit, few errors for more or less is not a problem, but it is better to be the most possible in the middle of the low level of each bit. This is why you should adjust your 1.728ms timing routine looking at the last data bit and fast pulse, if they match somehow ok, all the other bits should be ok too. Remember that any other remote key will generate a different pattern and it can confuse you. Use always key number ZERO for this software calibration. Once you find the correct timing delays, you can replace the FAST pulse instructions with NOPS (check your chip instruction set to keep the same clock count wasted), or keep the fast pulse there just for fun, so you will be able to recheck it in case of problems. Reading the 11 bits is easy. Just shift them left into a 8 bits register and ignore the high order 2 bits #7 and #6 (AND 03Fh instruction), keep only the COMMAND last 6 bits... You will not want to decode the ADDRESS bits, are you? The TV remote control will always send Address Zero, you know that, right? Here few examples of the complete waveform (14 bits) at the Receiver Output:
Values at
the right are the command in hexadecimal
|
Lesson 1: Lesson 2: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||