Hi All
Well after much head scratching I have now got it so that the servo moves left and right with the push of a button, and the right hand position adjustable with a pot.
There is however a small problem. If the voltage to the analogue input drops below about 170mV the servo starts glitching, and if the voltage drops below 140mV the servo shoots off and gives maximum left hand rotation.
I have tried various delays for the acquisition from 0 to 1ms but this makes no difference. I can remedy this by keeping the voltage above 170mV but I was wondering why this happens.
Below is the code for my delays
; SUBROUTINE SECTION.
SAMPLETIME
MOVLW d'20' ;initial value - tweak if required
LOOPST
ADDLW d'255' ;dec W
BTFSS STATUS,2 ;zero flag set?
GOTO LOOPST ;no, keep looping
RETURN ;yes, sampletime done
PILOT
BANKSEL ADCON1
MOVLW B'00010000' ;adc frc clock
MOVWF ADCON1
MOVLW B'00000100'
MOVWF ANSEL ;an2 set to analogue
BANKSEL ADCON0
MOVLW B'00001001' ;left justify,vdd ref,an2,on
MOVWF ADCON0
;CALL WAIT1MS
;CALL SAMPLETIME
BSF ADCON0,1
BTFSC ADCON0,1
GOTO $-1
BCF STATUS,0 ; use 5 most
RRF ADRESH,1 ; significant
BCF STATUS,0 ; bits of
RRF ADRESH,1 ; adresh
BCF STATUS,0 ; to give 5 bit
RRF ADRESH,1 ; resolution
BCF STATUS,0 ;
MOVF ADRESH,W ;
LOOPP
BSF PORTA,0
ADDLW d'255' ;dec W
BTFSS STATUS,2 ;zero flag set?
GOTO LOOPP ;no, keep looping
RETURN ;yes pilot delay done
WAIT1MS
MOVLW d'250' ;Initial value - tweak if req.
NOP
LOOP1MS
ADDLW d'255' ;dec W
BTFSS STATUS,2 ;Zero flag set?
GOTO LOOP1MS ;No, keep looping
RETURN ;Yes, 1ms done
Cheers
Stew