Trying to build an IR project


Results 1 to 14 of 14

Threaded View

  1. #12


    Did you find this post helpful? Yes | No

    Default

    Do you have an oscilloscope? You have to look at the 38kHz coming out of the TX pin at the pic. You should have 13us high pulse then a 13us low pulse for a period of 26us.

    Once you verify the above is happening correctly, then add the code that encodes a "1" bit and a "0" bit. Also IR RX modules do NOT want an IR DC carrier, in other words if you don't modulate at 38Khz with a data burst, shut off the IR LED. So between data transmissions (1 byte or 2 bytes..etc) send data then shut off the IR LED. I have seen many people get stuck on this nasty little characteristic of these devices and waste a lot of time debugging. If you do not the internal capacitive coupled amplifier stages and demodulation stage will charge up with a dc voltage. Within a 1sec to 2 saturate with no more data being demodulated. This is a bad thing.

    Make sure that you format your data output based on your transmission speed. If you choose 1200bps then set the bit width (on/off duration) to this spec and don't forget 1 start bit and 1 stop bit for the Debug command at the receiver. It is easy to get caught up in the code and hardware and want to throw all together in one shot. This does not happen until you have done 1or 2 IR projects and discover the pitfalls. My advise, test in pieces.

    Below is old TX code using hardware PWM for 16F877A to test IR modules...At the receive side I used Debugin with no other special consideration since the RX module gives me data out. The pause 5 statements need to be tweaked based on your IR module, this delay maybe too short and lead to saturation. I tested this at 40ft no problem very forgiving with the module I used.



    INCLUDE "Modedefs.Bas"
    @ device HS_OSC, LVP_OFF, WDT_OFF
    ; @ Device pic16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF


    DEFINE OSC 20



    DEFINE DEBUG_REG PORTC ' point to portB for output
    DEFINE DEBUG_BAUD 1200 ' set software TX to 1200 bps
    DEFINE DEBUG_BIT 7 ' Set Debug pin bit
    DEFINE DEBUG_MODE 0 ' Set Debug mode: 0 = true, 1 = inverted




    CCPR1L = 64 ' Set PWM Duty-Cycle to 50%
    CCPR2L = 64
    PR2 = 128 ' Set PWM for 38.7KHz
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100
    T2CON = %00000100 ' %00000100 = TMR2 ON 1:1 pre-scale
    ' %00000101 = TMR2 ON 1:4 pre-scale
    ' %00000110 = TMR2 ON 1:16 pre-scale



    ;set ports to output
    TRISA = %00000000
    TRISB = %00001111
    TRISC = %00000000
    TRISD = %00000000

    ; analog portA direction
    ADCON1 = 7
    CMCON = 7

    portc.7=1 ; used to reverse bias LED to shut it off when direct driven (no transistor)


    main:


    if portb.1 = 0 then
    debug 255, 50 ; left
    pause 5
    portc.7 = 1 ; used to reverse bias LED to shut it off when direct driven (no transistor)
    goto main
    endif

    if portb.2 =0 then
    debug 255, 10 ; right
    pause 5
    portc.7 =1
    goto main
    endif

    if portb.3 = 0 then ; straight
    debug 255, 100
    pause 5
    portc.7 = 1
    goto main
    endif

    ; The stop command is sent two times per loop to make sure the RX shuts off

    debug 255, 0 ; stop
    portc.7 = 1

    pause 30


    debug 255, 0 ; stop
    portc.7 = 1

    goto main
    Last edited by Macgman2000; - 10th November 2009 at 23:22.

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  3. Plz help in completing RC-5 IR remote lamp dimmer project
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2008, 08:44
  4. PIC10F200 Automated IR Light Switch
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 3rd May 2007, 11:40
  5. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12

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