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 22nd January 2008, 12:14 AM   (permalink)
Default adc two servos 12f675

Hi, I'm trying to make two servos move at the same time using the ADC. I can make one move really well from one end to the other. Then I modified my code to move two servos from two seperate ADCs. Now the servos affect eachother and neither moves past 90 degrees. My thought is that one ADC is affecting the other and causing them to change their values. Here is my code thanks for any suggestions.

Code:
;move a servo with 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
	servotime, servotime2, pulse, pulse2, pulseb, timer1, timer2, timer3
	endc
	
	bsf	STATUS,RP0		;bank 1
	movlw	0x38
	movwf	ANSEL
	movlw	0x1c
	movwf	TRISIO		;set I/O
	bcf	STATUS,RP0
	
	movlw	0x07		;turn off comparitors
	movwf	CMCON


start
	movlw	0x09
	movwf	ADCON0
	bsf	ADCON0,1
waiting2
	btfsc	ADCON0,1
	goto	waiting2
	movf	ADRESH,0
	movwf	pulseb

	movlw	0x0d
	movwf	ADCON0
	bsf	ADCON0,1
waiting
	btfsc	ADCON0,1
	goto	waiting
	movf	ADRESH,0
	movwf	pulse
	movlw	0xfa
	movwf	pulse2
servo
	bsf	GPIO,5
	decfsz	pulse2,1                      ;turn first on and wait for 1ms
	goto	servo
servo2
	nop
	nop 
	nop
	nop
	nop
	decfsz	pulse,1                        ;count down to make value
	goto	servo2                         ;between 1 and 2 ms
	bcf	GPIO,5

	movlw	0xfa
	movwf	pulse2
servob
	bsf	GPIO,1              ;turn second on and wait for 1ms
	decfsz	pulse2,1
	goto	servob
servo3
	nop
	nop
	nop
	nop
	nop
	decfsz	pulseb,1             ;leave on for between 1-3ms
	goto	servo3
	bcf	GPIO,1

	call	pause
	goto	start

pause
	movlw	0xff                  ;wait for the rest of the 18k to pass
	movwf	timer2
	movlw	0x12	
	movwf	timer1
	decfsz	timer1,1
	goto	$-1
	decfsz	timer2,1
	goto	$-5	
	return
	end
__________________
jeremy
jeremygaughan is offline  
Reply With Quote
Old 22nd January 2008, 12:22 AM   (permalink)
Default

You need a short delay (20uS) after you select the channel number by writing to ADCON0. This is needed to allow the ADC holding capacitor to charge.

Code:
	movlw	0x09
	movwf	ADCON0
	call	ShortDelay
	bsf	ADCON0,1
Mike.
Pommie is offline  
Reply With Quote
Old 22nd January 2008, 05:27 AM   (permalink)
Default

Good work pommie. It works without interference between the two servos. Now I need to change my pulse width to get a better range out of the servos. Thanks for the help
__________________
jeremy
jeremygaughan is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Drive 33 Servos With One PIC + USART wschroeder Micro Controllers 40 14th July 2008 02:22 PM
PIC12F675 ADC Circuit help. MERV Micro Controllers 4 16th January 2008 08:05 PM
ADC troubles andy257 General Electronics Chat 4 2nd December 2007 05:49 PM
HS1101 capacitive humidity sensor; need nearly linear voltage to feed to a 1-wire ADC FirefighterBlu3 Electronic Projects Design/Ideas/Reviews 5 19th October 2007 11:06 PM
16F877 Timer0 Interrupt Affecting ADC sebana Micro Controllers 13 12th September 2007 09:42 AM



All times are GMT. The time now is 06:45 PM.


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