Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 #INCLUDE "P16F877A.INC" __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF ERRORLEVEL -302 COUNTER EQU 0x0c COUNTERA EQU 0x0d ORG 0x00 GOTO START ORG 0x04 GOTO START START BSF STATUS,RP0 MOVLW 0x02 MOVWF TRISB MOVLW 0x07 MOVWF OPTION_REG BCF STATUS,RP0 CLRF PORTB MAIN BSF PORTB,5 ;SWITCH EN1 TO HIGH CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 ;SET SERVO 1 & 7 ON CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 ;SETS POSITION OF SERVO1 TO 17DEGREES CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE1 CALL ENABLE0 CALL ENABLE0 CALL ENABLE1 CALL ENABLE1 CALL ENABLE1 CALL ENABLE0 ;SETS POSITION OF SERVO7 TO -18DEGREES BSF GOTO MAIN ENABLE1 BSF PORTB,3 ;SWITCH CLK TO HIGH CALL DELAY BCF PORTB,5 ;SWITCH EN1 TO LOW CALL DELAY BSF PORTB,4 ;SEND 1 TO DATA CALL DELAY CLOCK1 BCF PORTB,3 ;SWITCH CLOCK TO LOW CALL DELAY BTFSC PORTB,1 GOTO CLOCK1 RETURN ENABLE0 BSF PORTB,5 ;SWITCH EN1 TO HIGH CALL DELAY BCF PORTB,5 ;SWITCH EN1 TO LOW CALL DELAY BCF PORTB,4 ;SEND 0 TO DATA CALL DELAY CLOCK0 BCF PORTB,3 ;SWITCH CLOCK TO LOW CALL DELAY BTFSC PORTB,1 GOTO CLOCK0 RETURN DELAY MOVLW D'1' MOVWF COUNTER LOOP CALL DELAYA DECFSZ COUNTER,1 GOTO LOOP RETLW 0x00 DELAYA MOVLW D'20' MOVWF COUNTERA LOOPA CALL DELAYB DECFSZ COUNTERA,1 GOTO LOOPA RETLW 0x00 DELAYB CLRF TMR0 BCF INTCON, T0IF LOOPB BTFSS INTCON, T0IF GOTO LOOPB RETLW 0x00 END
Hi,
Well it would not really be possible to fully check your code without being able to simulate that servo board.
A simple look at the code shows that your user register addresses are wrong - for the 877A chip they start at 20h not 0Ch.
What does seem a bit odd, assuming you are using the typical hobby servo motors, then if you are using a 877a chip with about 32 free i/o lines why are you trying to run a 16 channel controller from it.
Would have thought you could have easily controlled 16 servos direct from the 877A ?
#include "p16f877.inc"
LIST P=PIC16f877
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF
; Define variables used
CBLOCK 0x20
delay
delay1
delay2
ENDC
ORG 0x00
init:
Banksel TRISA
CLRF PORTA ; All pins on porta are output
banksel PORTA
loop:
BSF PORTA,1 ;
MOVLW d'249' ; set delay of approx 1.5ms
CALL Delay_1x ;
BCF PORTA,1 ; Turn them off, no more pulse
MOVLW d'18' ; set delay of approx 18ms
CALL Delay_10x ;
GOTO loop ; Start over
;Setup up the delay routines that may be used
;delay of 1ms for 4mHz clock
;
Delay_1ms
Movlw D'166'
Delay_1x ;call here with W set allows diiferent delays
Movwf Delay
delay_loop
Nop
Nop
Nop
Decfsz Delay,f
goto delay_loop
return
;delay of 10ms for 4mHz clock
Delay_10ms
movlw d'10'
Delay_10x ;call here with W set allows diiferent delays
movwf Delay2
Delay_Loop_10ms
Call Delay_1ms ; Call 1ms delay
Decfsz Delay2,f
goto Delay_Loop_10ms
return
end
Have you seen Nigel Goodwin's tutorials? Send me a PM if you can't find him by an internet search.
One of them includes the software (in assembly) for RS232 data transfer.. It may help you.
If it is not exactly what you want, you may be able to modify it.
Have you seen Nigel Goodwin's tutorials? Send me a PM if you can't find him by an internet search.
One of them includes the software (in assembly) for RS232 data transfer.. It may help you.
If it is not exactly what you want, you may be able to modify it.
Code:#include "p16f877.inc" LIST P=PIC16f877 __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF ; Define variables used CBLOCK 0x20 delay delay1 delay2 ENDC ORG 0x00 init: Banksel TRISA CLRF PORTA ; All pins on porta are output banksel PORTA loop: BSF PORTA,1 ; MOVLW d'249' ; set delay of approx 1.5ms CALL Delay_1x ; BCF PORTA,1 ; Turn them off, no more pulse MOVLW d'18' ; set delay of approx 18ms CALL Delay_10x ; GOTO loop ; Start over ;Setup up the delay routines that may be used ;delay of 1ms for 4mHz clock ; Delay_1ms Movlw D'166' Delay_1x ;call here with W set allows diiferent delays Movwf Delay delay_loop Nop Nop Nop Decfsz Delay,f goto delay_loop return ;delay of 10ms for 4mHz clock Delay_10ms movlw d'10' Delay_10x ;call here with W set allows diiferent delays movwf Delay2 Delay_Loop_10ms Call Delay_1ms ; Call 1ms delay Decfsz Delay2,f goto Delay_Loop_10ms return end
Here is an example that uses Porta,1 for the signal pulse.
Why not just post the link Nigel Goodwins tutorial page
would this be the exact code if im gonna send a pulse directly to a servo motor?.. because i have researched a schematic diagram for direct interface to a servo motor?..
---------- Post added at 10:54 ---------- Previous post was at 10:47 ----------
hi guys. thanks for your replies!!!... this servo controller board is really giving me hard time, been working with this for weeks and cant get any good results..... would it be possible to control 5 servo motors directly with the use of a PIC16f877A if im gonna operate those 5 motors one at a time or maybe two at a time?. cause right now im planning to shift from this controller board to just directly using my PIC to control the motors.. could someone give an ASSEMBLY CODE for this scenario of controlling motors?... thank you very much everyone!!!
LIST P=PIC16f877A
#include "p16f877A.inc"
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _LVP_OFF & _CPD_OFF
; Define variables used
CBLOCK 0x20
Delay
Delay1
Delay2
ENDC
ORG 0x00
init:
banksel ADCON1
movlw 0x06 ; all pins digital I/O
movwf ADCON1
CLRF PORTA
Banksel TRISA
CLRF TRISA ; All pins on porta are output
banksel PORTA
loop:
BSF PORTA,1 ;
MOVLW d'249' ; set delay of approx 1.5ms
CALL Delay_1x ;
BCF PORTA,1 ; Turn them off, no more pulse
MOVLW d'18' ; set delay of approx 18ms
CALL Delay_10x ;
GOTO loop ; Start over
;Setup up the delay routines that may be used
;delay of 1ms for 4mHz clock
;
Delay_1ms
Movlw D'166'
Delay_1x ;call here with W set allows diiferent delays
Movwf Delay
delay_loop
Nop
Nop
Nop
Decfsz Delay,f
goto delay_loop
return
;delay of 10ms for 4mHz clock
Delay_10ms
movlw d'10'
Delay_10x ;call here with W set allows diiferent delays
movwf Delay2
Delay_Loop_10ms
Call Delay_1ms ; Call 1ms delay
Decfsz Delay2,f
goto Delay_Loop_10ms
return
end
The normal throw for a servo is regarded as 180 degrees. With futaba, at the centre ie 90 degrees the pulse is 1.5ms and the 2 extremes 1ms & 2ms. There are some servos where the centre is 1.52ms, but this should not cause you any problems using the figures above. Using these figures you should be able to calculate the pulse time to angle.
1/180= 0.0055555555555556
Therefore each degree swing is approx 0.00555 * no of degrees + 1ms. (depending how many decimal places you wish to goto)
90 degrees = 90 * 0.00555 approx = 0.4995 + 1 = 1.4995ms (1.5ms centre)
what do you mean by connect a 100nF caps. across pin 31 & 32? its not shown in the figure.. y
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?