Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 8th May 2008, 12:21 AM   (permalink)
Default IR airplane equipment test help

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
jeremygaughan is offline   Reply With Quote
Old 8th May 2008, 12:37 AM   (permalink)
Default

What part are you using for the IR receiver?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 8th May 2008, 12:40 AM   (permalink)
Default

Here's a pretty rough drawing of my set up
Attached Images
File Type: jpg IR system.JPG (24.3 KB, 40 views)
__________________
jeremy
jeremygaughan is offline   Reply With Quote
Old 8th May 2008, 12:42 AM   (permalink)
Default

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
jeremygaughan is offline   Reply With Quote
Old 8th May 2008, 12:44 AM   (permalink)
Default

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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 8th May 2008, 01:01 AM   (permalink)
Default

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
audioguru is offline   Reply With Quote
Old 8th May 2008, 01:27 AM   (permalink)
Default

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
jeremygaughan is offline   Reply With Quote
Old 8th May 2008, 03:36 AM   (permalink)
Default

It's a very handy tool for sure.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 8th May 2008, 04:39 AM   (permalink)
Default

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
The delay value must greater than your time intervals.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/

Last edited by Gayan Soyza; 8th May 2008 at 04:42 AM.
Gayan Soyza is online now   Reply With Quote
Old 8th May 2008, 04:45 AM   (permalink)
Default

Hi jeremygaughan how long is your transmitter works? & what is that resister in the transmitter? is it a 4.7K for OSC?
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is online now   Reply With Quote
Old 8th May 2008, 05:10 AM   (permalink)
Default

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
jeremygaughan is offline   Reply With Quote
Old 8th May 2008, 05:35 AM   (permalink)
Default

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?
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is online now   Reply With Quote
Old 8th May 2008, 01:18 PM   (permalink)
Default

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
jeremygaughan is offline   Reply With Quote
Old 12th May 2008, 06:06 AM   (permalink)
Default

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
receiver

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
edit: this code has been polished and a switch added to the transmitter on GPIO 3 so the ADC can be adjusted by a potentiometer. If you push the switch a led on GPIO 5 will fade with the movement of the ADC
__________________
jeremy

Last edited by jeremygaughan; 14th May 2008 at 02:09 AM.
jeremygaughan is offline   Reply With Quote
Old 12th May 2008, 06:26 AM   (permalink)
Default

So you are sending fix IR pulses along with the AD values?

Code:
	call	IRpulse
	call	data1
	call	IRpulse
	call	data1
The data1 routine contains your data but its time is adding to the low part (minpause) of your IR routine is it?

Its ok its happening the last cycle in the min variable.

I just read your Transmitting part & trying to understand your receiving section.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/

Last edited by Gayan Soyza; 12th May 2008 at 06:29 AM.
Gayan Soyza is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 06:09 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.