It is currently 22 May 2019 05:39

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 15 Jul 2009 11:58 
Offline

Joined: 07 Dec 2006 11:00
Posts: 317
Location: Vienna, Austria
Hello,
I want to transmit serial data using infrared and standard IR-receivers like SFH506. I need no high speed, but it must work with a absolute minimum of parts and costs.

So I want to use a 12F683, it shall produce the carrier frequency with the built in PWM generator and an IR-Diode between this output and another PIN, where I output data with SoftUART.

Something like this:
   PIC 12F683

  .-----------.
  |    PWM Out|-----[300R]----------.
  |           |                    _|_
  |           |                    \ /  IR-LED
  |           |                    _V_
  |           |                     |
  |    Ser-Dat|---------------------'
  '-----------'

PWM-Out generates a continuous square-wave with 50% duty-cycle and 38 or 40 kHz (depending on the SFH506 model. The second output, Ser-Dat, outputs the serial data stream from Soft-UART. As the LED only emits in one current direction, it will send pulses only when Ser-Dat is low (in this schematic). The receiver (SFH 506) then does a pulldown (OC output), so I get the "L" level there too.

It may be necessary to add an anti-parallel diode, if the IR-LED has an insufficient reverse voltage level. As a PIC is usually strong enough, I assume that I will not need transistors as drivers, if I want to transmit only over 2-3 meters of distance.

In my opinion this should work up to (theoretically) 2400bps which is quite sufficient, I would even only use 1200bps to be sure that the pulse train is decoded correctly.


Possibly one of you has already tried that with more or less success. I will be very interested in reading your experiences. How precisely do I get 38kHz or 40 kHz at all?



rainer


Top
 Profile  
 
 Post subject:
PostPosted: 15 Jul 2009 18:20 
Offline

Joined: 26 Jan 2006 07:21
Posts: 202
Location: Bulgaria
Hi,
just use interrupt at 76 or 80 kHz. Toggle output pin on every int and you'll get 38 or 40 kHz.


Top
 Profile  
 
PostPosted: 16 Jul 2009 03:55 
Offline

Joined: 02 Apr 2006 05:56
Posts: 432
Location: Riode Janeiro, Brasil
rainer wrote:
Hello,
Something like this:
   PIC 12F683

  .-----------.
  |    PWM Out|-----[300R]----------.
  |           |                    _|_
  |           |                    \ /  IR-LED
  |           |                    _V_
  |           |                     |
  |    Ser-Dat|---------------------'
  '-----------'
Hi Rainer
1- Very clever your "modulation" method. Ilike simple and clever designs.
2- do not worry, your IR led normally has more thn 5v reverse voltage, so, no problem. I normaly use the TSALxxx IR line (buy at farnell), sometimes use with more than 5v (12v) reverse, never had a problem.
3- you could use your hard serial port to do that (or soft serial too, of course.
4- if needed I suggest far smaller R, something about 100R, if you need more "power" in led. The led and your pic will not burn...
4- here is a link where you can calculate your pwm parameters. Just put there your pic frequency, 38000 hertz and 50% for duty. It gives all parameters yu need.
http://www.micro-examples.com/public/mi ... lator.html
5- Follows the code normaly I use for 38KHz sensors, at 16F628A:
// ***38.4 KHz
     PR2:= %00011001 ;      //25=Set PR2 for 38.4kHz PWM [26uS period]
     T2CON := %00000100 ;   //Turn on Timer2, Prescale = 1
     CCPR1L := 12 ;         //Set PWM Duty-Cycle to 50%
     CCP1CON := 60 ;        //Set CCP1 to PWM
Jose


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2009 07:01 
Offline

Joined: 07 Dec 2006 11:00
Posts: 317
Location: Vienna, Austria
matrix wrote:
Hi,
just use interrupt at 76 or 80 kHz. Toggle output pin on every int and you'll get 38 or 40 kHz.

Thank you for this idea, but there is a minor problem by doing it this way: It causes problems with SoftUART, as the Interrupt will cause timing issues and stretch the timing of SoftUART therefore.

Therefore I want use the hardware PWM generator. It works without interrupting my program, so SoftUART will also not loose its timing.


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2009 17:06 
Offline

Joined: 17 Apr 2008 02:53
Posts: 332
Location: Fantasy Land
Hi rainer. I built an IR transmitter a while back and used the Panasonic PNA4602M 38KHz receiver. The bandpass response is fairly wide. I measured it at about +/- 1KHz or so. So if your receiver is similar, you don't need to worry about being smack dead on to 38KHz.

Mine was written in asm and had nothing to do but monitor a switch and send one of two different commands. So I generated the pulse train with delays: set the led bit, delay, clear the led bit, delay, etc.

My application was to control the stereo volume at work. Some people put on terrible music way too loud. My device was hidden across the room and I had a delay trigger. I would trigger it and walk out of the room; 30 seconds later, it would fire off 'volume-down' pulses. People never figured it out. :twisted:


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2009 19:23 
Offline

Joined: 02 Apr 2006 05:56
Posts: 432
Location: Riode Janeiro, Brasil
if you look at the receiver spec., 38K or 38.4K (as I mentioned earlier), is about the same thing. For example the TSOP4838, at http://www.datasheetcatalog.com/datashe ... 4838.shtml.
As I used 4MHz as cpu clock, the nearest frequency avaiable for pwm is 38.4, and it worked well for 40-60 meters outdors (but on that distance, BD139 was used to put up to 0.8Amps in the IR leds (TSAL 6100) -> it has an angle of 10 degrees, that can not suit your needs, so, you could find one with wider angle.
There is no need for any interrupt.
In practice, tsop takes 16 cycles of 38KHz (about 260-500us) to recognize the "pulse". And, don't forget that at each 80ms of continuous transmit you must give a 20 ms delay so tsop can "breeze".... you canot transmit a continuous train of pulses.
Good luck
Jose


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2009 19:30 
Offline

Joined: 26 Jan 2006 07:21
Posts: 202
Location: Bulgaria
I dont think this int will couse a problem. @1200 one bit time is more than 800 us.


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2009 20:13 
Offline

Joined: 02 Apr 2006 05:56
Posts: 432
Location: Riode Janeiro, Brasil
matrix wrote:
I dont think this int will couse a problem. @1200 one bit time is more than 800 us.
Agree... but don't forget at each 80ms "breeze" time.... it's realy required if pulse train is longer than that, let's say, if the message is nearor higher 80 bytes/char long...or, if betwen messages you do not have at least 20 ms...


Top
 Profile  
 
 Post subject:
PostPosted: 17 Jul 2009 13:15 
Offline

Joined: 26 Jan 2006 07:21
Posts: 202
Location: Bulgaria
I have a system with int on 100 us, and transmits @115200 with no problem, also refreshing 6 or 12 digit display, counting 3 inputs + rotary encoder inputs.


Top
 Profile  
 
 Post subject:
PostPosted: 17 Jul 2009 13:58 
Offline

Joined: 02 Apr 2006 05:56
Posts: 432
Location: Riode Janeiro, Brasil
matrix wrote:
I have a system with int on 100 us, and transmits @115200 with no problem....
You mean, thru a IR link? With normal TSOPxxx? That's very interesting to know... what's the distance?


Top
 Profile  
 
 Post subject:
PostPosted: 20 Jul 2009 20:27 
Offline

Joined: 26 Jan 2006 07:21
Posts: 202
Location: Bulgaria
No, no IR. May be I missunderstood something....


Top
 Profile  
 
 Post subject: Remote Control Repeater
PostPosted: 20 Jul 2009 22:04 
Offline

Joined: 02 Apr 2006 05:56
Posts: 432
Location: Riode Janeiro, Brasil
Hi
Here is a TV, video, etc. remote control repeater Pascal code. It just get the signal arrived from up to 4 sources (4 places where you can put a TSOP receiver). When there is detection it makes pwm pin = a out pin. When there is not, it makes pwm pin=tristate. The lR led is near the TV, video, etc. receivers in order to control them. So, from another room you can control them. There is an extra plain led in the board so you can see it brlinking when you press your remote control.
While it don't use usart (serial interface), can be of some use in order to see reception and transmission of IR at 38Kz.. There is also I used a 16F628, internal clock, 4MHz, in a weekend when I was bored to go back and forth to control a remote device...
PortA0 and portA1 must receive 38Khz sensors. PortA2 and portA3 must receive 36Khz sensors. You can use
only the sensors you intend to use. You can put the sensors in 2 distinct ambients.
Good Luck
Jose
*ps: this is a good program to extend in order to record the pulse sequence of any remote control, and, convert it to another set of commands, like making a universal remote control. Some kind of "recorder" where the guy would giving a sequence key presses.
program RemoteRepeat_v1;
{ this program is a repeater for remote controls. It can operate with 38Khz and 36Khz remote controls.
  The main loop verifies if there is any of the 4 sensors receiving signal. If yes, it starts pwm at
  38 or 36 Hkz and stays in a loop until the sensors does not detect any more the signal. So, it inhibits
  pwm output. Pwm output goes to a IR led.
  Jose Lavaquial - march 2009.
  PortA0 and portA1 must receive 38Khz sensors. PortA2 and portA3 must receive 36Khz sensors. You can use
  only the sensors you intend to use. You can put the  sensors in 2 distinct ambients.
}
Var sensors: byte; absolute $05; volatile; register;    {map sensors IR over PortA}
Const maskSensors= %00001111;   // up to 4 sensors can be connected , but just one used at each time
      SensorsAt38KzOn= %00000011; // sensors for 38Khz (bit 0 and 1)
      SensorsAt36KzOn= %00001100; // sensors for 36Khz (bit 2 and 3)
Var maskedSensors: byte;
k:byte;

procedure pwm38Kz;
begin
  // PWM: 38.4KHz, 50% duty , clock=4MHz
     PR2:= %00011001 ;      //25=Set PR2 for 38.4kHz PWM [26uS period]
     T2CON := %00000100 ;   //Turn on Timer2, Prescale = 1
     CCPR1L := 12 ;         //Set PWM Duty-Cycle to 50%
     CCP1CON := 60 ;        //Set CCP1 to PWM
     TrisB.3:= 0;           //enable pwm output
     portB.7:=1;
end;

procedure pwm36Kz;
begin
  // PWM: 35.7KHz, 50% duty , clock=4MHz
  PR2:= %00000110 ;
  T2CON:= %00000101 ;
  CCPR1L:= %00000011 ;
  CCP1CON:= %00011100 ;
  TrisB.3:= 0;           //enable pwm output
  portB.7:=1;
end;

procedure  initSetup;
begin
  // sets TrisA,TrisB and other registers
  IntCon:= 0;             // no interrupts
  CMCON:= 7;              // comparador off
  OPTION_REG:= %00001111; //ATIVA Timer0 (lido como semente p nros. randomicos)
                          //ativa postscaler máximo (128 vezes) p/ watchdog (perto de 2 segundos)
  trisA:= %11111111 ;     // faz portas serem IN=1/OUT=0
  trisB:= %01111111 ;     //PWM out as tristate (led will no blink) and B.7 = 0 (blinking led)
  portA:= $ff;
  portB:= $7f;
  trisB.3:=1;
//  delay_ms(300);
end;


begin
  delay_ms(1500);                  //just wait power to stabilize
  initSetup;
  while true do                    //loop checks if sensor detected any remote control sending commands
  begin
        TrisB.3:= 1;               //pwm pin=tristate => stops 38.4/36KhzKhz to IR Led
        portB.7:= 0;               //visual blinking led off
        if sensors.0 = 0 then      //if IR sensor1 is receiving signal...
         begin
           pwm38Kz;                //.. starts pwm for 38.4Khz, that goes to IR Led
           while sensors.0=0 do    //.. and while it's receiving signal..
           begin end;              //.....just wait for signal end.
           continue;               //.. goes to the next
         end;
        if sensors.1 = 0 then      //if IR sensor 2 is receiving signal...
         begin
           pwm38Kz;                //.. starts pwm for 38.4Khz, that goes to IR Led
           while sensors.1=0 do    //.. and while it's receiving signal..
           begin end;              //.....just wait for signal end.
           continue;               //.. goes to the next
         end;
        if sensors.2 = 0 then      //if IR sensor 3 is receiving signal...
         begin
           pwm36Kz;                //.. starts pwm for 36KKhz, that goes to IR Led
           while sensors.2=0 do    //.. and while it's receiving signal..
           begin end;              //.....just wait for signal end.
           continue;               //.. goes to the next
         end;
        if sensors.3 = 0 then      //if IR sensor 3 is receiving signal...
         begin
           pwm36Kz;                //.. starts pwm for 36KKhz, that goes to IR Led
           while sensors.3=0 do    //.. and while it's receiving signal..
           begin end;              //.....just wait for signal end.
           continue;               //.. goes to the next
         end;
  end;
end.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to: