Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
BSA2-MC Project Guidelines
– IR task Introduction Remote controls for consumer electronics have been available since around 1950.
Although the first models were either wired or used other transmission methods
, Infrared light transmission has long been used. This process offers many advantages:
Inexpensive construction Low standby power consumption in the remote control
Robust data transmission through modulation However, due to the advancing standardization and the technology itself,
there are also disadvantages: Practically always unidirectional data connection No authentication possible
Overlapping commands from different manufacturers In summary, it can be said that infrared-based remote
controls are very widespread, but are also increasingly being supplemented /
replaced by other technologies (Bluetooth Low Energy, other 2.4 GHz radio solutions). Infrared –
Technical Details Like all protocols, this can also be divided into various layers.
Due to the really simple structure (only unidirectional, no correct addressing, etc.) only 3 levels can be specified here:
2 Carrier Frequency / Modulation In order to generate a clearly recognizable signal (on the receiver side),
the infrared LED is switched off & on with a certain clock frequency (the so-called carrier frequency).
This is a simple PWM signal with a duty cycle of 50%: Tip: the period of ~ 26µs for 38kHz corresponds
to the time between 2 rising edges! To illustrate: the time between 2 edges corresponds to approx. 208 CPU cycles
at 16MHz. In principle, 38kHz has become the standard carrier frequency, but there are some manufacturers
who use frequencies close to 38kHz (30-40kHz). These frequencies are compatible with each other,
but a loss of range / sensitivity occurs if the frequency is different. In the receiving unit (see chapter TSOP),
other light waves (e.g. lighting or sunlight) are separated from the signal by an optical bandpass.
In order to be able to differentiate existing light waves in the infrared range from our useful signal, the electrical signal (received by the PIN diode) is filtered through another bandpass. This lets signals through in the desired frequency range (and with a certain deviation). Coding In order to be able to transmit a desired command, different types of coding are used (comparable: baud rate and frame format on UART): Pulse Distance Biphase (Manchester) 3 -5 0 5 10 15 20 25 30 35 40 45 Signalverlauf 38kHz LED led Zeit [µs] LE D Pulse Width Pulse Position Pulse Distance Width In the case of the universal remote control project, the coding should already be able to be processed universally, so the coding is not relevant for the project. Tip: The following values can be expected from our remote controls: Start Bit: 9000µs Pulse 4500µs Pause 0-Bit: 560µs Pulse 560µs Pause 1-Bit: 560µs Pulse 1690µs Pause Stop Bit: 560µs Pulse To illustrate: 560µs corresponds to 8960 cycles @ 16Mhz, 9000µs is already 144000 cycles. Protocol The used protocol is not relevant for this project. TSOP – IC The components of the TSOP series from Vishay are highly integrated receivers for infrared commands for a wide range of infrared carrier frequencies and modulations / protocols. The signal from the TSOP is already available in digital form and does not have to be preprocessed in analog form. 4 The signal processing takes place in this sequence: 1. All light waves with 950nm are received in the PIN diode and converted into a signal depending on the amplitude / intensity of the light waves 2. The AGC (Automatic Gain Control) unit amplifies this signal depending on the current background noise and other external influencing factors. 3. In the bandpass only the desired carrier frequency is allowed to pass (including attenuated components of other frequencies, the more different the frequency, the lower the component). 4. In the demodulator, the carrier frequency is removed and a digital signal, which corresponds to pulse / pause, is converted. Due to this internal structure, unwanted signals can be filtered very well by the TSOP. Tip: If the IR LED lights up continuously or is continuously modulated at 38kHz, the TSOP will output the quiescent high signal (since the TSOP sees an "undesired" signal). Signal example of an IR command (TSOP pin) Please note: this is an example. The universal remote control in this project must also be able to record other signals! 5 IR LED + MOSFET In the previous circuits, LEDs were operated with a relatively low current (less than 20mA), since their function was exclusively signaling. In this case, a long path must be bridged with the infrared diode, the luminosity must be above the background noise (ambient light in the infrared range) and reception should also work without a direct line of sight. To achieve this, a TSAL6200 LED is used in this project, which can be operated with a continuous forward current of 100mA (cf. typically 0.5-10mA for signal LEDs). As a reminder: one port pin of the AVR can deliver a MAXIMUM 40mA (see "DC Current per I / O Pin" in the data sheet). Typically 20mA per pin is used to increase the service life of the microcontroller. This current amplification is done in this project by a simple N-channel MOSFET circuit: The resistor R1 is calculated from the desired current and the remaining voltage at the resistor: The voltage across the MOSFET can be neglected. The forward voltage of the LED can be taken from the data sheet (Forward Voltage) and is specified as 1.35V typ. @ 100mA. In order to enable a longer range, this IR LED can also be operated with higher current for a short time. The so-called surge forward current is the maximum current pulse, in our case 1.5A. The 38kHz modulation with 50% duty cycle allows the current to be doubled to 200mA if the LED remains switched on permanently in the modulation. In our case, however, only short pulses are 6 sent. To do this, we reduce the resistance to 12Ω and thus enable a forward current of the order of 280mA (the forward voltage increases with higher current). Tip: To test the function of the program, a "normal" LED without MOSFET should be used before this circuit. This ensures that the LED is reliably switched off after a short time. Please note: in order to simulate the same active level of the port pin, the LED must be connected between the port pin and GND (0: LED off, 1: LED on). Suggestion – Timer Configuration Both recording and playback of infrared signals must be done with timers. The following 2 tasks must be carried out: Generating the 38kHz signal for modulation (playback only) Measurement of the time intervals between the edges of the TSOP signal (recording) and the exact reproduction of these intervals by switching the 38kHz timer off and on (playback) The length of the individual signals practically dictates the use of the timer units: 38kHz signal: short time intervals (208 cycles with prescaler 1): 8-bit Timer 0 or 2 Signal edges: highly variable time intervals, up to 144,000 cycles: 16-bit Timer 1 with prescaler 64 Timer 0/2 All timer units offer special modes for generating PWM signals. The exact description can be found in the data sheet (Modes of Operation). There are different approaches for generating a 38kHz signal with 50% duty cycle, we recommend the following: Mode of Operation: Clear Timer on Compare (CTC) Waveform generation mode: toggle OC0A / OC2A on compare The corresponding value must then be loaded into OCR0A / OCR2A so that the output is toggled at 76kHz. Prescaler: 1 In this setting, no ISR is necessary, the entire pin switching on / off is done by the hardware. 7 In general, there are many ways to achieve your goal, so you can use your own approaches. A timer MUST be used! Tipp: Please simply use the search function of the PDF reader if you are looking for certain register names and functions. Important sections in the datasheet: Waveform Generation Mode Bit Description Compare Output Mode / Output Compare Unit Modes of Operation Compare Match Output Unit Timer 1 Due to the 16-bit wide counting register, timer 1 is more suitable for measuring longer periods of time, whereby these can also be recorded with a higher resolution.
Due to the large difference between the pulse / pause duration and the most universal reception possible,
the duration between the individual edges of the TSOP block must be measured precisely.
The measurement of the edge distances can also be solved in many different ways, we recommend the following method:
Input Capture Unit Timer 1 offers a so-called input capture unit, which saves the current TCNT1 value in its
own register by means of a signal on a certain pin (ICP1) and then triggers its own interrupt. Prescaler:
64 8 Process - record IR sequence This flowchart is only a suggestion! The specific implementation is not
discussed in these diagrams. 9 Process - reproduce the IR signal This sequence diagram is only a suggestion! 10 Q&A
How do I find the correct name for the ISR ()? All possible interrupt sources are listed in the Interrupt Vectors table
in the data sheet. The "Source" column must be selected for the corresponding name and _vect must be appended
(e.g. TIMER1 OVF → TIMER1_OVF_vect). How do I find out whether an interrupt is triggered at all?
The easiest way is to connect an LED to a pin and set the corresponding bit in the ISR. UART output is also possible,
but in our case the timer ISR is called too fast. How do I find the right register?
There is a separate chapter for each unit of the AVR; there, in turn, the last chapter is always the Description tab.
Register and bit names can be found there, as well as descriptions.