![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi again, I am still building this infrared airplane system. I have a code here to test to see if my equipment is working properly, but it's not. The transmitter sends the 38khz and the receiver picks it up. My problem is that the receiver is supposed to keep the led on whenever it receives a 38khz pulse. It flashes every time I hit the switch but won't stay on when I leave the switch pressed. here are my codes. Can anyone see a logic flaw in my programs that would cause this to be happening.
(it has adc in the real code this is just a on off deal to test the equipment) Code:
;1 channel transmitter using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h counterslow, counterslow2, counterfast, counterfast2, counterslow3, counterslow4, counterfast3, counterfast4 endc bsf STATUS,RP0 ;bank 1 movlw 0x00 movwf ANSEL movlw 0x30 movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON start btfsc GPIO,5 goto $-1 call IRpulse goto start IRpulse BSF GPIO,0 ;27 commands makes 38khz goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 BCF GPIO,0 goto $+1 goto $+1 goto $+1 goto $+1 return end Code:
;1 channel receiver using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h pulseontime, pulsegap, pwmhighcounter, pwmlowcounter, pwmtimer endc bsf STATUS,RP0 ;bank 1 movlw 0x00 movwf ANSEL movlw 0x08 movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON start bcf GPIO,0 btfsc GPIO,3 goto $-1 bsf GPIO,0 bsf GPIO,4 bsf GPIO,5 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto start end
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
What part are you using for the IR receiver?
|
|
|
|
|
|
|
(permalink) |
|
Here's a pretty rough drawing of my set up
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
I stole it from an old VCR, I don't know what it is. The only thing it has on it is CS stamped on the back. I have another one that I will try from a mini helicopter.
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
Hook the output of the IR detector to your PICkit2 and use the Logic Analyzer, you can then see exactly what the PIC sees when you hit the transmit button.
|
|
|
|
|
|
|
(permalink) |
|
Most IR receivers have automatic-gain-control. They expect to see data, not continuous 38kHz interference from a compact fluorescent light bulb.
Data is sent in bursts of 10 to 70 cycles of 38kHz pulses. There should be a gap of at least 14 cycles of 38khz between bursts. If these rules are not followed then the AGC reduces the gain to avoid interference. Your IR receiver sees the 38kHz and turns on your LED. Then it doesn't get bursts and doesn't get gaps then it reduces the gain so that it doesn't respond anymore and turns off your LED.
__________________
Uncle $crooge |
|
|
|
|
|
|
(permalink) |
|
Audio, that solved it! thanks for the knowledge.
blueroom, that is the tool I've been waiting for, now I can problem solve my IR code. It's like having a mini oscilloscope. I'll post the first one channel IR indoor airplane control when I get the bugs out of the code. Thanks again
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
It's a very handy tool for sure.
|
|
|
|
|
|
|
(permalink) |
|
Hi jeremygaughan try my code it will allow you to turn on the output while you press & hold your transmitter button.
Code:
start btfss GPIO,3 ;Is IR pulse coming? goto Do_Output ;yes,Pulse coming decfsz Count,F ;no,Pulse read as zero goto start movlw XX ;delay has expired movwf Count bcf GPIO,0 ;turn off output goto Start Do_Output bsf GPIO,0 ;turn on output goto start Last edited by Gayan Soyza; 8th May 2008 at 04:42 AM. |
|
|
|
|
|
|
(permalink) |
|
Hi jeremygaughan how long is your transmitter works? & what is that resister in the transmitter? is it a 4.7K for OSC?
|
|
|
|
|
|
|
(permalink) |
|
Your right it's a 4k7. Actually, I got it working well as far as testing the equipment is concerned, and now I'm trying to send a pulse then read the time until the next pulse starts, then use that in a PWM for dimming an led or and in the end speeding up a motor. The transmitter sends a pulse then makes a delay based upon an adc reading. Then another pulse to tell the receiver to stop counting. So far it's not working but I'm still trying. Here it is, it's in it's first stages but if you got any ideas I could use the help.
Code:
;1 channel transmitter using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h pulseontime, pulsegaptime, pulsegaptime1, leadpause endc bsf STATUS,RP0 ;bank 1 movlw 0x34 movwf ANSEL movlw 0x04 movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON movlw 0x09 movwf ADCON0 start call startadc call IR call pulsegappause call IR call pulsegappause call IR call pulsegappause call IR call pulsegappause call IR call pulsegappause call IR goto start startadc bsf ADCON0,1 waiting btfsc ADCON0,1 goto waiting movf ADRESH,0 movwf pulsegaptime1 return IR movlw 0x1e movwf pulseontime ;send 30 cycles of pulse IRpulse BSF GPIO,0 ;27 commands makes 38khz goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 BCF GPIO,0 goto $+1 goto $+1 goto $+1 goto $+1 decfsz pulseontime,1 goto IRpulse movf pulsegaptime1,0 ;set pulse gap value movwf pulsegaptime return pulsegappause movlw 0x0e movwf leadpause pulsegap ;lead pause to make sure a 0 at lease waits a while nop goto $+1 goto $+1 goto $+1 decfsz leadpause,1 goto pulsegap pause ;pulse gap to be counted by receiver nop goto $+1 goto $+1 goto $+1 decfsz pulsegaptime,1 goto pause return end Code:
;1 channel receiver using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h pause, pulseontime, pulsegap, pwmhighcounter, pwmlowcounter, pwmtimer endc bsf STATUS,RP0 ;bank 1 movlw 0x00 movwf ANSEL movlw 0x08 movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON start call readpulsegap call pwm goto start pwm movf pulsegap,0 movwf pwmhighcounter movwf pwmlowcounter movlw 0x22 movwf pwmtimer pwmhigh bsf GPIO,1 bsf GPIO,0 decfsz pwmhighcounter,1 goto $-1 pwmlow bcf GPIO,1 bcf GPIO,0 incfsz pwmlowcounter,1 goto $-1 decfsz pwmtimer,1 goto pwm return readpulsegap clrf pulsegap btfsc GPIO,3 goto $-1 nop nop nop nop wait btfss GPIO,3 goto $-1 movlw 0x0f movwf pause leadpause nop goto $+1 goto $+1 goto $+1 decfsz pause,1 goto leadpause wait2 btfsc GPIO,3 goto $+1 goto $+1 goto $+1 incf pulsegap,1 goto wait2 return end
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
Cant you send the pulsegaptime1 along with the IRpulse routine?
I mean if AD reads the value 10, the pulsegaptime1 value will be 10.Now do the IR (38khz) routine 10 times (decrement via a loop). So from the receiver side count the number of times the IRpulse has done. Is it ok with that method? |
|
|
|
|
|
|
(permalink) |
|
I thought about that before. The problem is that I would have to sacrifice either time or resolution. However I should test the motor I'm using to see how much resolution it needs anyway. I think other people are only using 16 points. I don't think that wouldn't be too slow. But then again that would involve changing the 256 ADC values into smaller pieces because the IR receptor can have a max of only 70 pulses. When I'm back from work I'll rework the program.
__________________
jeremy |
|
|
|
|
|
|
(permalink) |
|
thanks for all the help. finally it works!!!! Using the logic tool suggested by Blueroom I found the bugs in the program. Granted it's probably the roughest IR out there it still works. The next step is to put the ADC acquisition and IR reception in interrupt routines so the main programs can run more smoothly. I'm thinking timer1 to give about 4 times a second acquisitions and receptions. Here are the rough drafts.
These programs run a single motor airplane. The plane goes up with more throttle and down with less while always going in a circle because a little permanent left rudder. transmitter Code:
;1 channel transmitter using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h irpulse, datagap, min, trimpwm, trimpwm2, pwmcounter endc bsf STATUS,RP0 ;bank 1 movlw 0x34 movwf ANSEL movlw 0x1c movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON movlw 0x09 movwf ADCON0 start btfss GPIO,3 call trim call adc call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse call data1 call IRpulse goto start adc bsf ADCON0,1 waiting btfsc ADCON0,1 goto waiting return IRpulse movlw 0x0f movwf min movlw 0x1e movwf irpulse IRpulse2 BSF GPIO,1 ;27 commands makes 38khz goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 BCF GPIO,1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 decfsz irpulse,1 goto IRpulse2 minpause NOP ;27 commands makes 38khz goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 NOP goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 decfsz min,1 goto minpause return data1 movf ADRESH,0 movwf datagap data2 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 decfsz datagap,1 goto data2 return trim call adc movlw 0x20 movwf pwmcounter pwmstart movf ADRESH,0 movwf trimpwm movwf trimpwm2 pwm bsf GPIO,5 decfsz trimpwm,1 goto $-1 bcf GPIO,5 incfsz trimpwm2,1 goto $-1 decfsz pwmcounter,1 goto pwmstart btfss GPIO,3 goto trim return end Code:
;1 channel receiver using IR and ADC on a 12f675 list P=12f675 #include <p12f675.inc> __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF ERRORLEVEL -302 cblock 20h pause, pulseontime, pulsegap, pwmhighcounter, pwmlowcounter, pwmtimer endc bsf STATUS,RP0 ;bank 1 movlw 0x00 movwf ANSEL movlw 0x08 movwf TRISIO ;set I/O bcf STATUS,RP0 movlw 0x07 ;turn off comparitors movwf CMCON start call readpulsegap call pwm call pwm goto start pwm movlw 0x22 movwf pwmtimer pwm2 movf pulsegap,0 movwf pwmhighcounter movwf pwmlowcounter pwmhigh bsf GPIO,1 bsf GPIO,0 decfsz pwmhighcounter,1 goto $-1 pwmlow bcf GPIO,1 incfsz pwmlowcounter,1 goto $-1 decfsz pwmtimer,1 goto pwm2 return readpulsegap clrf pulsegap btfsc GPIO,3 goto $-1 nop nop nop wait btfss GPIO,3 goto $-1 movlw 0x0f movwf pause leadpause NOP ;27 commands makes 38khz goto $+1 NOP goto $+1 goto $+1 goto $+1 goto $+1 decfsz pause,1 goto leadpause wait2 btfss GPIO,3 return nop nop nop nop goto $+1 goto $+1 goto $+1 goto $+1 incf pulsegap,1 goto wait2 end
__________________
jeremy Last edited by jeremygaughan; 14th May 2008 at 02:09 AM. |
|
|
|
|
|
|
(permalink) |
|
So you are sending fix IR pulses along with the AD values?
Code:
call IRpulse call data1 call IRpulse call data1 Its ok its happening the last cycle in the min variable. I just read your Transmitting part & trying to understand your receiving section. Last edited by Gayan Soyza; 12th May 2008 at 06:29 AM. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| where to buy test equipment | notwist | General Electronics Chat | 5 | 30th March 2008 09:37 PM |
| Test Equipment | abbarue | General Electronics Chat | 3 | 10th November 2007 04:59 AM |
| Good Electronic Supply's Sites, Everyone Come On In! :P | Electric Rain | General Electronics Chat | 44 | 27th August 2007 11:05 PM |
| more test equipment! | HiTech | Chit-Chat | 5 | 15th September 2006 05:41 PM |
| High speed switch in psu..I have better test equipment now | heathtech | General Electronics Chat | 26 | 11th July 2005 05:15 PM |