Shop OBEX P1 Docs P2 Docs Learn Events
LED Frequency Modulation — Parallax Forums

LED Frequency Modulation

IG3D MediaIG3D Media Posts: 24
edited 2005-02-02 14:54 in General Discussion
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

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-28 04:49
    38 kHz

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • BeanBean Posts: 8,129
    edited 2005-01-28 12:03
    Use an interrupt routine with a variable used on the RETURNINT command. Set the variable to change the frequency.
    Let me know if you need an example and I'll whip one up.
    Bean.
  • IG3D MediaIG3D Media Posts: 24
    edited 2005-01-28 13:35
    Just to clerify... I am using straight assembly, no BASIC. I suppose I could compile a basic program and look at the generated assembly (which I might do later today when I have some more time)... could you give me an example of changing the frequency (in either assembly or BASIC)?

    If it helps write an example, here are some code snippits from my program:
    ; sets a variable for the pin that has the IR LED on it
    LED_IR equ rb.1
     
    ...
     
    ; Sets a mode constant
    PLP equ $0e
     
    ...
     
    ; Tells the chip to pull up pins rb.0 and rb.1
    mode PLP
    mov !rc, #%11111100
    
    

    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
  • BeanBean Posts: 8,129
    edited 2005-01-28 14:37
    You didn't say what clock frequency, so I assumed 4Mhz

    It's kinda messy because 38KHz is not an even multiple of 4 mhz.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-28 18:10
    Or:

    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.
  • BeanBean Posts: 8,129
    edited 2005-01-29 02:15
    There I go making thing more complecated then they need to be...
    Bean.
  • IG3D MediaIG3D Media Posts: 24
    edited 2005-01-29 21:51
    I'm actually running at a full 50 Mhz (the program does a lot of things other than just blinking the LED so I need the speed - and the clock I happen to have on hand is 50 Mhz).
    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
  • PJMontyPJMonty Posts: 983
    edited 2005-01-30 00:09
    Andrew,

    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.
    • The CPU is runing at 50 Mhz, which is the same as saying 50 million cycles per second.
    • You want to blink something at 38 khz, which is the same as saying 38 thousand cycles per second.
    • 1 second / 50 million cycles = .00000002 seconds per cycle
    • 1 second / 38 thousand cycles = .000026315 seconds per cycle
    • .000026315 seconds / .00000002 seconds = 1315.789474 CPU cycles

    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
  • BeanBean Posts: 8,129
    edited 2005-01-30 02:30
    Yeah I think you should convert the whole program to SX/B... Just kidding, but I am a BIG fan of SX/B.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-31 18:30
    You can start with the SX/B template file, add a single FREQOUT Mypin, 38000, 1 command, and then look at the generated assembly.

    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.
  • IG3D MediaIG3D Media Posts: 24
    edited 2005-02-01 16:41
    allanlane5 said...
    You can start with the SX/B template file, add a single FREQOUT Mypin, 38000, 1 command, and then look at the generated assembly.

    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 looked at the generated assembly and it is overly complicated especialy since it adds constant in there that are unecessary for my use (__PARAM1, __PARAM2, etc).

    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-02-02 13:57
    The logic is correct. The number of cycles depends on your clock, so that may or may not be correct, but that's the way to go about it.
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-02-02 14:54
    At 50 MHz clock, 657 cycles are equivalent to 13.14 µs times 2 = 26.28 µs which is equivalent to 38.052 kHz - IOW, this is a hit.

    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:

    ISR
        decsz  Timer
           jmp  ISROut
         mov   Timer, #7
         [noparse][[/noparse]toggle LED here]
    ISROut
        mov    w, #-94
        retiw
    
    



    @ 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
Sign In or Register to comment.