Searching \ for '[PIC]:servo control with 16F84' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=servo
Search entire site for: 'servo control with 16F84'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:servo control with 16F84'
2000\12\18@023229 by Dave W

picon face
Hi, my name is Dave, and I am trying to get a couple of servo's working with
a pic16f84, but am not having much luck.   I was able to get the servos
working with this article

http://www.rentron.com/servo.htm

but I want to modify the source, and I don't have their c compiler.   So, I
went about to make my own program, but since this is one of my first pic
programs, I am looking for a little help.   What I have so far is at the end
of this message.   (the servo's are modified for continuous rotation).   All
I am trying to do with this right now is when B1 goes high, start the servo
for a period of time, and stop it before the period expires if B0 goes high.

But, it doesn't work.  That's why I'm mailing the list of course :)

Any help would be greatly appreciated.....

(Trust me, I've searched the archives plenty, and couldn't find the awnser
or any other servo controller that suited my needs....)


-Dave watson
---------------------------------------------------

       LIST P=16F84           ;  tells which processor is used
       INCLUDE "p16f84a.inc"   ;  defines various registers etc. Look it
over.
       ERRORLEVEL -224        ;  supress annoying message because of tris
       __CONFIG _PWRTE_ON & _LP_OSC & _WDT_OFF   ;  configuration switches

w equ 0 ;in byte instructions, use w & f

f equ 1 ; instead of 0 & 1, it s much clearer


;-----------------------------------------------------------------------;
;    Here we set up our own registers start at the 1st free address     ;
;-----------------------------------------------------------------------;
          CBLOCK H'0C'
              dlycount         ; counter used in delays
               speedright
               speedleft
               lcnt
               wcnt
               tempright
               templeft
               d1
               d2
          ENDC

          ORG 0              ; start a program memory location zero

;-----------------------------------------------------------------------;
;        First we set up all bits of PORT A and B as outputs            ;
;-----------------------------------------------------------------------;
       movlw B'00000000'    ; all a output 0,1 are servos
       tris PORTA           ; contents of W copied to PORT A ...
       movlw B'11111111'    ; all b input
       tris PORTB           ; and PORT B
       movlw B'00000000'    ; port B pull-ups active
       option
       movwf PORTA
       movwf PORTB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MAIN

mainloop:
       btfss PORTB,1  ;if porta.1 is one, then do this func
       goto skipa1
               movlw B'11111111'
               movwf speedright
               movwf speedleft
               call motor
skipa1:
       goto mainloop

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MTOTOR function
motor:
       movwf wcnt
mloopw:
       movlw B'00011110'
       movwf lcnt
mloopl:
       btfsc PORTB,0
       goto endmotor

       movf speedright,w
       movwf tempright
       movf speedleft,w
       movwf templeft

       bsf PORTA,0
rightmotorl:
       goto $+1
       goto $+1
       goto $+1
       nop
       decfsz tempright,f
       goto rightmotorl

       bcf PORTA,0

       bsf PORTA,1
leftmotorl:
       goto $+1
       goto $+1
       goto $+1
       nop
       decfsz templeft,f
       goto leftmotorl

       bcf PORTA,1

       ;wait
                       ;13625 cycles
       movlw   0x34
       movwf   d1
Delay_00
       movlw   0x56
       movwf   d2
Delay_01
       decfsz  d2, f
       goto    Delay_01
       decfsz  d1, f
       goto    Delay_00

                       ;40 cycles
       movlw   0x0d
       movwf   d1
Delay_10
       decfsz  d1, f
       goto    Delay_10

                       ;2 cycles
       goto    $+1
       ;end wait

       decfsz lcnt,f
       goto mloopl
       decfsz wcnt,f
       goto mloopw
endmotor:
       return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;END of prog
       END
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\18@024100 by Abidin Yildirim

flavicon
face
Hi Dave,

You need to change to page (BANK) 1, before you change TRIS-Reg's.
ABI



bsf    status, rp0        ; change to bank1!!!!!!!!!!!!!!!!!!!!!!

       movlw B'00000000'    ; all a output 0,1 are servos
       tris PORTA           ; contents of W copied to PORT A ...
       movlw B'11111111'    ; all b input
       tris PORTB           ; and PORT B
       movlw B'00000000'    ; port B pull-ups active
bcf    status, rp0                ; cahange to bank 0 (back !)
!!!!!!!!!!!!!!!!!!!!
       clrf PORTA
       clrf PORTB

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\18@043629 by JP.BROWN

flavicon
face
Hi Dave, here is a simple servo test program written in CC5X pic C.
A free compiler is available.

// servo2.c
//
// Servo control using push buttons or switches         JPB 11/12/00
// ********************************************
// For CC5X C compiler
// Xtl frequency 4MHz
// A simple r/c servo test program.
// This version uses switches to control the servo position.
// Port B bit 1 is the servo control signal o/p
// Port A bit 0 = 0 resets the servo position to center (pulse = 1.5 ms)
// Port A bit 1  moves the servo clockwise when taken low.
// Port A bit 2  moves the servo anticlockwise when taken low.
//
// Note the pulse width range is specified as 1ms to 2ms giving a movement
// of 180 deg. but the precise pulse width and mechanical range varies from
// manufacturer to manufacturer.
//
// The pulse width range generated by this program has been found to work
// well with a range of servos.
//
// Connect the servo to a 5volt supply and take the control wire to port A
// bit 3, you will need a connection from the PSU 0V to the pic circuit
// supply 0V. Connect port A bit 0 to 3 to push buttons (with pullups).
// Do not leave the servo running at the extreme range of movement if it
// is pushing against the end stop. You can tell when this is happening
// by watching the current taken from the PSU which will be high if the
// servo is stalled.

#include "16F84.H"
#define CP_off |= 0x3FFF  // copy protect off for 16F84
#pragma config CP_off, PWRTE=on, WDTE=off, FOSC=XT

/* assign names to ports and pins */
#pragma bit SERVO       @ PORTB.1
#pragma bit RESET_S     @ PORTA.0
#pragma bit TURN_C      @ PORTA.1
#pragma bit TURN_A      @ PORTA.2

/* function prototypes */
void delay_min (void);
void delay_var (char n);
void pause (void);

void main( void)
{
   PORTB = 0b.0000.0000;  /* initial value */
   TRISB = 0b.0000.0000;  /* Port B all o/p */
   PORTA = 0b.0.0111;     /* initial value */
   TRISA = 0b.1110.0111;  /* xxx0 0001 */

char position=107;  // total time 1.5ms   center position

while(1) // endless loop
{
SERVO=1;
delay_min();
if (position>0)
 delay_var(position);
SERVO=0;
pause(); // 20 ms delay before next pulse
if ((TURN_C==0)&&(position<255))
position++;
if ((TURN_A==0)&&(position>0))
position--;
if (RESET_S==0)
position=107; // center the servo
}

} // end of main


void delay_min (void)  // 750 uS including overhead
{
char n=248;
do ; while(--n>0);
nop(); //  padding to produce precise time
}
// delay = 2 + 2 + (n x 3) -1 +1 +2 = 750us  @ 4MHz
// 2 for call, 2 for preset n, (n x 3)-1 for loop, 1 padding, 2 for return

void delay_var (char n) // adc x 7 uS = 1790us max.
{
do {nop(); nop(); nop(); nop();} while(--n>0);
}
// delay= 2 + 2 + (t x 7) -1 +2 us  @ 4MHz

void pause (void)  // delay between pulses approx 20 ms
{
char n;
for (n=0;n<26;n++)
{
delay_min();   // 750 us
}
}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\18@085449 by Drew Vassallo

picon face
>
>        LIST P=16F84           ;  tells which processor is used
>        INCLUDE "p16f84a.inc"   ;  defines various registers etc. Look it
>over.
>        ERRORLEVEL -224        ;  supress annoying message because of tris
>        __CONFIG _PWRTE_ON & _LP_OSC & _WDT_OFF   ;  configuration switches

You failed to mention what speed you are running.  If you're trying to
control a servo, you need some fairly precise timing, otherwise you'll end
up with so much jitter that your servos will be unusable.  Your timing in
your routines looks like it's 4MHz, but I'm guessing.

>;        First we set up all bits of PORT A and B as outputs            ;
>;-----------------------------------------------------------------------

I'm not sure if the TRIS instruction defaults to bank 1, but I always do it
manually anyways.  You should select bank 1 before you access the TRIS
registers.

        bsf STATUS, RP0

;
>        movlw B'00000000'    ; all a output 0,1 are servos
>        tris PORTA           ; contents of W copied to PORT A ...
>        movlw B'11111111'    ; all b input
>        tris PORTB           ; and PORT B

        bcf STATUS, RP0  ; select Bank 0 for PORTA/B access

>        movlw B'00000000'    ; port B pull-ups active
>        option
>        movwf PORTA
>        movwf PORTB

Your main routine looks like it times out at 158 seconds, which should be
plenty to run the servos around.  But your servo timing seems to be off a
little.  Servos run from 1.0ms to 2.0ms with 1.50ms being centered.  I doubt
whether the comparator inside the servo can differentiate signals greater
than 2.0ms.  In your routines, you're running a value of 0xFF through a 10us
loop (@4MHz) which would create a high servo pulse of 2.55ms.  I think this
is your problem.  Try reducing your initial loop counters to a value less
than 200 decimal.

Also, try to stick with a 50Hz pulse timing (which is not so critical, by
the way) to operate the servos.  Your delay counters for the low pulse cycle
total 13.667ms instead of 18ms.  This MAY not be a problem, but there's no
reason you can't get precisely 18ms.  This should give you an 18ms delay at
4MHz, and a servo cycle of 50Hz if you're using a 2.0ms high pulse:

    movlw 0x12  ; 18 times through @ 1ms per loop
    movwf Counter
Delay_Start
    movlw 0x07 ;249 cycles * 4us per cycle + 4us = 1.000ms
Delay
    addlw 0x01
    btfss STATUS, Z
    goto Delay
    decfsz Counter
    goto Delay_Start

Hope this helps.

--Andrew
{Quote hidden}

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\18@170731 by Eric Naus

picon face
Check out my home site at http://www.webhome.idirect.com/~bine .
I have not updated it for some time now but my source code might help.

At 07:23 AM 12/18/2000 -0000, you wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


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