38Khz IR carrier - best way to turn it on and off


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    If you look in the manual under HPWM. You can see that pbp HPWM is only 8bits.
    In your code you have the duty set at 254, which is nearly 100%. I think you would want to set
    the duty to 50% or 127.

    untested
    Code:
    TRISC.2 = 0
    MAIN:
    	HPWM 1,127, 38000 ' duty cycle 50% 
                  pauseus 1000
                  HPWM 1, 0, 38000 ' duty cycle 0
                  pauseus 1000
    
    	GOTO MAIN

  2. #2
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Quote Originally Posted by mark_s View Post
    If you look in the manual under HPWM. You can see that pbp HPWM is only 8bits.
    In your code you have the duty set at 254, which is nearly 100%. I think you would want to set
    the duty to 50% or 127.
    Wow! You are SO right - looks MUCH better now. Thanks!

    Name:  IR3.JPG
Views: 1205
Size:  83.7 KB

    Still has that slope on it though. I might try DT's Instant Interrupts and use a pin on and off to get it. Here's what the code is now:

    Code:
    HPWM 1, 127, 38000
    MAIN:
            pauseus 1000
            trisc.2 = 1
            pauseus 1000
            trisc.2 = 0
    	GOTO MAIN
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Have you tried turning it off and on again?
    Code:
    MAIN:
    	HPWM 1, 127, 38000
            pauseus 1000
    	HPWM 1, 0, 38000
            pauseus 1000
    	GOTO MAIN
    Strictly speaking of course, the HPWM takes some instructions so the loop takes longer than 2ms to execute,
    but you could make your own time wasting routine for accurate delay, so that shouldn’t be a problem.
    I mentioned that since I noticed you had more accurate timing before using HPWM only once.
    But you have a scope, you don’t even have to do the math to calculate a time waste routine.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,720


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Frequency
    is the desired frequency of the PWM signal. On devices with 2
    channels, the
    Frequency must be the same on both channels. Not all frequencies
    are available at all oscillator settings. For the non-long versions of PBP (PBP and
    PBPW), the highest frequency at any oscillator speed is 32767Hz. The lowest
    usable HPWM
    Frequency at each oscillator setting is shown in the following table.
    quote from the pbp3 manual

    did you actually check the resulting freq, it can be done manually of course

    would a pull down resistor (say 1k) make the trace look better

  5. #5
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Hi,

    Here's what had worked for me. Richard is right, you cant use HPWM for frequencies above 32.768khz.

    Set the registers as follows.

    TRISC.2 = 0 ' CCP1 (PortC.2 = Output)
    PR2 = 25 ' Set PWM Period for approximately 38KHz
    CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
    CCP1CON = %00001100 ' Mode select = PWM
    T2CON = %00000100 ' Timer2 ON + 1:1 prescale

    This would give you a continuous 38khz on the pwm pin, at 50% duty cycle.

    Now, toggle TRISC.2 between an input and an output at 1ms.

    Hope it works! If it does, thanks go to Bruce Reynolds. If doesnt, brickbats to me!

    Regards.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,720


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    that would be for fosc=4
    for my money I'd say :
    CCPR1L = 52 ' Set PWM Duty-Cycle to 50%
    {mister_e pic multi-calc}

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    As Ardhuru said, credit to Bruce Reynolds for publishing some great projects.

    Maybe you can gets some ideas here.
    http://wayback.archive.org/web/20120...com/remote.htm

  8. #8
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Quote Originally Posted by ardhuru View Post
    Hi,

    Here's what had worked for me. Richard is right, you cant use HPWM for frequencies above 32.768khz.
    From what I understand of what was quoted, 32768Hz was maximum WITHOUT using longs. I'm using an 18F2550, and when I compile, I get the following message:

    '[MESSAGE]pic18f2550.pbpinc(285): LONG Variables enabled (PBPL used)'

    It seems like it used longs because of the frequency I specified, and it seemed happy. Anyway, the problem is solved, see my last post.

    Thanks for the help!
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  9. #9
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off - SOLVED

    Thanks Everyone!

    It worked!

    The answer was a pull down resistor. It got rid of that slope. I tried a few, and worked out that 4.7K was the highest value I could use. That gave me a final voltage about 4.2V which should be fine.

    Then I had to play with the frequency I specified to get exactly 38 pulses in 1mS. Even though the scope's measurement function still reports it as 38.46KHz - I told you it was a cheap scope!

    Here are two images of what I have now.

    Thanks again!

    Andy

    Attachment 8114

    Name:  IR5.JPG
Views: 1206
Size:  78.3 KB
    Attached Images Attached Images  
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  10. #10
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Quote Originally Posted by richard View Post
    did you actually check the resulting freq, it can be done manually of course
    Well, the scope has measurement functions. Again, this is NOT an expensive scope ($75), but it was reporting 38.46KHz and 26uS period......both right in the ballpark of what I was looking for.

    Quote Originally Posted by richard View Post
    would a pull down resistor (say 1k) make the trace look better
    And that was the answer! See my last post for images.

    Thank you!!
    Last edited by andywpg; - 1st December 2015 at 01:54.
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  11. #11
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 38Khz IR carrier - best way to turn it on and off

    Quote Originally Posted by Art View Post
    Have you tried turning it off and on again?
    Code:
    MAIN:
    	HPWM 1, 127, 38000
            pauseus 1000
    	HPWM 1, 0, 38000
            pauseus 1000
    	GOTO MAIN
    Strictly speaking of course, the HPWM takes some instructions so the loop takes longer than 2ms to execute,
    but you could make your own time wasting routine for accurate delay, so that shouldn’t be a problem.
    I mentioned that since I noticed you had more accurate timing before using HPWM only once.
    But you have a scope, you don’t even have to do the math to calculate a time waste routine.
    Hmm, tried it, but I couldn't get the frequency up high enough due to the 'setup time' of HPWM. See below though.....got it looking great now.

    Thanks Art,

    Andy
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

Similar Threads

  1. How to setup 38kHz PWM with PIC18F1330
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 7th March 2015, 13:35
  2. 38Khz Modulator
    By Gord11 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th September 2011, 09:14
  3. Turn me on
    By AvionicsMaster1 in forum General
    Replies: 8
    Last Post: - 16th November 2010, 15:04
  4. turn-off lcd and turn-on again
    By mehmetOzdemir in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th September 2009, 13:57
  5. Generated square wave 19Khz and 38Khz
    By blinkstar88 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th August 2007, 17:40

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts