
Originally Posted by
Macgman2000
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
Thanks for the reply. Your code surely is good but I don't have 16F877A and neither I am advance enough to use PWM technique at this stage and also even if I think about doing it that way my 12F635 does not have this feature.
"Do you have an oscilloscope?" - No, don't have access to one either. But the LED flashing part of the code is from a trusted source so 40kHz should not be a problem.
Now, with the code I have attached, can you see any obvious mistakes in it?
I know I am using 38kHz receiver BUT transmitting at 40kHz. It is because firstly, I have seen and read that this combination still works if you don't have access to a 40kHz IR Module and secondly, I don't have any knowledge about Assembly so thanks to Bruce @ Rentron (link: http://www.rentron.com/PicBasic/IR_Chips.htm) where I could get this piece of assembly code and stick it in my code as a module and modify my code for 12F635 and send 16 bits instead of 13.
Last edited by financecatalyst; - 10th November 2009 at 23:54.
___________________
WHY things get boring when they work just fine?
Bookmarks