Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

adc two servos 12f675

Status
Not open for further replies.

jeremygaughan

New Member
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
 
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.
 
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
 
Pot Interference Problems

I've had the same problem while tinkering with an 8-axis joystick for the flightgear open source flight simulator. The interference between the 2 analog inputs have been giving me sleepless nights for days. Thanks for the help.
 
I've had the same problem while tinkering with an 8-axis joystick for the flightgear open source flight simulator. The interference between the 2 analog inputs have been giving me sleepless nights for days. Thanks for the help.

In order to change ADC channels quickly, the input pins need to be fed from a low impedance source - what causes the slow change is the charge/discharge time of the sample and hold capacitor.

If speed isn't an issue (as in the case of a joystick), you can add delays to give it time to settle.
 
Pot Interference

Thanks for the heads up. I'm a newcomer to electronics and still drowning in the sea of information : I didn't even realize what source impedance meant until you mentioned the holding capacitor charge time. Thanks again.

I think I'll resort to a voltage follower buffer between the pots and the ADC pins - will that do the trick? Do I have to add a current limiting resistor between the op-amp outputs and the ADC pins? Can you suggest a decent single-supply op-amp with rail-to-rail swing?

Thanks again for illuminating. Cannot overemphasize how much fun it was to steer a Cesna 172p with 2 screwdrivers on a pair of trimpots. ;-)
 
hey i am very new to this stuff and really need to know something.
Actually i am using pic12f675 for sine wave regulation through push pull topology. This analog input is given to the pic, what it does it is that whenever the voltage rises above a certain value (decided by me) the pic toggles the output on one of its pins. I donot know how pics are programmed actually so pls if anyone can help me out in this program. Its simple i know but i dont have time for all this. thnx :)
 
Kind of an ironic name huh?

What are you trying to do, get someone to write you a program, or get some help doing it yourself? What's your project going to do in the end?
 
Yea I liked the name, very funny. So, do you want to indicate reaching a certain voltage by turning on and off a light? Send some more specifics and maybe I can help.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top