See the latest version in the documentation wiki.
The USB IR Toy raw IO mode samples and replays infrared waveforms. IRIO mode starts with a default 36kHz infrared transmit modulation frequency. The rate can be changed with the setup modulation command (0×02), followed by a byte that sets the pulse-width modulator match value (PR2), and a don’t care byte.
Odje asked how to change the modulation frequency to 38.4Khz. To do this we need to calculate the timer PR2 value that gives the closest frequency. The best online tool we’ve found is this PWM Calculator.
Setup the PWM calculator with the US IR Toy constants (the clock (fosc) is 48Mhz, duty cycle is always 50%, the prescaler is fixed at 4x). Enter you desired frequency in hz (38400), and click calculate. A table similar to this one will be generated.
Choose the closest frequency from the table, the closest match to 384000Hz is 38461.54Hz. The values won’t match exactly, but IR receivers usually work over a range of modulations, from roughly 20kHz to 60kHz. The USB IR Toy currently uses a fixed 4x prescaler, so choose a value with a 4x timer2 prescaler. Here, the closest value uses a 4x prescaler anyways. The USB IR Toy prescaler could be made adjustable in a future firmware if more flexibility is needed.
The value to send is PR2. for 38.4kHz the PR2 value is 0b01001101, or 77 (0x4D). The complete command to send to the IR Toy is 0x02 0x4d 0x00:
- 0x02 is the setup TX command
- 0x4d is the PR2 value from the table
- 0x00 is a don’t care byte (doesn’t matter)
Connect to the IR Toy virtual serial port with a terminal program that can send byte values, we like Hercules and realterm. Send the PWM setup command (0×02), the PR2 value, and a don’t car byte (0x00). New settings take effect immediately. Here is where the settings are processed in the code.