HarveyH42 said:A servo motor only has 3 wires, usually red, black and white. Red and white are +ve and ground connections, and white
is the drive connection. Usually a pulse width of 1 mS will make the servo motor to drive from one far end, and 2 mS
to the other end (180 degree). A 1.5 mS w
Not to pic at this, but a small edit, white should be black, the image is correct. Would also suggest checking the specific servo's data sheet to make sure, read they are easy to damage if hooked up wrong.
HarveyH42 said:I should apologize, I didn't mean to be critical. This is a good thing. You can edit your own past posts and correct typing errors. Figured you were going to keep adding more to this thread.
Anyway, I've got some interest in micros and servos, but I'm using AVR, and was going to try BASIC (just started learning a few weeks ago).
Hi Harvey,HarveyH42 said:Anyway, I've got some interest in micros and servos, but I'm using AVR, and was going to try BASIC (just started learning a few weeks ago).
{
****************************************************************
* Name : K8LH_Soft_Servo.BAS *
* Author : Mike McLaren, K8LH *
* Notice : Copyright (c) 2007 Micro Applications Consultants *
* : All Rights Reserved *
* Date : 11/28/07 *
* Version : 1.0 "untested" *
* Notes : Uses CCP1 "compare" mode for 8 servos on PORTB *
* : 1-usec resolution, extended 600-2400 usec pulses *
****************************************************************
}
Device = 18F452
Clock = 8
{
****************************************************************
* Servo(0)..Servo(7) elements hold 600..2400 usec "on times" *
* Servo(8) = period "off time" (20000 - cumulative on times) *
****************************************************************
}
Dim Servo(9) As Word ' 8 servo and 1 period elements
Dim TMR1 As TMR1L.AsWord ' promote to 16 bit TMR1H:L
Dim CCPR1 As CCPR1L.AsWord ' promote to 16 bit CCPR1H:L
Dim CCP1IF As PIR1.2 ' the CCP1 interrupt flag bit
Dim Servx As Byte ' servo bitmask (only 1 bit hi)
Dim n As Byte ' servo array index
{
****************************************************************
* K8LH Hi-Rez Soft 8-channel PORTB 'compare' Servo Algorithm *
****************************************************************
}
Interrupt Soft_Servo()
LATB = Servx ' output new Servo pulse bit
CCPR1 = CCPR1 + Servo(n) ' setup next compare interrupt
CCP1IF = 0 ' clear CCP1 interrupt flag
Servo(8) = Servo(8)- Servo(n) ' adjust end-of-cycle off time
Servx = Servx << 1 ' and prep for next channel
Inc(n) ' increment servo array index
If n = 9 Then ' if end of 20 msec period
n = 0 ' reset array index
Servo(8) = 20000 ' reset 20 msec period element
Inc(Servx) ' reset Servo shadow to Servo 1
EndIf
End Interrupt
{
****************************************************************
* Init Ports and Variables *
****************************************************************
}
Sub Init()
LATB = 0 ' all PORT B servo outputs '0'
TRISB = 0 ' set PORT B all outputs
ADCON1 = 15 ' all digital I/O (no analog)
For n = 0 To 7 ' preload the Servo array
Servo(n) = 1500 ' mid-range 1500 usec position
Next '
Servo(8) = 20000 ' Servo period = 20 msecs
n = 0 ' init ISR array index
Servx = %00000001 ' init PORT B servo output mask
TMR1 = 0 ' clear 16 bit TMR1H:L pair
CCPR1 = 1000 ' first "compare" interrupt
T1CON = %00010000 ' pre 2, post 1, 1 usec 'ticks'
CCP1CON = %00001010 ' setup CCP1 "compare" mode
PIR1 = 0 ' clear peripheral int flags
PIR2 = 0 '
PIE1 = 0 ' clear peripheral int enables
PIE2 = 0 '
PIE1.2 = 1 ' enable CCP1 interrupts
INTCON.6 = 1 ' enable peripheral interrupts
T1CON.0 = 1 ' turn on Timer 1
Enable(Soft_Servo) ' set GIE, enable interrupts
End Sub
{
****************************************************************
* Main Program *
****************************************************************
}
Init
Repeat
Until 0 = 1
antkids said:i test your program in by using pic16f877a, as you say this program will make that motor to far right then back to middle then to far left, why the motor after trun to far right then direct stop there ?
antkids said:Thank for replay !!!
I am using your program code to test servo motor, because i'm using PIC16F877A and my crystal is 20MHz, so what i should change in your program code ?
I try to change "#define XTAL 4000000" to "
#define XTAL 20000000" but the result also same, after move to right just stop there. Why like this ? I also try to change the delay time but the result also same.
May i add you as friend in hotmail ? Because I can easily ask you the question ?
antkids said:Below are my program code :
#include <pic.h>
#include "delay.c"
#include "delay.h"
__CONFIG(WDTDIS & XT & UNPROTECT);
#define XTAL 20000000 //crystal frequency- 20MHz
main()
{
int i;
TRISC = 0; //PortC is output.
for (i = 0; i < 50; i++) //Send 50 pulses with width 600 uS
{
PORTC = 1; //Pulse high for 600uS
DelayBigUs(600); //since delayUs (x); x<255 so i change to delaybigus
PORTC = 0; //Pulse low for 20mS
DelayMs(20);
}
DelayMs(100); //Pause for 100mS
for (i = 0; i < 50; i++) //Send 50 pulses with width 1.5mS
{
PORTC = 1;
DelayMs(1); //Pulse high for 1.5mS
DelayBigUs(500);
PORTC = 0;
DelayMs(20);
}
DelayMs(100);
for (i = 0; i < 50; i++) //Send 50 pulses with width 2ms
{
PORTC = 1;
DelayMs(2);
PORTC = 0;
DelayMs(20);
}
DelayMs(100);
while (1); //Stops here, do nothing.
}
why send 50 pulses? why motor trun to right then stop there ? Acctually this program code is same as you post on forum, I just change something only.
What meaning of " __CONFIG(WDTDIS & XT & UNPROTECT); "
I'm using PIC16F877A, 20Mhz crystal.
HarveyH42 said:What about the fuse bits? I really don't know a lot about PIC, still little better than a beginner with AVR. But on my setup, burning the program is one thing, and setting the fuses is another. On the AVR, there are several choices that involve the clock (well 2 that I've used and understand). One divides the clock by 8. If PIC has a similar fuse, then the timing in your program wouldn't be set up right. Servos are all about the timing.
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?