Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM and TV remote control receiver

Status
Not open for further replies.

kasamiko

Member
I'm going crazy with this..:(

I'm using 16F628A to generate modulated 40khz to drive an infrared led and a tv infrared remote control receiver as detector...

here is my PWM code below:

@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 20 ' We're using a 20MHz crystal
CCPR1L = 25 ' 25=20% PWM Duty-Cycle
PR2 = 124 ' Set PWM for ~40KHz
T2CON = 4 ' Timer2 ON + 1:1 prescale
TRISB=%00000100 ' Set PortB TRIS register
PORTB=%00000011 ' LEDs off, pulsout pins set for logic 1 pulses

but I can't make it works...:(

I also tried using 556 which is the 40khz oscillator is gated by another 250hz oscillator but still doesn't work!

Any ideas will be appreciated...

TIA
 
Using the PWM module to generate the carrier is a really poor way of doing it, it's FAR more accurate, easier, and better overall to just do it in simple software loops.

My PIC tutorials show how to do that using the Sony SIRC's system.
 
What isn't happening?

the IR receiver will respond for awhile then shutdown...


Using the PWM module to generate the carrier is a really poor way of doing it, it's FAR more accurate, easier, and better overall to just do it in simple software loops.

My PIC tutorials show how to do that using the Sony SIRC's system.


Thanks...I'll check this out....


is this a simple software loops? sorry I only "speak" BASIC....:(

Code:
[B]DEFINE [/B]OSC 20
TRISB=%00000001 [COLOR=#000080][I]' PortB.0=input, rest=outputs
[/I][/COLOR]PortB=%00000010 [COLOR=#000080][I]' LED=off on start
                   '                 430       IRLED
                   ' PortB.1 -------/\/\/\/------|<|----------+5V

[/I][/COLOR]NumCycles [B]VAR BYTE [/B][COLOR=#000080][I]' Holds number of 40KHz carrier cycles
[/I][/COLOR]IR_IN     [B]VAR BIT  [/B][COLOR=#000080][I]' IR detector input storage bit
[/I][/COLOR]IR_IN=1            [COLOR=#000080][I]' Start with 1 | Indicates no object detected
[/I][/COLOR][B]GOTO [/B]Main          [COLOR=#000080][I]' Jump over sub to Main routine

                  '                           ~47%
                  '                     High duty-cycle
[/I][/COLOR]Pulse:            [COLOR=#000080][I]'                +5V     ___________         ____
[/I][/COLOR][COLOR=#008000]@   bcf portb,1   [/COLOR][COLOR=#000080][I]; 200nS, LED=on          |         |         |
    [/I][/COLOR][B]PAUSEUS [/B]13    [COLOR=#000080][I]' 13uS                   | 11.8uS  | 13.2uS  |
[/I][/COLOR][COLOR=#008000]@   bsf portb,1   [/COLOR][COLOR=#000080][I]; 200nS, LED=off  0  ____|         |_________|
    [/I][/COLOR][B]PAUSEUS [/B]11    [COLOR=#000080][I]' 11uS                   |                   | 
[/I][/COLOR][COLOR=#008000]@   decfsz _NumCycles,F [/COLOR][COLOR=#000080][I]; 200nS            |<----  ~25uS  ---->|
[/I][/COLOR][COLOR=#008000]@   goto _Pulse   [/COLOR][COLOR=#000080][I]; 400nS, LED=off
    [/I][/COLOR]IR_IN=PortB.0 [COLOR=#000080][I]' Read detector output
    [/I][/COLOR][B]RETURN        [/B][COLOR=#000080][I]' Return to Main    

[/I][/COLOR]Main:
    NumCycles=20  [COLOR=#000080][I]' 20 carrier cycles
                  ' Most IR detectors require >=10 carrier cycles
                  ' Adjust as required to adjust time of 40KHz burst
    [/I][/COLOR][B]GOSUB [/B]Pulse   [COLOR=#000080][I]' Go check for obstacle
    [/I][/COLOR][B]IF [/B]IR_IN=0 [B]THEN [/B]Obstacle
    [B]LOW [/B]Portb.2   [COLOR=#000080][I]' No obstacle, indicator LED=off
    [/I][/COLOR][B]GOTO [/B]Main     [COLOR=#000080][I]' Return to Main
                  '                  430         LED
[/I][/COLOR]Obstacle:         [COLOR=#000080][I]' PortB.2 -------/\/\/\/\-------|>|-------GND
    [/I][/COLOR]IR_IN=1       [COLOR=#000080][I]' Reset object detection indicator bit 
    [/I][/COLOR][B]HIGH [/B]Portb.2  [COLOR=#000080][I]' Turn on LED when object is detected
    [/I][/COLOR][B]GOTO [/B]Main     [COLOR=#000080][I]' Return to Main[/I][/COLOR]
If I'll be using a 38khz IR detector then it should be 26.3uS instead of 25uS?? like this one?

Code:
Pulse:            '                +5V     ___________         ____
@   bcf portb,1   ; 200nS, LED=on          |         |         |
    [COLOR=Red][B]PAUSEUS 13[/B][/COLOR]    ' 13uS                   | [COLOR=Red][B]13.2uS[/B][/COLOR]  | [COLOR=Red][B]13.2uS[/B][/COLOR]  |
@   bsf portb,1   ; 200nS, LED=off  0  ____|         |_________|
   [COLOR=Red][B] PAUSEUS 13[/B][/COLOR]    ' 13uS                   |                   | 
@   decfsz _NumCycles,F ; 200nS            |<----  ~[COLOR=Red][B]26.4uS[/B][/COLOR]  ---->|
@   goto _Pulse   ; 400nS, LED=off
    IR_IN=PortB.0 ' Read detector output
    RETURN        ' Return to Main
 
Last edited:
is this a simple software loops? sorry I only "speak" BASIC....:(

Code:
[B]DEFINE [/B]OSC 20
TRISB=%00000001 [COLOR=#000080][I]' PortB.0=input, rest=outputs
[/I][/COLOR]PortB=%00000010 [COLOR=#000080][I]' LED=off on start
                   '                 430       IRLED
                   ' PortB.1 -------/\/\/\/------|<|----------+5V

[/I][/COLOR]NumCycles [B]VAR BYTE [/B][COLOR=#000080][I]' Holds number of 40KHz carrier cycles
[/I][/COLOR]IR_IN     [B]VAR BIT  [/B][COLOR=#000080][I]' IR detector input storage bit
[/I][/COLOR]IR_IN=1            [COLOR=#000080][I]' Start with 1 | Indicates no object detected
[/I][/COLOR][B]GOTO [/B]Main          [COLOR=#000080][I]' Jump over sub to Main routine

                  '                           ~47%
                  '                     High duty-cycle
[/I][/COLOR]Pulse:            [COLOR=#000080][I]'                +5V     ___________         ____
[/I][/COLOR][COLOR=#008000]@   bcf portb,1   [/COLOR][COLOR=#000080][I]; 200nS, LED=on          |         |         |
    [/I][/COLOR][B]PAUSEUS [/B]13    [COLOR=#000080][I]' 13uS                   | 11.8uS  | 13.2uS  |
[/I][/COLOR][COLOR=#008000]@   bsf portb,1   [/COLOR][COLOR=#000080][I]; 200nS, LED=off  0  ____|         |_________|
    [/I][/COLOR][B]PAUSEUS [/B]11    [COLOR=#000080][I]' 11uS                   |                   | 
[/I][/COLOR][COLOR=#008000]@   decfsz _NumCycles,F [/COLOR][COLOR=#000080][I]; 200nS            |<----  ~25uS  ---->|
[/I][/COLOR][COLOR=#008000]@   goto _Pulse   [/COLOR][COLOR=#000080][I]; 400nS, LED=off
    [/I][/COLOR]IR_IN=PortB.0 [COLOR=#000080][I]' Read detector output
    [/I][/COLOR][B]RETURN        [/B][COLOR=#000080][I]' Return to Main    

[/I][/COLOR]Main:
    NumCycles=20  [COLOR=#000080][I]' 20 carrier cycles
                  ' Most IR detectors require >=10 carrier cycles
                  ' Adjust as required to adjust time of 40KHz burst
    [/I][/COLOR][B]GOSUB [/B]Pulse   [COLOR=#000080][I]' Go check for obstacle
    [/I][/COLOR][B]IF [/B]IR_IN=0 [B]THEN [/B]Obstacle
    [B]LOW [/B]Portb.2   [COLOR=#000080][I]' No obstacle, indicator LED=off
    [/I][/COLOR][B]GOTO [/B]Main     [COLOR=#000080][I]' Return to Main
                  '                  430         LED
[/I][/COLOR]Obstacle:         [COLOR=#000080][I]' PortB.2 -------/\/\/\/\-------|>|-------GND
    [/I][/COLOR]IR_IN=1       [COLOR=#000080][I]' Reset object detection indicator bit 
    [/I][/COLOR][B]HIGH [/B]Portb.2  [COLOR=#000080][I]' Turn on LED when object is detected
    [/I][/COLOR][B]GOTO [/B]Main     [COLOR=#000080][I]' Return to Main[/I][/COLOR]
If I'll be using a 38khz IR detector then it should be 26.3uS instead of 25uS?? like this one?

Code:
Pulse:            '                +5V     ___________         ____
@   bcf portb,1   ; 200nS, LED=on          |         |         |
    [COLOR=Red][B]PAUSEUS 13[/B][/COLOR]    ' 13uS                   | [COLOR=Red][B]13.2uS[/B][/COLOR]  | [COLOR=Red][B]13.2uS[/B][/COLOR]  |
@   bsf portb,1   ; 200nS, LED=off  0  ____|         |_________|
   [COLOR=Red][B] PAUSEUS 13[/B][/COLOR]    ' 13uS                   |                   | 
@   decfsz _NumCycles,F ; 200nS            |<----  ~[COLOR=Red][B]26.4uS[/B][/COLOR]  ---->|
@   goto _Pulse   ; 400nS, LED=off
    IR_IN=PortB.0 ' Read detector output
    RETURN        ' Return to Main

Yes it is.

38KHz and 40KHz makes almost no difference at all, it's not a concern - if you really want to, simply alter the timing to make it as accurate as you like.
 
Still wont work..:(..The IR receiver still shut down...

I wonder what frequency the TV IR remote is modulated?? cause when i point my remote control it can receive the signal continuously..
 
I've been there sir but I don't understand assembly....All i need is something like 38khz modulated by 100hz....:(
I'm lost with that bit and byte..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top