CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

infrared communication
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eros
Guest







infrared communication
PostPosted: Tue Feb 26, 2002 3:59 pm     Reply with quote

<font face="Courier New" size=-1>I m doing the infrared data sending and receiving using the pic 16f877.but i can't find any infrared communication library file or the examble souce code from the ccs for me to refer..
can i use the rs232 concept using the infrared instead of cable connect
i m lost,and dun't know how to start, do somebody have idea..


ThankQ



</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 2829
johnpcunningham
Guest







Re: infrared communication
PostPosted: Wed Feb 27, 2002 8:56 am     Reply with quote

Infrared is just a transfer medium, like RF wireless or a cable. You can use RS232 to transfer data through Infrared just like using a cable. RS232 typically uses drivers (ie MAX232) to invert the voltages and increase the drive cababilities, but since you are going wireless, this does not pose a problem. Just make sure the receive side signals matches the transmit side signals.

One thing to point out is that you wont have any handshaking capabilities and error correction gets tough if you are trying to transmit data where other IR is being transmitted. You might need an error correction scheme like Reed_Solomon or some other type of correction. But that is beyond the scope of this email.

JC
___________________________
This message was ported from CCS's old forum
Original Post ID: 2844
Eros
Guest







Re: infrared communication
PostPosted: Wed Feb 27, 2002 5:53 pm     Reply with quote

:=Infrared is just a transfer medium, like RF wireless or a cable. You can use RS232 to transfer data through Infrared just like using a cable. RS232 typically uses drivers (ie MAX232) to invert the voltages and increase the drive cababilities, but since you are going wireless, this does not pose a problem. Just make sure the receive side signals matches the transmit side signals.
:=
:=One thing to point out is that you wont have any handshaking capabilities and error correction gets tough if you are trying to transmit data where other IR is being transmitted. You might need an error correction scheme like Reed_Solomon or some other type of correction. But that is beyond the scope of this email.
:=
:=JC


ThanQ for u reply
refer to ur saying,the error checking and the handshaking also are the problems..
That is why i m no sure the rs232 is do able or not,if not using rs232, what methods else i can use?
(my concept is use the software flow control, add the start bit, stop bit and error checking on the data... do anyone have other idea or comment )

Eros :>
___________________________
This message was ported from CCS's old forum
Original Post ID: 2855
John Purbrick
Guest







Re: infrared communication
PostPosted: Thu Feb 28, 2002 7:15 am     Reply with quote

If you attempt to have the IR sent out strictly the way a serial port works, i.e. LED is on for 1/9600 sec per bit if you selected 9600 Baud, I'm afraid you'll have a miserably poor range and the system won't work well, and it'll be subject to total death if there are incandescent lights or sunlight anywhere near.

One method that works well across a room is to use TV remote control receivers, and modulate the LED at the required frequency (40KHz or 38KHz are common). If the PIC has time to do this it can do it directly, or you can use an external oscillator. I've tried the TV decoders and they work, but you have to accept a fairly low Baud rate--1.2KB worked but I had trouble at 2.4KB. Note that 40KHz actually means 80000 interrupts per second, as you need one to turn the LED on and another to turn it off!
___________________________
This message was ported from CCS's old forum
Original Post ID: 2872
Dennis Clark
Guest







Re: infrared communication
PostPosted: Thu Feb 28, 2002 8:18 am     Reply with quote

IR commo is no problem, as long as you don't set your sights
too high. I have used 2400 N81 over IR at distances of a
several feet via Parallax Stamps and PIC12C508 bit-banging with
no problems in full indoor lighting conditions. With the
Stamp II I used inverted serial out and with PICs I've used
my own 40KHz modulation routines to send bit-banged serial.
The key to remember is that the IR demodulator will read a
"signal present"(saw modulation) as a '0' and a lack of signal
as a '1'. Make sure you set up your transmitter and receiver
such that they agree on this protocol! In trivial cases I
didn't bother with error detection or correction as commands
were usually repeated anyway. Where it is important you can
take a leaf from the LEGO Mindstorms RCX IR protocol. They
used 8 bit WITH even parity, sent each byte normal and inverted
and used a checksum at the end of the series. This is most
paranoid but was rock solid. Pick your pain level. If you
want to see an example of IR serial I/O using PIC code and
being bit-banged, check my web page at
<a href="http://www.techtoystoday.com" TARGET="_blank">http://www.techtoystoday.com</a> and bonk on the "sensor projects"
link and look for the IR transmitter/receiver project.

have fun,
DLC

:=:=Infrared is just a transfer medium, like RF wireless or a cable. You can use RS232 to transfer data through Infrared just like using a cable. RS232 typically uses drivers (ie MAX232) to invert the voltages and increase the drive cababilities, but since you are going wireless, this does not pose a problem. Just make sure the receive side signals matches the transmit side signals.
:=:=
:=:=One thing to point out is that you wont have any handshaking capabilities and error correction gets tough if you are trying to transmit data where other IR is being transmitted. You might need an error correction scheme like Reed_Solomon or some other type of correction. But that is beyond the scope of this email.
:=:=
:=:=JC
:=
:=
:=ThanQ for u reply
:=refer to ur saying,the error checking and the handshaking also are the problems..
:=That is why i m no sure the rs232 is do able or not,if not using rs232, what methods else i can use?
:=(my concept is use the software flow control, add the start bit, stop bit and error checking on the data... do anyone have other idea or comment )
:=
:=Eros :>
___________________________
This message was ported from CCS's old forum
Original Post ID: 2875
Magic_Pilot
Guest







Re: infrared communication
PostPosted: Fri Mar 01, 2002 3:33 am     Reply with quote

you can use rs232 protocol but you must also use data check eg
you can send a string following format #data1*data1# and check it in receiver.



:= IR commo is no problem, as long as you don't set your sights
:=too high. I have used 2400 N81 over IR at distances of a
:=several feet via Parallax Stamps and PIC12C508 bit-banging with
:=no problems in full indoor lighting conditions. With the
:=Stamp II I used inverted serial out and with PICs I've used
:=my own 40KHz modulation routines to send bit-banged serial.
:=The key to remember is that the IR demodulator will read a
:="signal present"(saw modulation) as a '0' and a lack of signal
:=as a '1'. Make sure you set up your transmitter and receiver
:=such that they agree on this protocol! In trivial cases I
:=didn't bother with error detection or correction as commands
:=were usually repeated anyway. Where it is important you can
:=take a leaf from the LEGO Mindstorms RCX IR protocol. They
:=used 8 bit WITH even parity, sent each byte normal and inverted
:=and used a checksum at the end of the series. This is most
:=paranoid but was rock solid. Pick your pain level. If you
:=want to see an example of IR serial I/O using PIC code and
:=being bit-banged, check my web page at
:= <a href="http://www.techtoystoday.com" TARGET="_blank"> <a href="http://www.techtoystoday.com" TARGET="_blank">http://www.techtoystoday.com</a></a> and bonk on the "sensor projects"
:=link and look for the IR transmitter/receiver project.
:=
:=have fun,
:=DLC
:=
:=:=:=Infrared is just a transfer medium, like RF wireless or a cable. You can use RS232 to transfer data through Infrared just like using a cable. RS232 typically uses drivers (ie MAX232) to invert the voltages and increase the drive cababilities, but since you are going wireless, this does not pose a problem. Just make sure the receive side signals matches the transmit side signals.
:=:=:=
:=:=:=One thing to point out is that you wont have any handshaking capabilities and error correction gets tough if you are trying to transmit data where other IR is being transmitted. You might need an error correction scheme like Reed_Solomon or some other type of correction. But that is beyond the scope of this email.
:=:=:=
:=:=:=JC
:=:=
:=:=
:=:=ThanQ for u reply
:=:=refer to ur saying,the error checking and the handshaking also are the problems..
:=:=That is why i m no sure the rs232 is do able or not,if not using rs232, what methods else i can use?
:=:=(my concept is use the software flow control, add the start bit, stop bit and error checking on the data... do anyone have other idea or comment )
:=:=
:=:=Eros :>
___________________________
This message was ported from CCS's old forum
Original Post ID: 2891
cxiong



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

Infrared transmitter / receiver
PostPosted: Wed Jan 12, 2005 1:26 pm     Reply with quote

I am working on a project using IR communication, I have the transmitter
and the receiver talking, but the data are junk per hypertminal.

Per the code below, it should display (0123456789), but it display (c3f2dcged).

I USE THE IRLED from RadioShack 276-0143 for the TX and I use the
Panasonic PNA4602M for the receiver. I generate a 39Kh (PWM) for the
transmitter to match up the receiver freq.

I connect them to 2 of the Demo 2 Plus board.

Any body have any idea what did I did wrong?
Here is my code:

///RECEIVER////
Code:

#include <18F458.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7) 


main()
{
   char c;
   while(1)
    {     
                         
        c=getc();

      printf("%d\n",c);

      
   }

}


/// TRANSMITTER CODE////
Code:

#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_b1, rcv=PIN_b2) 


main()
{

   int value;
    output_low(pin_a5);
   output_b(0x31);
   output_low(PIN_C2);    // Set CCP1 output low
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
   setup_timer_2(T2_DIV_BY_1, 127, 1);   // Setup for 39KHz     
   set_pwm1_duty(64);                    //  50% duty cycle


   
   
//   setup_adc_ports( ALL_ANALOG );
//   setup_adc( ADC_CLOCK_INTERNAL );
   

   while(1)
   {   
//      set_adc_channel( 0 );
 //     delay_ms(20);
//      value = read_adc();
//     delay_ms(20);
//     printf("Value: %d",value);

   printf("0");
   delay_ms(50);
   printf("1");
   delay_ms(50);
   printf("2");
   delay_ms(50);
   printf("3");
   delay_ms(50);
   printf("4");
   delay_ms(50);
   printf("5");
   delay_ms(50);
   printf("6");
   delay_ms(50);
   printf("7");
   delay_ms(50);
   printf("8");
   delay_ms(50);
   printf("9");
   delay_ms(50);
   printf("\n\r");
   printf("\n\r");
    }
                                   
 

}





I did try the ADC subroutine above that I comment out, the same problem.

PLEASE HELP...
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 12, 2005 2:01 pm     Reply with quote

That receiver is a 38KHz version. Why are you using 39KHz? Try a value of 130 for PR2. You will have to adjust the duty cycle as well. You can also take a scope and look at the output of the PNA4602M and compare this to the output of the serial data. They ought to be the same.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Re: infrared communication
PostPosted: Wed Jan 12, 2005 2:36 pm     Reply with quote

John Purbrick wrote:
Note that 40KHz actually means 80000 interrupts per second, as you need one to turn the LED on and another to turn it off!


Which is why I would never do it that way. Instead have the PIC UART key a simple 40kHz oscillator such as a LM555. Also the Maxim MAX3100 has a special mode just for use with IR. It would be worth reading the datasheet to see how they do it.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Re: Infrared transmitter / receiver
PostPosted: Wed Jan 12, 2005 3:15 pm     Reply with quote

cxiong wrote:
I am working on a project using IR communication, I have the transmitter
and the receiver talking, but the data are junk per hypertminal.



Someone mentioned MAX3100 which is also a UART and requires SPI and an external clock, I have used it, but when the PIC already has a UART it's a waste, unless you need two UARTS.

For IR I use TIR1000, it also requires an external clock, however the interface is easy, the chip formats the RS-232 (TTL direct from PIC) and drives a ZXH1010 Tx/Rx IR LED module.

With this combination my unit does a solid 115,200 Baud indoors at a distance of about 6 -10 feet.

Outdoors in bright sunshine.... 1 foot ! Crying or Very sad

That's why I moved to Bluetooth. Outdoors 300 Feet. amd 460,800 Baud. Very Happy
cxiong



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 12, 2005 3:57 pm     Reply with quote

When I re-adjust the PR2 to 130, I measure it with the O'scope, I have 38.4Khz.

The data display in the hyperterminal still the same as above. It does not solve the problem.

I change from printf("%d\n",c); to putc(c), no different. I measure the data out (data_pin )of transmitter compare it to the data out of receiver, they are different.

At the transmitter side, the scope show more like the 38.4Khz clock with some noise.

At the receiver side, the scope show a data line (more like serial data signal, such 01010001).

Below is my circuit.


Transmitter connect to 1st Demo 2 Plus board.


Receiver connect to the 2nd Demo 2 Plus board.

Will the above software work for these circuits?
cxiong



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

Infrared data conversion
PostPosted: Thu Jan 13, 2005 12:22 pm     Reply with quote

Infrared data conversion, does it need to have a MAX 232 between the receiver and the PC port?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 13, 2005 12:42 pm     Reply with quote

Quote:
does it need to have a MAX 232 between the receiver and the PC port
To a PC yes, to the PIC, no.


You should Power the IR receiver through a 100 ohm resistor. Also add a 4.7uF cap from the Vcc pin of the receiver to ground (after the 100R). Also add a 10K pullup to the Vout line.

Take a look at this datasheet.
http://www.rentron.com/Files/TSOP11xx.pdf

I would recommend using that circuit.
cxiong



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

PostPosted: Thu Jan 13, 2005 2:59 pm     Reply with quote

I have the receiver send the received data to hyperterminal.
Here is what I got from the Hyperteminal:



Here is my latest transmit code:
Code:

#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_b1) 


main()
{

   int i;
    output_low(pin_a5);      // to turn on LED indicate pwr is applied
   output_low(PIN_B1);      //Reset pin b1
   output_low(PIN_C2);    // Set CCP1 output low
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
/*
 *
   setup the 38Khz at 50% duty cycle PWM

   Frequency ( f ) and period ( P ) are inversely proportional. f = 1/P, & P = 1/f.

   To calculate the value to be loaded into PR2:
   (20MHz / (4 * TMR2 prescale value * 38KHz)) - 1= PR2.

   We'll use a prescale value of 1 for timer2.

   4 * 1 * 38,000 = 152,000
   20,000,000 / 152,000 = 131.57
   131.57 - 1 = 130.57

   PR2 = 130



   To figure the value to load into CCPRL1 for 38KHz @ 4MHz with a 50% duty cycle:

   (PR2 + 1) * TMR2 prescale * 50% Duty Cycle = value for CCPRL1, or
   (130+ 1) * 1 * 0.50 = 65.5

   load 65 to duty_cycle to get 50% duty cycle.



 *
*/
   setup_timer_2(T2_DIV_BY_1, 130, 1);    //setup for 38.4khz
   set_pwm1_duty(65);                     //  50% duty cycle


 

   while(1)                         //send 0 - 9 to the receiver
   {   
   
   for(i=0; i<10; i++)
   printf("%u\n\r",i);

    }
                                   
 

}



Receiver Code:

Code:

#include <18F458.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7) 


main()
{
   char c;

   while(1)
    {     
                         
        c=getc();
      putc(c);



      
   }

}



Thanks for those who has previously help, but I
still need more support from everyone.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Jan 14, 2005 8:53 am     Reply with quote

cxiong wrote:

Quote:

Thanks for those who has previously help, but I
still need more support from everyone.


Surely there are many ways to do what you want. The easiest one is using a NAND IC
gate array (74HC00 or similar) wich has internally 4 NAND gates.
With one gate + 1 Resistor + 1 Capacitor you can create an oscillator and selecting
R and C you will get a good 38 Khz free running oscillator.
The ouput of this gate (oscillator) connect to one input of the next NAND gate.
The free input of this second gate connect to the PIC, so you have a gated 38 Khz oscillator.
Itīs a matter of driving the IR Led with this gated pulses using a transistor in such a way to
"modulate" with the PIC the info you want to send.

This way you donīt need to use (and fight) with prescalers, timers, PWM and processor overhead.


Hope this help (and understand the explanation). Very Happy

Humberto

PD: donīt forget to tie to Gnd the unused NAND inputs.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group