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

Need help in IR receiver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
attabros



Joined: 28 Jul 2008
Posts: 35

View user's profile Send private message

Need help in IR receiver
PostPosted: Thu Nov 20, 2008 6:36 am     Reply with quote

Hi Everyone,

I have made a sample program for IR transmitter
Code:


#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


void main()
{

int y;
 
 
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
 
while(TRUE)

  {
y=1;
  {
    setup_timer_2(T2_DIV_BY_1,131,1);
    set_pwm1_duty(264);
    delay_ms(1000);
  }
 
  y=0;
  {
    setup_timer_2(T2_DIV_BY_1,131,1);
    set_pwm1_duty(264);
    delay_ms(1000);
  }
 
  {
    set_pwm1_duty(0);
    delay_ms(1000);
  }
  }
  }


But slightly confused on how I will receive those bits on the receiver side.
I have connected the output pin of receiver to PIC B0 pin. If I want to
glow two leds when y=1 occur D0 will turn on an LED & when y=0 occur D1 will turn another LED. Please help me to generate the receiver code.
THANKS
attabros



Joined: 28 Jul 2008
Posts: 35

View user's profile Send private message

PostPosted: Fri Nov 21, 2008 6:30 am     Reply with quote

I have studied some projects is it necessary to use interrupt
on the reciever side.
So how i will make a reciever code for the above transmitter.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 21, 2008 9:59 pm     Reply with quote

Quote:
y=1;
{
setup_timer_2(T2_DIV_BY_1,131,1);
set_pwm1_duty(264);
delay_ms(1000);
}

y=0;
{
setup_timer_2(T2_DIV_BY_1,131,1);
set_pwm1_duty(264);
delay_ms(1000);
}

{
set_pwm1_duty(0);
delay_ms(1000);
}
I don't get how you are encoding a y=1 and y=0. Anyway, if all you need to do do is turn ON or OFF two LEDs based based on the value of 'y', you don't need to use interrupts. I suppose you are using a TSOP at the receiving end? When the TSOP detects a modulated pulse stream it switches its output low. All you need to do is run a loop on your receiver microcontroller checking for the state of the TSOP pin:

Code:
while(1)
{                              //TSOP output is active-low; idle-high
    if(input(TSOP))      //no pulses are detected by TSOP
    {
          output_high(LED0);
          output_low(LED1);
     }
     else
     {
          output_low(LED0);
          output_high(LED1);
     }
}

This is going to keep your processor really busy. So if the only thing you want to is toggle LEDs, this is fine. Else, you should look at interrupts.

Rohit
     
attabros



Joined: 28 Jul 2008
Posts: 35

View user's profile Send private message

PostPosted: Mon Nov 24, 2008 7:02 am     Reply with quote

Thanks for your reply.

It works fine what if i use an interrupt for the same senario,
what i have studied iterrupt function is used before main function,
but i have no idea how i will use it as well as i need to transfer binary
data just for a practice let suppose 0 to 9 plz have a look

Code:


#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

void main()
{

int y;
 
 
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
 
while(TRUE)

 
  {
  for(y=0;y<10;y++)
  {
    setup_timer_2(T2_DIV_BY_1,131,1);
    set_pwm1_duty(264);
    delay_ms(1000);
  }
 
  {
    set_pwm1_duty(0);
   delay_ms(1000);
  }}}



will it work fine n how i will read this on the reciever as i m using TSOP
if i connect three LEDs on D0, D1 & D2 to show binary data.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 24, 2008 7:36 am     Reply with quote

To send any sort of data you would need to use a protocol. A protocol is a set of 'rules' that are common to the transmitter and receiver. The 'rules' are used to encode and decode the raw data into something meaningful. It would be very difficult to send data other than just '1' and '0' without using a protocol.

The protocol can be a simple one like the generic RS232 (EIA/TIA 232) based serial protocol, or something more complex, like IrDA. The protocol is used to ensure that the receiver gets only the data meant for it - nothing else. Some protocols also have the additional facility of checking for/ensuring data integrity.

Common protocols include the Sony SIRC, Phillips RC5, NEC, JVC, etc. The protocol defines timings of the IR pulse lengths, whether or not Manchester encoding is used, etc.

Most protocols have a 'preamble' or starting sequence; a device address; the actual data; and a stop sequence. When this data is received by the receiver (with the correct address), the preamble, address, and stop sequence are stripped, and the data is extracted out.

Please have a look at http://www.sbprojects.com/knowledge/ir/ir.htm . It has a lot of useful information.

Rohit
attabros



Joined: 28 Jul 2008
Posts: 35

View user's profile Send private message

PostPosted: Sat Nov 29, 2008 2:17 am     Reply with quote

While Transmitting & Receiving data using RS-232 at both sides from one microcontroller to another using IR as a communication medium between controllers what baud rate should I select for better results ?

THANKS
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Sat Nov 29, 2008 2:44 am     Reply with quote

Speed depends entirely on what hardware you use. You still haven't stated what IR receiver you are using. Anyway, with the TSOP1738 I would not recommend going over 2400 baud, though I have sucessfully tried 4800. At this speed I start to lose data only at a range of 4 feet and over. At 9600 baud there is almost zero data integrity. This is in accordance with the TSOP's datasheet, which states that at least 10 cycles at 38kHz are necessary for the TSOP to detect an IR pulse.

Rohit
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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