LED Frequency Modulation
IG3D Media
Posts: 24
I am trying to create something that is somewhat like a universal remote (it has to communicate with two devices that have different Infrared frequencies).
I am wondering how (in code or with chips) I can get my infrared emitting LED to opperate at a specific frequency. Do I have to turn the LED on and off very quickly in code or is there a more reliable way?
Also, what frequency does the Infrared Receiver·sold in the Parallax online store opperate at? The datasheet lists frequencies but the webpage does not list which part number from the data sheet Parallax is actually selling.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Curioso
IG3D Media
I am wondering how (in code or with chips) I can get my infrared emitting LED to opperate at a specific frequency. Do I have to turn the LED on and off very quickly in code or is there a more reliable way?
Also, what frequency does the Infrared Receiver·sold in the Parallax online store opperate at? The datasheet lists frequencies but the webpage does not list which part number from the data sheet Parallax is actually selling.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Curioso
IG3D Media
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Let me know if you need an example and I'll whip one up.
Bean.
If it helps write an example, here are some code snippits from my program:
I also have the books "Programming the SX Microcontroller: A Complete Guide" and "Beginning Assembly Language for the SX Microcontroller" is anyone would rather refference page numbers in either of those books rather than write an example.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Curioso
IG3D Media
It's kinda messy because 38KHz is not an even multiple of 4 mhz.
FREQOUT MyPin, 38000, 1 ' To output a 38,000 hz burst for 1 mSec.
And yes, what you are doing is turning your IR-LED on and off very quickly,
at a 38,000 hz rate.
Bean.
The code needs to be able to generate an arbitrary frequency so it would be nice to have an assembly version of FREQOUT. I am almost tempted to rewrite my entire program in BASIC just so I can use that one function. The assembly translation of the basic program will take me a while to be able to interpret because I don't have experience looking at the translated basic code yet. I can always write the aeembly code from scratch if all it is, is blinking it on and off.
I have a question though, if I am going to do that...
At 50 Mhz how many program cycles should I take to blink the light on and off once if I'm looking for (for example) a 38 Mhz signal?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Curioso
IG3D Media
This is a pretty straight forward problem to solve. Let's look at the steps involved in doing so. BTW, it's 38 khz, not 38 Mhz.
Now, there is one little trick involved. You want the LED to turn on and off 38,000 times a second. The number of CPU cycles expressed as an integer (1316) is the number of 50 MHz CPU cycles needed to accmulate 1/38,000 of a second. Since you need to turn it both on and off in that time, you divide the number of cycles in half (1316 / 2 = 658) and turn the LED on for 658 cycles, and off for 658 cycles. That will give you an LED that pulses at 38 khz.
Thanks, PeterM
And I assume you mean with a 50 Mhz clock you want to generate a 38 Khz (Kilo, not Mega) signal. There's 3 factors of 10 difference there between 38 Mhz and 38 Khz. And the decoder wants Khz, anyway.
I think PJMony did a good job at answering my question. If I am following correctly, then my program flow should go like this:
Turn LED on (clear output bit)
eat·657 cycles
Turn LED off (clear output bit)
eat 657 cycles
Giving me 0.00002632 seconds of a 38 Khz signal. Does that seam correct to everyone?
Again, thank you all for your help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Curioso
IG3D Media
When you do this modulation part in the mainline program, keep in mind that any interrupts will "steal" cycles causing that the created signal will have a yitter, depending on how often the ISR is called, and how many instruction cycles it takes.
Therefore, I would let the ISR do the timing:
@ 50 MHz, the ISR is called every 1.88 µs at RTCC rollover with no prescaler - this multiplied by 7 results in 13.16 µs which is equivalent to 37.994 kHz.
This is just one possible combination of the interrupt period and the timer initialization. I'm sure, you can find many others.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
Post Edited (Guenther Daubach) : 2/2/2005 2:59:29 PM GMT