Windmiller
Member level 4
Hi!
I'm trying like many others to learn how to control a servo with in my case a PIC12F683 and a Futaba S3110 Servo.
What I've learnt is that a 1 ms long pulse will turn the servo to max ccw and 2 ms will turn it max to the other way, and 1.5 ms will center it.
The interval between the pulses should be between 10-20 ms
I've tried to turn GP1 on in 1.5ms and then turn it off and have it turned off in 10ms which will be a sum of 11.5 ms that is between 10-20ms just like it should? This is working in the simulator of Proteus but not on the real thing, when trying. The servo is just going one way to max in every case, what am I missing?
My latest try in assembler:
My delay procedures were generated at this page Microchip PIC, ASM Delay Code, Code Generator
I have been trying several different interval settings, with no go.
Someone who would like to help me in this? Make me understand PWM and Servo.
Regards
/ Morgan
I'm trying like many others to learn how to control a servo with in my case a PIC12F683 and a Futaba S3110 Servo.
What I've learnt is that a 1 ms long pulse will turn the servo to max ccw and 2 ms will turn it max to the other way, and 1.5 ms will center it.
The interval between the pulses should be between 10-20 ms
Code:
1.5ms 1.5ms
<-> <->
___ ___
______| |____________________________| |__
<--------------- 10-20ms-------->
I've tried to turn GP1 on in 1.5ms and then turn it off and have it turned off in 10ms which will be a sum of 11.5 ms that is between 10-20ms just like it should? This is working in the simulator of Proteus but not on the real thing, when trying. The servo is just going one way to max in every case, what am I missing?
My latest try in assembler:
Code:
#include "p12f683.inc"
LIST P=PIC12F683
__CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF
; Define variables used
CBLOCK 0x20
d10ms1 ; 10 ms delay part 1
d10ms2 ; 10 ms delay part 2
d1
d2
ENDC
ORG 0x00
init:
BANKSEL TRISIO ;
MOVLW b'00000000' ; Set GPIO to output
MOVWF TRISIO
BANKSEL GPIO
CLRF GPIO
BANKSEL ANSEL ;
CLRF ANSEL ; digital I/O
BANKSEL CMCON0
MOVLW 0x07 ; Turn comparator off
MOVWF CMCON0
BANKSEL GPIO
loop:
MOVLW b'11111110' ; Turn them all on, pulse on
MOVWF GPIO ;
CALL Delay1_5ms ; Servo delay 1.5 ms pulse
CLRF GPIO ; Turn them off, no more pulse
CALL Delay10ms ; Run 10 ms delay
GOTO loop ; Start over
Delay10ms:
MOVLW 0xCF
MOVWF d10ms1
MOVLW 0x08
MOVWF d10ms2
Delay10ms_0
DECFSZ d10ms1, f
GOTO $+2
DECFSZ d10ms2, f
GOTO Delay10ms_0
GOTO $+1
RETURN
Delay1_5ms
movlw 0x2B
movwf d1
movlw 0x02
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
return
END
My delay procedures were generated at this page Microchip PIC, ASM Delay Code, Code Generator
I have been trying several different interval settings, with no go.
Someone who would like to help me in this? Make me understand PWM and Servo.
Regards
/ Morgan