Re: IR Learner? Need ideas
Your approach is far too limited. Some protocols use PulseWidthModulation (PWM), some use PulsePositionModulation (PPM) and some use something entirely different. Also the number of bits in a code can vary from less than 20 to more than 100. Most, but not all, use an extended silence between repeat copies of the code.
My interest has been more with RF than IR but the approach is similar except that most RF receivers are active high while most IR receivers are active low.
Here's some code I use with RF. You'll need to modify it for IR. And it will capture only PWM & PPM codes - there are other protocols.
Code:
'============================RECEIVER============================
'PIC12F683 @ 8MHz <500 words
'Receives up to 44 bits of PDM/PWM RF with initial lead-in of 2-9mS
'outputs received codes via RS232 @ 9600bps on GPIO.4 (Pin 3)
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BOD_ON & _CP_OFF & _CPD_OFF
DEFINE OSC 8 '8 MHz oscillator
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 25
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 4 'GPIO.4 (Pin 3)
DEFINE DEBUGIN_BIT 3 'GPIO.3 (Pin 4)
DEFINE DEBUG_MODE 1 'Inverted logic
DEFINE DEBUG_BAUD 9600
Symbol Capture=PIR1.2 'CCP1 capture flag
Symbol PinChng=INTCON.0 'InterruptOnChange
Symbol RS232=GPIO.3 'GPIO.3 (Pin 2)
Symbol RS485=GPIO.0 'GPIO.0 (Pin 6)
RF VAR byte[6]
RS VAR byte[6]
cfg VAR byte[5]
ID VAR byte
pw VAR word
i VAR byte
bits VAR byte
bytes VAR byte
sof VAR word 'start of frame
minSOF VAR word 'minimum start pulse (1900-8500 ~1.9mS-8.5mS)
minBits VAR byte
adc VAR byte
id VAR byte
module VAR byte
addr VAR byte
rssi VAR word 'received signal strength indicator
DATA $01,$FE,$6C,$07,$0E,$01 'EEPROM module,id,minSOF (1900),minBits (14),adc
OSCCON = %01110001 'INT HF OSC 8MHz
WHILE OSCCON.3>0:WEND 'OSC startup timeout
WHILE OSCCON.2=0:WEND 'INT HF OSC stable
CMCON0 =%00000111 'comparators off
TRISIO =%00101110 'make GPIO.0,4 outputs
GPIO =%00000000 'make GPIO.0,4 LOW
ANSEL =%00000010 'make GPIO.1 analog
ADCON0.7=1 'right justify ADC result for 10-bit
IOC =%00001001 'IOC Pins enabled
INTCON =%00000000 'disable interrupts
READ 0,module
DEBUG DEC module,32
READ 1,id
DEBUG DEC id,32
READ 2,minSOF.LowByte
READ 3,minSOF.HighByte
DEBUG DEC minSOF,32
READ 4,minBits
DEBUG DEC minBits,32
READ 5,adc
DEBUG DEC adc,10,13
init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0:RF[4]=0:RF[5]=0
CCP1CON=%00000101:Capture=0 'capture rising edge
While !Capture 'wait for rising edge
Wend
TMR1H=0:TMR1L=0:T1CON=%00010000 'prescale=2, tick=1uS
ADCIN 1, rssi 'read pulse amplitude
CCP1CON=0:Capture=0 'capture falling edge
While !Capture 'wait for falling edge
Wend
sof.HighByte=CCPR1H:sof.LowByte=CCPR1L
If (sof<minSOF) Then init '<min so abort
If (sof>9600) Then init '>max so abort
ADCIN 1, i 'read space amplitude
If (i<rssi) Then
rssi=rssi-i
Else
rssi=i-rssi
EndIf
CCP1CON=%00000101 'capture rising edge
bits=0:Capture=0:INTCON.2=0
While !Capture 'wait for rising edge
Wend
Repeat
TMR1H=0:TMR1L=0:T1CON=%00010000 'prescale=2, tick=1uS
TMR0=100 'overflow 156*16=2496uS (100+156=256)
OPTION_REG=%10000100:Capture=0 'TMR0 prescale=16
While !Capture 'wait rising edge
If INTCON.2=1 Then break 'TMR0 overflow (GAP>2.5mS)
Wend
pw.HighByte=CCPR1H:pw.LowByte=CCPR1L
If (pw<850) Then init '<0.85mS so abort
If (pw>1300) Then '>1.3mS
RF.0(i)=1 'set bit
EndIf
i=i+1
Until (i>43)
break: If (bits<>20) Then
bits=i+1
EndIf
If (bits<minBits) Then init
bytes=(bits)/8
If ((bits)//8>0) Then
bytes=bytes+1
EndIf
Debug bits
For i = 0 to bytes
Debug ihex2 RF[i]
RS[i]=RF[i]
Next
DEBUG ihex2 (sof/40)
If (adc>0) Then
DEBUG ihex2 (rssi>>2)
EndIf
debug 13,10
GoTo init
End
A more generalized method that can capture any protocol uses a bit array and samples the input at 25-50µS intervals, setting a bit when the sample is high. This gives you an image of the code with the resolution depending on the sample rate.
You might find some of the links on my web page useful.
Re: IR Learner? Need ideas
Quote:
Originally Posted by
dhouston
A more generalized method that can capture any protocol uses a bit array and samples the input at 25-50µS intervals, setting a bit when the sample is high. This gives you an image of the code with the resolution depending on the sample rate.
Cheers Dave for the reply. I am still learning this stuff at my pace, can you please elaborate your point with few lines of code for my better understanding.
Re: IR Learner? Need ideas
As my interest has been with RF, with PWM & PPM and with defined protocols, I've never needed to use the generalized method so I have no code. Also, most PICs (all but PIC18) are limited to a maximum array size of 256 bits. If we sample every 50µS (0.00005 secs) 256 bits can only record 0.00005x256=0.0128 secs or 12.8mS which is less than 1/10 the length of some IR codes.
This method was used by dedicated IR devices such as Slink-e and Ocelot which had more powerful processors and much more memory (external to the processor).
Re: IR Learner? Need ideas
Thanks for the info Dave.
I have also gone through a lot of info about this today. I will narrow down my selection to only accept codes from 3 protocols only SIRC, NEC & RC5.
Can anyone advice on how to catch and write routines to save a particular button value coming from any of the remote operating on either of the above protocols. ( I am using 16F676)
Thanks a lot in advance
Re: IR Learner? Need ideas
The RF code I posted earlier in the thread will handle SIRC & NEC although you will need to modify it because IR is active low and it is expecting active high. You want to catch falling edges rather than rising edges.
RC5 is harder - there is no pronounced difference in its start sequence. IIRC Bruce Reynolds has code for it. He may have posted it here or it may be on his website.This site is also quite helpful.
Re: IR Learner? Need ideas
I use the sony protocol. I think that is more easy to learning.
You can use some universal remote control (with sony protocol) to test and to learn.
My sample to help:
@ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT ' System Clock Options
@ DEVICE pic16F628a, WDT_OFF ' Watchdog Timer
@ DEVICE pic16F628a, PWRT_OFF ' Power-On Timer
@ DEVICE pic16F628a, BOD_OFF ' Brown-Out Detect
@ DEVICE pic16F628a, MCLR_ON ' Master Clear Options (External)
@ DEVICE pic16F628a, LVP_OFF ' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF ' Data Memory Code Protect
@ DEVICE pic16F628a, PROTECT_OFF ' Program Code Protection
DEFINE OSC 4
'Definição das variáveis e declarações
INCLUDE "bs1defs.bas" 'inclui arquivo p/ compatibilizar com BS1
'p/entender as variáveis b0...b3, w0...w6 e bit0...bit13
CMCON = 7 'DEFINE PORTA COMO DIGITAL (COMPARADORES ANALÓGICOS:OFF)
symbol ir = PORTB.7 'entrada do sinal de IR
SYMBOL LED = PORTB.4
SYMBOL RELE = PORTB.0
TRISB = %10000000
'-------------------------------------------------------------------------------
PORTB = 0
LED = 1: PAUSE 100
'-------------------------------------------------------------------------------
'rotina principal
LOOP_1:
pulsin ir,0,w0 'wait start bit
if w0 < 200 then LOOP_1 'start bit is > 200
pause 20 'jump first sent
pulsin ir,0,b0 'wait 2º start bit
pulsin ir,0,b1
pulsin ir,0,b2 'read each bit from IR code
pulsin ir,0,b3
pulsin ir,0,b4
pulsin ir,0,b5
pulsin ir,0,b6
pulsin ir,0,b7
bit0=b1/96 ' LSB
bit1=b2/96
bit2=b3/96
bit3=b4/96
bit4=b5/96
bit5=b6/96
bit6=b7/96 ' MSB
bit7=0
if b0=21 then COMANDO 'test the values of your control
GOTO LOOP_1
COMANDO:
RELE = 1
LED = 1
PAUSE 500
RELE = 0
LED = 0
GOTO LOOP_1
'-------------------------------------------------------------------------------
end
Other article to learning from Experimenting_pbp.pdf:
"
Sony, infrared remote control Receiver
There are three main protocols used for the transmission and reception
of infrared signals . RC5, which is used by Philips, Rec-80, which is used
by Panasonic, and the Sony format (SIRCS), which will be described
here. Each form of infrared signalling has one thing in common, that is
the use of modulated infrared light. Modulation is used to enable a
certain amount of immunity from ambient light sources, especially
fluorescent lighting. The frequency of modulation varies from 36kHz to
40kHz, depending on the manufacturer . An infrared detector is required
to convert this modulated light into a digital signal . These are readily
available in just about every TV, VCR, and satellite receiver made within
the past 20 years . The type used for these series of experiments is the
Siemens SFH506-38, (unfortunately it's now out of production, but the
alternatives are the SFH5110 or the LT-1059) . These are small three
terminal devices that have a centre frequency of around 38kHz .
However, just about any type may be substituted, the only difference that
will be apparent will be a slight lack of range .
For the Sony protocol, the remote sends a start bit, sometimes called an
AGC pulse, that is 2.4ms in length . This allows the receiver to
synchronize, and adjust its automatic gain control, this occurs inside the
infrared detector module. After the start bit, the remote sends a series of
pulses . A 600us pulse represents a zero, and a 1200us pulse represents
a one, there is a 600us gap between each pulse. Not all manufacturers
stick stringently to these timings, so we will consider them as
approximates. All of these pulses build up a 12-bit serial signal called a
packet . This comprises of a 7-bit button value (the remote button
pressed), and a 5-bit device value (TV, VCR, etc) . The serial signal is
transmitted with the least significant bit sent first . "
Re: IR Learner? Need ideas
Have somebody doing something like this (ir-remote, ir-learner, ir-repeater) but using RC10 protocol ?
Re: IR Learner? Need ideas
1 Attachment(s)
Re: IR Learner? Need ideas
It looks like he named it IRM_out, because it is the output of the infra red sensor, so an input on the PIC.
Not sure why he is setting it high, and I don't see it ever set to input.
Have you thought about emailing the author?
IRM_VDD VAR PORTA.0 'IR RX Module Out (VCC)
IRM_Out VAR PORTA.1 'IR RX Module VDD (OUT)
Attachment 5329
Re: IR Learner? Need ideas
Quote:
Originally Posted by
scalerobotics
It looks like he named it IRM_out, because it is the output of the infra red sensor, so an input on the PIC.
Thanks for the reply.
If it is an input to the PIC then why the TrisA register is set for it to be an output?
Re: IR Learner? Need ideas
Quote:
Originally Posted by
Megahertz
Thanks for the reply.
If it is an input to the PIC then why the TrisA register is set for it to be an output?
Yes, I am with you, confused. Have you tried emailing the author, Flutoloplex?
Re: IR Learner? Need ideas
Yes I did, but seems the author is a very busy man, so I believe experts here will be able to help me on this topic.
Re: IR Learner? Need ideas
I Think that if he used a IR module, then just go work if TRISA.1 = 1, as input!
Pimentel
Re: IR Learner? Need ideas
Quote:
Originally Posted by
Pimentel
I Think that if he used a IR module, then just go work if TRISA.1 = 1, as input!
Pimentel
That could be fine if I just want to copy and replicate the code. But I am in a process to understand it fully. Making it input will settle question number 1 in my post above, but still looking for explanation on 2 & 3.
Re: IR Learner? Need ideas
Hi there,
I've been working on some other things these last months so no much time for this forum left :-(
I'll come back with answers shortly.