Searching \ for 'HELP! R/C Servo Code problems-Can U find problem.' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/servo/index.htm?key=servo
Search entire site for: 'HELP! R/C Servo Code problems-Can U find problem.'.

Truncated match.
PICList Thread
'HELP! R/C Servo Code problems-Can U find problem.'
1998\01\10@113704 by PHXSYS

picon face
I am a beginner and I'll bet one of you servo experts can solve my problem in
about 5 seconds. Undoubtedly I have made a code error.

I am trying to control the position of a R/C servo using a Pot. I am timing
the discharge of a capacitor to determine the pot position. I ran that part of
the program by itself and displayed the results of pot position in binary on
port b, everything worked fine. The leds displayed position from 1-255
(limit=255). When I combined the pot program with a servo program nothing
happens. On power up the servo moves immediately to one position and does not
respond to the pot position. If I ground PIC 16f84 pot position pin nothing
happens unless I reset power where it will stay in a middle position. If I
apply 5 volts nothing happens until a power reset.

BO

I have attached the code, if someone could review and comment I would be able
to get on with my life.

Thankyou   Jon

;*******************************;
;       MAIN ENTRY POINT        ;
;*******************************;
       ORG 0X000
       GOTO START
;*******************************;
;    INTERRUPT SERVICE CODE     ;
;*******************************;
       ORG 0X004
       RETFIE                  ;return from interrupt


;*******************************;
;       SETUP PORTS Etc.        ;
;*******************************;
START
       MOVLW      B'10000111'
       OPTION                  ;set up the OPTION register

       MOVLW      B'00000000'
       MOVWF      0BH              ;Set up the INTCON register

       MOVLW     B'00000000'
       TRIS           PORTA            ;setup port A BITs 0-3 as OUTPUT
       MOVWF     PORTA            ;clear port A

       MOVLW     B'11111111'
       TRIS          PORTB            ;setup port B BITs 0-7 as INPUT

;       MOVLW      080H             ;Setup SERVOS to CENTRE
;       MOVWF      PULSE1S          ;Servo 1 Initial Position
;       MOVWF      PULSE2S          ;Servo 2 Initial Position
;         MOVLW       040H
;         MOVWF       PULSE1PS1
;         MOVWF       PULSE2PS1
;         MOVLW      0C0H
;         MOVWF      PULSE1PS2
;         MOVWF      PULSE2PS2
                               ;*******************************;
                               ;       MAIN LOOP               ;
                               ;*******************************;
                               ;       FIRST  SERVO            ;
                               ;*******************************;
BEGIN   MOVFW    PULSE1S          ;LOAD Pulse Store
            MOVWF    PULSE1           ;LOAD Pulse Counter
            MOVLW     0FAH             ;Load 1ms. counter
            MOVWF     DELAY1           ;Get it into reg
            BSF           PORTA,0          ;Start pulse output
HIMS1   NOP                                    ;Force loop into 4 cycle duty
(even #)
            DECFSZ     DELAY1,F         ;Decriment Counter DELAY1
            GOTO         HIMS1            ;No yet Zero -> Goto HIMS1
HIGH1   NOP                                  ;Force loop into 4 cycle duty
(even #)
            DECFSZ     PULSE1,F         ;Decriment PULSE1
            GOTO        HIGH1            ;Not Yet Zero -> Gotot HIGH1
            BCF           PORTA,0          ;End pulse output
                               ;***********************************;
                               ; EXTEND TO FULL 2 mSEC PULSE WIDTH ;
                               ;***********************************;
            MOVFW      PULSE1S          ;get the register position value
            SUBLW       0FAH             ;subtract it from 250
            MOVWF     PULSE1           ;place the difference in the counter
LOW1    NOP                                ;force loop into 4 cycle duty (even
#)
            DECFSZ     PULSE1,F         ;loop for high part of duty cycle
            GOTO        LOW1             ;while pulse > 0
                               ;***********************************;
                               ; READ INPUT POT B0             ;
                               ;***********************************;
UP_DOWN  CLRF   PULSE1S         ;Clear previous value
                    MOVLW  B'11111110' ;setup port B BITs  as OUTPUT
                  TRIS   PORTB         ;
                     BSF    PORTB,0            ;START CAPACITOR CHARGE
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     MOVLW  b'11111111'        ;Set PortB,0 to input
                     TRIS   PORTB              ;Teach portA
 MEAS1   CLRWDT
                     BTFSS  PORTB,0          ;Test b0 skip if 1
                     GOTO   UP_DOWN
                     INCFSZ PULSE1S,F  ;Inc pulse1s skip if 0
                    GOTO   MEAS1            ;
CLEANUP   MOVLW  0XFF
                     MOVF   PULSE1S,W
                               ;***********************************;
                               ; DUTY CYCLE DELAY LOOP 15 mSEC     ;
                               ;***********************************;
LOOP15  MOVLW      0FH              ;load the value of 15
             MOVWF     DELAY2           ;store it in counter Delay2
DUTY1    MOVLW     0FAh             ;load the value of 250
             MOVWF     DELAY1           ;Store it int the counter delay1
DUTY2    NOP                     ;force loop into 4 cycle duty (even #)
             DECFSZ      DELAY1,F         ;Decriment Delay1
             GOTO         DUTY2            ;if not zero -> Goto DUTY2
             DECFSZ      DELAY2,F         ;Decriment Delay2
             GOTO         DUTY1            ;if not zero -> Goto DUTY1
FINAL     GOTO         BEGIN            ;restart the MAIN Programme loop
;
ERROR_  SLEEP                   ;Hmm if we got here we ha
               END                     ;The End

1998\01\10@114507 by PHXSYS

picon face
I am a beginner and I'll bet one of you servo experts can solve my problem in
about 5 seconds. Undoubtedly I have made a code error.

I am trying to control the position of a R/C servo using a Pot. I am timing
the discharge of a capacitor to determine the pot position. I ran that part of
the program by itself and displayed the results of pot position in binary on
port b, everything worked fine. The leds displayed position from 1-255
(limit=255). When I combined the pot program with a servo program nothing
happens. On power up the servo moves immediately to one position and does not
respond to the pot position. If I ground PIC 16f84 pot position pin nothing
happens unless I reset power where it will stay in a middle position. If I
apply 5 volts nothing happens until a power reset, it may move to one extreme.
At no time does the servo respond to pot position. With power cycle servo will
go from a center position to one extreme, but never to the other.

BO is used to measure the pot and A0 is used to control the servo. I switch B0
from output to input to measure cap discharge.

I have attached the code, if someone could review and comment I would be able
to get on with my life.

Thankyou   Jon

;*******************************;
;       MAIN ENTRY POINT        ;
;*******************************;
       ORG 0X000
       GOTO START
;*******************************;
;    INTERRUPT SERVICE CODE     ;
;*******************************;
       ORG 0X004
       RETFIE                  ;return from interrupt


;*******************************;
;       SETUP PORTS Etc.        ;
;*******************************;
START
       MOVLW      B'10000111'
       OPTION                  ;set up the OPTION register

       MOVLW      B'00000000'
       MOVWF      0BH              ;Set up the INTCON register

       MOVLW     B'00000000'
       TRIS           PORTA            ;setup port A BITs 0-3 as OUTPUT
       MOVWF     PORTA            ;clear port A

       MOVLW     B'11111111'
       TRIS          PORTB            ;setup port B BITs 0-7 as INPUT

      MOVLW      080H             ;Setup SERVOS to CENTRE;       MOVWF
PULSE1S          ;Servo 1 Initial Position
;       MOVWF      PULSE2S          ;Servo 2 Initial Position
;         MOVLW       040H
;         MOVWF       PULSE1PS1
;         MOVWF       PULSE2PS1
;         MOVLW      0C0H
;         MOVWF      PULSE1PS2
;         MOVWF      PULSE2PS2
                               ;*******************************;
                               ;       MAIN LOOP               ;
                               ;*******************************;
                               ;       FIRST  SERVO            ;
                               ;*******************************;
BEGIN   MOVFW    PULSE1S          ;LOAD Pulse Store
            MOVWF    PULSE1           ;LOAD Pulse Counter
            MOVLW     0FAH             ;Load 1ms. counter
            MOVWF     DELAY1           ;Get it into reg
            BSF           PORTA,0          ;Start pulse output
HIMS1   NOP                                    ;Force loop into 4 cycle duty
(even #)
            DECFSZ     DELAY1,F         ;Decriment Counter DELAY1
            GOTO         HIMS1            ;No yet Zero -> Goto HIMS1
HIGH1   NOP                                  ;Force loop into 4 cycle duty
(even #)
            DECFSZ     PULSE1,F         ;Decriment PULSE1
            GOTO        HIGH1            ;Not Yet Zero -> Gotot HIGH1
            BCF           PORTA,0          ;End pulse output
                               ;***********************************;
                               ; EXTEND TO FULL 2 mSEC PULSE WIDTH ;
                               ;***********************************;
            MOVFW      PULSE1S          ;get the register position value
            SUBLW       0FAH             ;subtract it from 250
            MOVWF     PULSE1           ;place the difference in the counter
LOW1    NOP                                ;force loop into 4 cycle duty (even
#)
            DECFSZ     PULSE1,F         ;loop for high part of duty cycle
            GOTO        LOW1             ;while pulse > 0
                               ;***********************************;
                               ; READ INPUT POT B0             ;
                               ;***********************************;
UP_DOWN  CLRF   PULSE1S         ;Clear previous value
                    MOVLW  B'11111110' ;setup port B BITs  as OUTPUT
                  TRIS   PORTB         ;
                     BSF    PORTB,0            ;START CAPACITOR CHARGE
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     NOP                       ;Time to charge
                     MOVLW  b'11111111'        ;Set PortB,0 to input
                     TRIS   PORTB              ;Teach portA
 MEAS1   CLRWDT
                     BTFSS  PORTB,0          ;Test b0 skip if 1
                     GOTO   UP_DOWN
                     INCFSZ PULSE1S,F  ;Inc pulse1s skip if 0
                    GOTO   MEAS1            ;
CLEANUP   MOVLW  0XFF
                     MOVF   PULSE1S,W
                               ;***********************************;
                               ; DUTY CYCLE DELAY LOOP 15 mSEC     ;
                               ;***********************************;
LOOP15  MOVLW      0FH              ;load the value of 15
             MOVWF     DELAY2           ;store it in counter Delay2
DUTY1    MOVLW     0FAh             ;load the value of 250
             MOVWF     DELAY1           ;Store it int the counter delay1
DUTY2    NOP                     ;force loop into 4 cycle duty (even #)
             DECFSZ      DELAY1,F         ;Decriment Delay1
             GOTO         DUTY2            ;if not zero -> Goto DUTY2
             DECFSZ      DELAY2,F         ;Decriment Delay2
             GOTO         DUTY1            ;if not zero -> Goto DUTY1
FINAL     GOTO         BEGIN            ;restart the MAIN Programme loop
;
ERROR_  SLEEP                   ;Hmm if we got here we ha
               END                     ;The End

1998\01\10@170642 by Mike Keitz

picon face
On Sat, 10 Jan 1998 11:34:40 EST PHXSYS <spam_OUTPHXSYSTakeThisOuTspamAOL.COM> writes:

>I am trying to control the position of a R/C servo using a Pot. I am
>timing
>the discharge of a capacitor to determine the pot position.
[...]
>  MEAS1   CLRWDT
>                      BTFSS  PORTB,0          ;Test b0 skip if 1
>                      GOTO   UP_DOWN
>                      INCFSZ PULSE1S,F  ;Inc pulse1s skip if 0
>                     GOTO   MEAS1            ;
>CLEANUP   MOVLW  0XFF
>                      MOVF   PULSE1S,W

As written, there is no way out of the measurement routine except when
PULSE1S overflows to 0.  You don't ever want to go back to UP_DOWN
(taking a new measurement) except as part of the main loop after doing a
servo pulse with the old measurement.  Rewrite it to something like:

meas_lp
       btfss   PORT_B,0                ;When cap has discharged,
       goto    meas_done               ;measurement done.
       incfsz  PULSE1S,f               ;Inc. measured value
       goto    meas_lp                 ;If no overflow, wait
more
       decf    PULSE1S,f               ;Fix overflow value back to
255
meas_done

The "cleanup", whatever it's supposed to do, appears unnecessary.  Make
sure the WDT prescaler is set high enough to guarantee that the WDT won't
run out during the 20 ms main loop.  Then clear it just at the start of
each main loop.  It would help to write the delay, cap measure, etc.
sections as subroutines.  This makes it easier to follow the flow through
the main loop as well as expand the function of the program later.

1998\01\11@111937 by ken

flavicon
picon face
Just out of interest the servo control pulse never goes below about
0.9mS so measuring this part of the input is a waste of resolution if
you want to keep to 8 bits. What I do is have fixed delay of about 875uS
and then I start measuring the input pulse, this gives me 5uS resolution
and a count of FF is about 2.035mS. In the output routine I have the
same fixed delay before I start the variable part. You must keep the
steps as small as possible if you go up to 10uS resolution the servos
will jitter and buzz. If anyone wants my basic input and output routines
email me and I will send them out to you.

Ken.

+-----------------------------+--------------------------------------+
|      Ken Hewitt  G8PWC      |     Email .....kenKILLspamspam@spam@welwyn.demon.co.uk     |
|      /\/\/\/\/\/\/\/\/      |   Homepage  http://www.welwyn.demon.co.uk   |
+-----------------------------+--------------------------------------+

1998\01\11@130857 by Andy Shaw

flavicon
face
I've also played around with RC pulse a fair bit and the system I use uses
the TMR0 function of a 4Mhz part to time and generate RC pulses. If you use
it with the pre-scaler set to divide by 8 then you end up with 125 ticks
being a millisecond. Using 1.5 ms as the mid point of the RC pulse (and
subtracted on input added on output as described by ken) means that you can
use a value of +-64 to represent the servo position (or whatever). The nice
thing about this sort of range is that you can perform a fair bit of
manipulation of values etc. using only 8 bit arithmetic it is easy to put
together functions/macros to limit things to this range, create deadbands
etc. I've used this system to create simple mixers, and various other
systems that require RC inputs to be combined with real world measurements
before being used to control an RC servo.

just a thought

Andy

{Original Message removed}

1998\01\12@121631 by 'Grif' w. keith griffith

flavicon
face
Ken,,, I'd like a look at your code as well...  I'm a system dba by day,
and for some reason, the pic products have brought some of the fun of
microcomputers back home.  I havent' had this much fun since I got my
altair8080 to do the first 8 bit add and halt!

At 12:58 1/11/98 +0000, you wrote:
>What I do is have fixed delay of about 875uS
>and then I start measuring the input pulse, this gives me 5uS resolution
>and a count of FF is about 2.035mS. If anyone wants my basic input and
output routines
>email me and I will send them out to you.
>
>Ken.




'Grif' N7IVS

1998\01\12@153533 by ken
flavicon
picon face
part 0 669 bytes content-type:text/plainTo save me having to keep mailing this out I ached the code to this
response, its not too big so I hope those not interested in it don't
mind.


Content-Description: rc_samp.asm
Content-Disposition: attachment; filename="rc_samp.asm"
Content-MD5: eb4kQr6Y1Iqc7WdXPXkjEw==
Content-Type: text/plain

Attachment converted: wonderland:rc_samp.asm (TEXT/MSIE) (0000F8D8)

Ken.

+-----------------------------+--------------------------------------+
|      Ken Hewitt  G8PWC      |     Email kenspamKILLspamwelwyn.demon.co.uk     |
|      /\/\/\/\/\/\/\/\/      |   Homepage  http://www.welwyn.demon.co.uk   |
+-----------------------------+--------------------------------------+


More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...