40KHz? Are you receiving me?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10

    Default 40KHz? Are you receiving me?

    Hi everyone,

    Has anyone used a PIC (coded with PicBasic Pro) to accurately receive a 40KHz infrared signal before? I'm not sure wether it is do-able or not, so I figured I'd ask you fine people to see if anyone's done it before and if so, what would the code be?

    Just to give more info on what I'm doing, the signal I'm trying to receive is as follows:

    3ms on
    6ms off
    3ms on
    2ms off
    1ms on
    2ms off
    1ms on
    2ms off
    1ms on
    2ms off
    1ms on
    2ms off
    1ms on
    2ms off
    1ms on
    2ms off
    1ms on

    So yeah, any help would be awesome. Thanks.
    Last edited by CumQuaT; - 28th September 2009 at 02:02.

  2. #2
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Here is a IR remote code I used way back for a Remote Robot using a Sony remote control.



    Hope it helps

    Code:
    define  LOADER_USED 1
    
    
    DEFINE  OSC 20
    start:
    	ADCON1 = 7 
        'angleVar VAR BYTE	' set up constants with the minimum and maximum pulsewidths
    	'SERVO1 CON 450
    	'SERVO2 CON 1000	' set up a constant with the time between pulses:
    	refreshPeriod CON 20
    	A  VAR BYTE	' set an initial pulsewidth:
    	'angleVar = minAngle
        TRISB = 0
        TRISA = %00000100
        P_VAL VAR WORD
        IR_DEV  VAR BYTE
        IR_BUT  VAR BYTE
        HEADER  VAR WORD
        BITCNT  VAR BYTE
        PACKET  VAR WORD
        DIRINF  VAR BYTE
        
        SEROUT2 PORTC.6,32,["START  " , 10,13]
    main:
    	GOSUB IRIN
        SELECT CASE IR_BUT
        CASE $10
        GOSUB LEFT
        CASE $11
        GOSUB RIGHT
        CASE $12
        GOSUB FWD
        
        CASE $13
        GOSUB RE
        
        CASE $14
        GOSUB ST
        
        CASE ELSE
        
        END SELECT
        
     
    GoTo main
    'Recieve a signel from a Sony remote control
    ' and return with a 7 bit button code
    ' IR_BUT and a 5 bit device code IR_DEV in the variable IR_DEV
    ' if no header then IR_DEV and IR_BUT hold 255
    
    IRIN:   IR_DEV = 255:IR_BUT = 255
            PULSIN PORTA.2,0,HEADER 'Measure header 
            IF HEADER < 1000 THEN RETURN
            IF HEADER > 1350 THEN RETURN ' VERIFY GOOD HEADER IF BAD RETURN
            FOR BITCNT = 0 TO 11
                PULSIN PORTA.2,0,P_VAL
                IF p_VAL >= 450 THEN
                    PACKET.0[BITCNT] = 1
                    ELSE
                    PACKET.0[BITCNT] = 0
                ENDIF
            NEXT
            'Split the 7 bit button code and the 5 bit device code
            IR_BUT = PACKET & %01111111
           
            IR_DEV = (PACKET>>7) & %00011111
            SEROUT2 PORTC.6,32,["BUTTON =", HEX IR_BUT, 10,13]
    RETURN
    
    
    FWD:
    FOR A = 1 TO 20
    	Low PORTB.7
    	Low PORTB.6
     ' pulse the pin
    	PulsOut PORTB.7, 450
    	PulsOut PORTB.6, 1000
     ' pause for as long as needed:
    	Pause refreshPeriod
    NEXT A
    
    RETURN
    
    RE:
    FOR A = 1 TO 20
    	Low PORTB.7
    	Low PORTB.6
     ' pulse the pin
    	PulsOut PORTB.7, 1000
    	PulsOut PORTB.6, 450
     ' pause for as long as needed:
    	Pause refreshPeriod
     NEXT A
    RETURN
    ST:
    Low PORTB.7
    Low PORTB.6
    'PAUSE 1000
    RETURN
    
    LEFT:
    FOR A = 1 TO 20
    	Low PORTB.7
    	Low PORTB.6
     ' pulse the pin
    	PulsOut PORTB.7, 1000
    	PulsOut PORTB.6, 1000
     ' pause for as long as needed:
    	Pause refreshPeriod
     NEXT A
    RETURN
    
    
    RIGHT:
    FOR A = 1 TO 20
    	Low PORTB.7
    	Low PORTB.6
     ' pulse the pin
    	PulsOut PORTB.7, 450
    	PulsOut PORTB.6, 450
     ' pause for as long as needed:
    	Pause refreshPeriod
     NEXT A
    RETURN

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    You should be able to use the PULSIN command to measure the length of the pulses, but we will need more info to give further help.

    I assume you have an IR receiver hooked up to one of your I/O pins?

    Is the IR signal coming from a remote control? If so, what is the remote for, and what brand is it? Do you know the encoding scheme its using?
    Last edited by Kamikaze47; - 28th September 2009 at 02:56.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  4. #4


    Did you find this post helpful? Yes | No

    Default

    ET phone home?

  5. #5
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    From the figures you have given, it looks like the modulation frequency might be 40 kHz; the actual data is slower. So, as long as your IR receiver module can handle 40 kHz, decoding the data (pulse widths and spaces), which is in milli seconds, should most certainly be within the scope of PBP.

    Depending on the range you expect, even a generic 36 - 38 kHz IR module should work fine at 40 kHz.

    Anand

  6. #6
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    Hi all,

    Thanks for the responses. Sorry it takes me so long to respond. I'm in Australia, so with the time differences all of your responses come in while I'm asleep.

    I'm using a 40KHz phototransistor to receive, yes, and interfacing it to a PIC16F628A oscillating at 4MHz.

    Thanks for the example code, DaveC3. It's not a remote control that I'm trying to read from, but I imagine it's a similar process across the board. I'll pick that code apart and see what I can come up with.

Similar Threads

  1. Receiving Packet Array In Usart
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 24th April 2007, 20:41
  2. Receiving Packet Array In Usart
    By crhomberg in forum Serial
    Replies: 1
    Last Post: - 18th April 2007, 22:31
  3. Receiving and Transmitting Serial data at the same time
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th April 2007, 22:00
  4. USART Stops Receiving Characters
    By breesy in forum Serial
    Replies: 7
    Last Post: - 26th November 2006, 03:50
  5. USB Receiving a Word
    By sean-h in forum USB
    Replies: 2
    Last Post: - 9th October 2005, 16:56

Members who have read this thread : 1

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