AVR410 RC5 IR Remote Control Receiver.pdf

(120 KB) Pobierz
AVR410: RC5 IR Remote Control Receiver
8-bit
Microcontroller
Features
Low-cost
Compact Design, Only One External Component
Requires Only One Controller Pin, Any AVR Device Can be Used
Size-efficient Code
Application
Note
Introduction
Most audio and video systems are equipped with an infrared remote control. This
application note describes a receiver for the frequently used Philips/Sony RC5 coding
scheme.
Figure 1. RC5 Receiver
DATA
The RC5 code is a 14-bit word bi-phase coded signal (See Figure 2). The two first bits
are start bits, always having the value one. The next bit is a control bit or toggle bit,
which is inverted every time a button is pressed on the remote control transmitter. Five
system bits hold the system address so that only the right system responds to the
code. Usually, TV sets have the system address 0, VCRs the address 5 and so on.
The command sequence is six bits long, allowing up to 64 different commands per
address.
The bits are transmitted in bi-phase code (also known as Manchester code) as shown
in Figure 3. An example where the command 0x35 is sent to system 5 is shown in Fig-
ure 4.
Rev. 1473B–AVR–05/02
1
819685050.154.png 819685050.164.png 819685050.175.png 819685050.186.png 819685050.001.png 819685050.012.png 819685050.023.png 819685050.034.png 819685050.045.png 819685050.056.png 819685050.067.png 819685050.078.png 819685050.087.png 819685050.098.png 819685050.108.png 819685050.118.png 819685050.120.png 819685050.121.png 819685050.122.png 819685050.123.png 819685050.124.png 819685050.125.png 819685050.126.png 819685050.127.png 819685050.128.png 819685050.129.png 819685050.130.png 819685050.131.png 819685050.132.png 819685050.133.png 819685050.134.png 819685050.135.png 819685050.136.png 819685050.137.png 819685050.138.png 819685050.139.png 819685050.140.png 819685050.141.png 819685050.142.png 819685050.143.png 819685050.144.png 819685050.145.png
 
 
819685050.146.png
 
 
819685050.147.png 819685050.148.png 819685050.149.png 819685050.150.png 819685050.151.png 819685050.152.png 819685050.153.png 819685050.155.png 819685050.156.png 819685050.157.png 819685050.158.png 819685050.159.png 819685050.160.png
 
Figure 2. RC5 Frame Format
Figure 3. Bi-phase Coding
Figure 4. Example of Transmission
Timing
The bit length is approximately 1.8 ms. The code is repeated every 114 ms. To improve
noise rejection, the pulses are modulated at 36 kHz. The easiest way to receive these
pulses is to use an integrated IR-receiver/demodulator like the Siemens SFH 506-36.
This is a 3-pin device that receives the infra-red burst and gives out the demodulated bit
stream at the output pin. Note that the data is inverted compared to the transmitted data
(i.e., the data is idle high).
The Software
The assembly code found in AVR410.ASM contains the RC5 decode routine. In addi-
tion, it contains an example program which initializes the resources, decodes the RC5
data and outputs the received command on port B.
The Detect
Subroutine
When the detect subroutine is called, it first waits for the data line to be idle high for
more than 3.5 ms. Then, a start bit can be detected. The length of the low part of the first
start bit is measured. If no start bit is detected within 131 ms, or if the low pulse is longer
than 1.1 ms, the routine returns indicating no command received.
Figure 5. Synchronizing and Sampling of the Data
The measurement of the start bit is used to calculate two reference times, ref1 and ref2,
which are used when sampling the data line. The program uses the edge in the middle
of every bit to synchronize the timing. 3/4 bit length after this edge, the line is sampled.
This is in the middle of the first half of the next bit (see Figure 5). The state is stored and
the routine waits for the middle edge. Then, the timer is synchronized again and every-
thing is repeated for the following bits. If the synchronizing edge is not detected within
5/4 bit times from the previous synchronizing edge, this is detected as a fault and the
routine terminates.
When all the bits are received, the command and system address are stored in the
“command” and “system” registers. The control bit is stored in bit 6 of “command”.
AVR410
2
1473B–AVR–05/02
819685050.161.png 819685050.162.png 819685050.163.png 819685050.165.png 819685050.166.png 819685050.167.png 819685050.168.png 819685050.169.png 819685050.170.png 819685050.171.png 819685050.172.png 819685050.173.png 819685050.174.png 819685050.176.png 819685050.177.png 819685050.178.png 819685050.179.png 819685050.180.png 819685050.181.png 819685050.182.png 819685050.183.png 819685050.184.png 819685050.185.png 819685050.187.png 819685050.188.png 819685050.189.png 819685050.190.png 819685050.191.png 819685050.192.png 819685050.193.png 819685050.194.png 819685050.195.png 819685050.196.png 819685050.002.png 819685050.003.png 819685050.004.png 819685050.005.png 819685050.006.png 819685050.007.png 819685050.008.png 819685050.009.png 819685050.010.png 819685050.011.png 819685050.013.png 819685050.014.png 819685050.015.png 819685050.016.png 819685050.017.png 819685050.018.png 819685050.019.png 819685050.020.png 819685050.021.png 819685050.022.png 819685050.024.png 819685050.025.png 819685050.026.png 819685050.027.png 819685050.028.png 819685050.029.png 819685050.030.png 819685050.031.png 819685050.032.png 819685050.033.png 819685050.035.png 819685050.036.png 819685050.037.png 819685050.038.png 819685050.039.png 819685050.040.png 819685050.041.png 819685050.042.png 819685050.043.png 819685050.044.png 819685050.046.png 819685050.047.png 819685050.048.png 819685050.049.png 819685050.050.png 819685050.051.png 819685050.052.png 819685050.053.png 819685050.054.png 819685050.055.png 819685050.057.png 819685050.058.png 819685050.059.png 819685050.060.png 819685050.061.png 819685050.062.png 819685050.063.png 819685050.064.png 819685050.065.png 819685050.066.png 819685050.068.png 819685050.069.png 819685050.070.png 819685050.071.png 819685050.072.png 819685050.073.png 819685050.074.png 819685050.075.png 819685050.076.png 819685050.077.png 819685050.079.png 819685050.080.png 819685050.081.png
 
AVR410
Ta ble 1. “Decode” Subroutine Performance Figures
Parameter
Value
Code Size
72 words
Execution Cycles
Register Usage
Low Registers Used: 3
High Registers Used: 6
Global Registers: 6
Pointers Used: None
Ta ble 2. “Detect” Register Usage
Register
Internal
Output
R1
“inttemp”–Used by TIM0_OVF
R2
“ref1”–Holds Timing Information
R3
“ref2”–Holds Timing Information
R16
“temp”–Temporary Register
R17
“timerL”–Timing Register
R18
“timerH”–Timing Register
R19
“system”– The System Address
R20
“command”–The Received Command
R21
“bitcnt”–Counts the Bits Received
Timer/Counter0
Overflow Interrupt
Handler
The function of the timer interrupt is to generate a clock base for the timing required.
The routine increments the “timerL” Register every 64 µs, and the “timerH” every
16,384 ms.
Ta ble 3. “TIM0_OVF” Interrupt Handler Performance Figures
Parameter
Value
Code Size
7 words
Execution Cycles
6 + reti
Register Usage
Low Registers Used: 2
High Registers Used: 2
Global Registers: 0
Pointers Used: None
Ta ble 4. “TIM0_OVF” Register Usage
Register
Internal
Output
R0
“S”–Temporary Storage of Sreg
R1
“inttemp”–Used by TIM0_OVF
R17
“timerL”–Incremented every 64 µs
R18
“timerH”–Incremented every 16,384 ms
3
1473B–AVR–05/02
819685050.082.png 819685050.083.png 819685050.084.png
 
819685050.085.png 819685050.086.png 819685050.088.png 819685050.089.png 819685050.090.png 819685050.091.png 819685050.092.png 819685050.093.png 819685050.094.png 819685050.095.png 819685050.096.png 819685050.097.png 819685050.099.png 819685050.100.png 819685050.101.png 819685050.102.png 819685050.103.png
 
Example Program
The example program initializes the ports, sets up the timer and enables interrupts.
Then, the program enters an eternal loop, calling the detect routine. If the system
address is correct, the command is output on port B.
Ta ble 5. Overall Performance Figures
Parameter
Value
Code Size
79 words –“detect” and “TIM0_OVF
96 words – Complete Application Note
Register Usage
Low Registers: 4
High Registers: 6
Pointers: None
Interrupt Usage
Timer/Counter 0 Interrupt
Peripheral Usage
Timer/Counter
Port D, pin 2
Port B (example program only)
AVR410
4
1473B–AVR–05/02
819685050.104.png 819685050.105.png 819685050.106.png 819685050.107.png 819685050.109.png 819685050.110.png 819685050.111.png 819685050.112.png 819685050.113.png 819685050.114.png
 
AVR410
;***************************************************************************
;*APPLICATION NOTE FOR THE AVR FAMILY
;*
;* Number
: AVR410
;* File Name
:"rc5.asm"
;* Title
:RC5 IR Remote Control Decoder
;* Date
:97.08.15
;* Version
:1.0
;* Support telephone
:+47 72 88 43 88 (ATMEL Norway)
;* Support fax
:+47 72 88 43 99 (ATMEL Norway)
;* Target MCU
:AT90S1200
;*
;* DESCRIPTION
;* This Application note describes how to decode the frequently used
;* RC5 IR remote control protocol.
;*
;* The timing is adapted for 4 MHz crystal
;*
;***************************************************************************
.include "1200def.inc"
.device AT90S1200
.equ
INPUT
=2
;PD2
.equ
SYS_ADDR =0
;The system address
.def
S
=R0
; Storage for the Status Register
.def
inttemp
=R1
; Temporary variable for ISR
.def
ref1
=R2
.def
ref2
=R3
; Reference for timing
.def
temp
=R16
; Temporary variable
.def
timerL
=R17
; Timing variable updated every 14 us
.def
timerH
=R18
; Timing variable updated every 16 ms
.def
system
=R19
; Address data received
.def
command
=R20
; Command received
.def
bitcnt
=R21
; Counter
.cseg
.org 0
rjmp
reset
;********************************************************************
;* "TIM0_OVF" – Timer/counter overflow interrupt handler
;*
;* The overflow interrupt increments the "timerL" and "timerH"
;* every 64us and 16,384us.
;*
5
1473B–AVR–05/02
819685050.115.png 819685050.116.png 819685050.117.png
 
819685050.119.png
Zgłoś jeśli naruszono regulamin