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


Closed Thread
Results 1 to 17 of 17

Hybrid View

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

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

    I bought my wife a Roomba for Christmas. The one I got has one 'virtual wall' with it. The virtual wall allows you to place it inside a doorway, for example, and it emits an IR signal the the machine won't cross - you can stop it from going into the room. You can buy more of these virtual walls, but, of course, I would rather build one.

    In searching robotics forums, it would appear that the virtual wall is a 38Khz carrier, turned on and off at 1ms intervals.

    I'm just starting to experiment, so I may be WAY off here - but I just used an 18F2550 that I happen to have breadboarded, right now, and did the following:

    Code:
    HPWM 1, 254, 38000
    When I put the scope on it, I got 38KHz (a little over, actually) and a period of 26uS (38KHz is actually 26.3uS). So probably, that will be close enough to work - I can't imagine the receiver on the robot is too fussy, but I'll have to try it.

    Then, to get the 1mS on and off, I decided to just switch the pin from output to input and back again. Not sure why I have to use 500uS on one pause and 1000uS on the other pause, but the scope shows what I wanted for times. So I came up with:

    Code:
    MAIN:
    	HPWM 1, 254, 38000  
            pauseus 500
            TRISC.2 = 1
            pauseus 1000
            TRISC.2 = 0
    	GOTO MAIN
    And the attached picture is what the scope shows (not an expensive scope by ANY means). My question is after the image.

    Name:  IR1.JPG
Views: 1196
Size:  86.6 KB

    Any idea what that slope is as the port is switched from output to input? Any way to get rid of it? Or am I just on the wrong track here?

    Thanks

    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

  2. #2
    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

    Does it happen with x10 attenuation probes and setting on the scope?

    If the chip is doing nothing else, is it any better switching the whole port?
    Code:
    TRISC = $00
    TRISC = $FF

  3. #3
    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=Art;135608]Does it happen with x10 attenuation probes and setting on the scope?

    Yes. Here is the image:

    Name:  IR2.JPG
Views: 1074
Size:  74.7 KB

    I also had the thought that I did not have a decoupling capacitor on Vdd - no difference. I also tried hooking a regular LED up to the port as I only had the scope hooked up to the port before. No difference.

    I also realized that I did not have to keep turning the PWM on and off, all I had to do was the HPWM command once, and then change the port back and forth. No difference, but here is the code now.

    Code:
    HPWM 1, 254, 38000
    MAIN:
        pauseus 1000
        TRISC = $FF
        pauseus 1000
        TRISC = $0
        GOTO MAIN


    You'll notice, I tried switching the whole port - no joy. This is getting frustrating, any other ideas?

    *Update* I had the bright idea that, maybe, if I turned a MOSFET on and off with another port and used the MOSFET to switch the pwm signal on and off, it would get better. Not really, its about the same, but as the MOSFET turns off, that slope has the pwm signal messing it up. So its worse. Back to the way it was - I guess I'll have to try it. Of course, I can't try it until after Christmas......

    Thanks

    Andy
    Last edited by andywpg; - 29th November 2015 at 16:43.
    "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

  4. #4


    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

  5. #5
    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: 1036
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

  6. #6
    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.

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, 12:35
  2. 38Khz Modulator
    By Gord11 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th September 2011, 08:14
  3. Turn me on
    By AvionicsMaster1 in forum General
    Replies: 8
    Last Post: - 16th November 2010, 14:04
  4. turn-off lcd and turn-on again
    By mehmetOzdemir in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th September 2009, 12:57
  5. Generated square wave 19Khz and 38Khz
    By blinkstar88 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th August 2007, 16: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