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
 
LinkBack Thread Tools Display Modes
Old 4th August 2008, 11:22 PM   (permalink)
Default

So here is the latest update in the IR receiver. I think the transmitter is good. It sends consistent signals almost 100% of the time. I checked it with the pickit analyzer. The receiver is wasting too much time reading the IR signal so I get a small pause in the pwm that causes the motor to pulse. The solution is to turn on the pins of all the PWM channels using TMR0 interrupt. Then throughout the program call a small subroutine that does an addwf of the TMR0 to the value of each channel and checks the flag. If the flag is tripped then turn that channel off. this allows me to constantly read the IR input signal with almost no interruption. It is working smoothly with leds, which I suppose will be even smoother with DC motors. This program is on a circuit with a pot and two leds, nothing more. So now I have to adapt this method to the actual IR receiver program and scrap my old receiver program.
Code:
;learning to do pwm with tmro 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
	pwmcounter, channel1, channel2
	endc

	ORG		0000h
	goto	setup
	
	ORG		0004h
	movlw	0x03		;interrupt turns on motors then
	movwf	GPIO		;call pwm keeps checking to see it's
	BCF		INTCON,2	;time to shut them off
	RETFIE				;reset interrupt
	

setup
	bsf		STATUS,RP0	;bank 1
	movlw	0x3c
	movwf	ANSEL
	movlw	0x3c
	movwf	TRISIO		;set I/O
	movlw	0xd0		
	movwf	OPTION_REG	;set tmr0
	bcf		STATUS,RP0
	movlw	0x07		;turn off comparitors
	movwf	CMCON
	movlw	0xa0
	movwf	INTCON		;set interrupt 

start
	movlw	0x09
	movwf	ADCON0
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	bsf		ADCON0,1
	call	pwm
waiting
	btfsc	ADCON0,1
	goto	waiting
	call	pwm
	call	pwm
	call	pwm
	movf	ADRESH,0
	movwf	channel1

	movlw	0x0d		;change to read channel 2 potentiometer
	movwf	ADCON0
	call	pwm			;time for adc recharge
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	call	pwm
	bsf		ADCON0,1

waiting2
	btfsc	ADCON0,1	;waiting for adc
	goto	waiting2
	call	pwm
	call	pwm
	call	pwm
	movf	ADRESH,0
	movwf	channel2
	goto	start

pwm
	movf	channel1,0
	addwf	TMR0,0
	btfss	STATUS,C		;test flag if set then turn off GPIO,0
	bcf		GPIO,0
	
	movf	channel2,0
	addwf	TMR0,0
	btfss	STATUS,C
	bcf		GPIO,1
	return
	
	end
edit: code updated
__________________
jeremy

Last edited by jeremygaughan; 5th August 2008 at 10:53 PM.
jeremygaughan is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
where to buy test equipment notwist General Electronics Chat 5 30th March 2008 10:37 PM
Test Equipment abbarue General Electronics Chat 3 10th November 2007 05:59 AM
Good Electronic Supply's Sites, Everyone Come On In! :P Electric Rain General Electronics Chat 44 28th August 2007 12:06 AM
more test equipment! HiTech Chit-Chat 5 15th September 2006 06:42 PM
High speed switch in psu..I have better test equipment now heathtech General Electronics Chat 26 11th July 2005 06:15 PM



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


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

eXTReMe Tracker