PDA

View Full Version : Wireless Comunication Dilemma



jhorsburgh
- 27th August 2008, 07:58
Hello Again,
I have another problem with wireless communication, this time with IR.
I am trying to setup stable IR communication between to PIC's but I cannot get it to work.
For the transmitter i am using the 16F628 because of its Hardware PWM and for the receiver i am using the 12F629 because i have a heap of them.

Below is the code for the PIC's, can anyone see anything wrong?

Reciever Code<code>
INCLUDE "modedefs.bas"

@ DEVICE PIC12f629, XT_OSC
@ DEVICE PIC12f629, WDT_OFF
@ DEVICE PIC12f629, PWRT_ON
@ DEVICE PIC12f629, MCLR_OFF
@ DEVICE PIC12f629, BOD_ON
@ DEVICE PIC12f629, CPD_OFF

Define OSC 4
CMCON = 7

RXPIN Var GPIO.1 'Input PIN
TXPIN VAR GPIO.2 'Output PIN
VALID VAR byte 'Valid Code
UTYPE VAR BYTE 'Unit Type
UID VAR BYTE 'Unit Identefier
VALID = 0
utype = 0
uid = 0

LOW 0

rx:
serin rxpin,n1200,[$66],VALID,UTYPE,UID
if VALID = 22 then hit
goto rx

hit:
high 0
pause 250
low 0
VALID = 0
goto rx

end
</code>

Transmitter Code<code>
INCLUDE "modedefs.bas"

@ DEVICE PIC16f628, XT_OSC
@ DEVICE PIC16f628, LVP_OFF
@ DEVICE PIC16f628, WDT_OFF
@ DEVICE PIC16f628, MCLR_OFF

DEFINE OSC 4 ' We're using a 4MHz oscillator
TXPIN Var PortB.1 ' Output PIN
VALID CON 22 ' Valid Code
UTYPE CON 27 ' Unit Type
UID con 2550 ' Unit Identefier

' Initialize hardware PWM - IRLED 38KHz drive

PORTB = %00000000 ' PortB = 0 : IRLED On PortB.1 Off
TRISB = %00000000 ' PortB = all outputs
PR2 = 25 ' Set PWM for approximately 38KHz
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale


IR_TX:
serout txpin,n1200,[$66,VALID,UTYPE,UID]
PAUSE 1000 ' 1sec delay
GOTO IR_TX

End
</code>

Thank Again,
Jeremy

Jerson
- 27th August 2008, 11:14
Hello Again,
rx:
serin rxpin,n1200,[$66],VALID,UTYPE,UID
if VALID = 22 then hit
goto rx

hit:
</code>

Jeremy

After a cursory glance at your code, I think the statement in RX should change to


rx:
serin rxpin,n1200,[WAIT($66),VALID,UTYPE,UID]

Wait for $66 and then read the rest.

jhorsburgh
- 27th August 2008, 12:44
Hey Jerson,
I tried changing the the code but for some reason when i try to compile the code, the following error occurrs. <code>ERROR Line 25: Bad expression. (RX.pbp)</code>

<code>rx:
serin rxpin,n1200,[WAIT($66),VALID,UTYPE,UID] 'Line 25
if VALID = 22 then hit
goto rx</code>

Is it the software i am using?
MicroCode Studio - PBP Compiler

The previous code works using RF modules but not for IR.

Regards,
Jeremy

mackrackit
- 27th August 2008, 13:26
Double check the syntax for SERIN and the wait modifier.

Other than that, are you sure the hardware is working correctly, everything is matched?

If you have not seen this it may help. The receiver code is for a BS2 though.
http://www.rentron.com/Infrared_Communication.htm

Bruce
- 27th August 2008, 14:51
See this example http://www.rentron.com/Micro-Bot/IR_Serial.htm

SERIN does not require the WAIT modifier. Just enclose the qualifier in square
brackets. SERIN2 can be used with the WAIT modifier followed by the qualifier
in square brackets.

jhorsburgh
- 29th August 2008, 13:03
Thanks Guys,
I have been looking around at different posts and the internet and i can't find a solution, they all say what i am doing is correct but it does not work. I have attached a copy of the wiring for you guys to look at. The only other thing i can think of in the Baud Rate and the way its driven. Should N1200 work? or should i drive it TRUE?

Thanks Again,
Jeremy

mackrackit
- 29th August 2008, 13:15
Your drawing will not display. Try uploading again.

jhorsburgh
- 29th August 2008, 14:07
does this attachment work better? PS. i forgot to put the external oscillator on the the drawing, but its connected.

Jeremy

mackrackit
- 29th August 2008, 15:18
All I get is this
"The image “http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2839&amp;d=1220015090” cannot be displayed, because it contains errors."

ardhuru
- 29th August 2008, 17:58
Once you have the basic setup working, I suggest you drive the LED from just the PWM pin (ground the cathode), by controlling the output of the pin as per your data requirement; you will find a significant improvement in range.

Regards,

Anand