USB IR Toy: Calculate transmitter carrier frequency

in Infrared toy by Ian | 0 comments

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 0×02 0x4d 0×00:

  • 0×02 is the setup TX command
  • 0x4d is the PR2 value from the table
  • 0×00 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 (0×00). New settings take effect immediately. Here is where the settings are processed in the code.

This entry was posted in Infrared toy and tagged , , .

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.