Skip to content

IR Modulation

lucullusTheOnly edited this page Jan 14, 2018 · 2 revisions

Here I will describe the used IR modulation protocol.

Since I've already used the IR receiver chip TSOP4838, I also used them in this project. They react upon a modulation frequency of 38kHz (which is denoted in the name by the last two digits). So if you turn the IR-LED on and off with this frequency, the receiver will put his output pin to low. If it doesn't detect such a modulation, it put the output on high level. The Arduino Nano has to meet this frequency. This is reached with a simple pulse function, which turns the IR-LED on and off with a specified time delay in between.

To transmit information over IR we need to define a protocol, which says how the informations are represented. For simpler drawing I'm showing the inverted output signal of the receiver chip (so the HIGH level parts in the image are actually LOW level parts at the receiver output). The transmission starts with a start pulse, which is 800µs long. Then a pause of 700µs follows. After that two bytes of information are transmitted: a pulse duration of 500µs denotes a '0' and a pulse duration of 200µs denotes a '1'. The ATTiny detects these with the pulseIn() function. Since reality doesn't give you such exact values, the duration can be 100µs shorter or longer than the expected value. This is an experimental value and can be adjusted if necessary. Every pulse is followed by the 700µs long pause. Note: The duration of the pulses can be varied, so these values are only the default values.

The two bytes are divided in different fields depending on the first bit, which determines, if the IR signal was game signal (for example from a player base or other peripheries) - denoted by a '1' - or a shot from a tagger or other combat system - denoted by a '0'. For a shot we have the following information coded in the IR signal: The Team ID has two bits, confining the number of teams in a game to maximal 4. I considered this sufficient for most cases. The shot damage has 4 bits, so that you have to map the damage values, you need, to this 16 values. The PlayerID got 5 bits, so the maximum player number is confined to 32 per team. You can also reserve PlayerIDs for special behavior, for example an environmental damage. The WeaponID has two bits, giving the maximum weapon number of 4. You can define different weapon types, for example a simple gun, a one-hit-kill gun or a healing gun, so that you can help your teammates.

For a game command (first bit in IR data is '1') the two bytes are divided like this:The command ID got 5 bit, so there are 32 possible commands. Some commands are predefined, but there are unused command IDs you can use for defining your on IR game commands. You can provide 8 bits of command data for each command. For some predefined commands these bits are used to send some required information for the specific command.

The two bytes have each one parity bit, which is used to detect errors in the received data. The code uses even parity, so that the parity bit is 1, when the byte contains an uneven number of 1s, and 0, when it contains an even number of 1s.

Clone this wiki locally