Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
Also, is the angle directly proportional to the pulsewidth?
If you're using two servos per robot, then you can easily control them using hardware PWM depending on which microcontroller you are using. The AVR microcontrollers (specifically the ATmega line) are quite capable of this.- Jon
;----------------------------------------;Dual servo control using PIC16F628A;send two bytes to the PIC - 1st = servo number, second = position;by Hazzer123;--------------------------------------; Boot Baud Rate = 9600, No Parity, 1 Stop Bit; movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps) movwf SPBRG movlw b'00100100' ; brgh = high (2) movwf TXSTA ; enable Async Transmission, set brgh bcf STATUS,RP0 ; RAM PAGE 0 movlw b'10010000' ; enable Async Reception movwf RCSTA;; ------------------------------------; PROVIDE A SETTLING TIME FOR START UP; ------------------------------------; clrf dataLsettle decfsz dataL,F goto settle movf RCREG,W movf RCREG,W movf RCREG,W ; flush receive buffer; movwf 0x80 ;initial pulse width of roughly 1.5ms movwf servo_pos0 movwf servo_pos1 loop23 btfsc PIR1, RCIF ;Has something been received? call receive ; -------------------------------------------; SEND PULSE; ------------------------------------------- PULSE BSF PORTA,0 ;Begin pulse on servo 0 call delay_long ;delay 1 ms movf servo_pos0,w ;delay by more time to make up required pulse width call delay_tiny BCF PORTA,0 ;end pulse BSF PORTA,1 ;repeat on servo 1 call delay_long movf servo_pos1,w call delay_tiny BCF PORTA,1 call delay_vlong ;~30ms delay between pulses goto loop23 ; -------------------------------------------; RECEIVE CHARACTER FROM RS232; -------------------------------------------receive call delay_vlong ;delay to ensure both bytes are received movf RCREG,W ;read first byte - servo number addlw 0x21 ;find the address of the position variable for the servo in question movwf FSR movf RCREG,W ;copy the second byte received, position, to the appropriate servo position variable movwf INDF return;-------------------------------------------; 4uS delay; -------------------------------------------delay_tiny movwf move_pos loop nop decfsz move_pos,f goto loop return;-------------------------------------------; 1ms delay; ------------------------------------------ ;998 cyclesdelay_long movlw 0xC7 movwf d1 movlw 0x01 movwf d2Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay_0 ;2 cycles goto $+1 return;-------------------------------------------; 30ms delay; ------------------------------------------ ;29998 cyclesdelay_vlong movlw 0x6F movwf d1 movlw 0x18 movwf d2Delay_1 decfsz d1, f goto $+2 decfsz d2, f goto Delay_1 ;2 cycles goto $+1 return end
Is it simply by measuring them with a protractor and noting down the pulse width required? All servos are slightly different arent they?