• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

please anyone help me motor servo with Pic16F877A

Status
Not open for further replies.

blaze13

New Member
Hi .. I am new :D:) and I don't have experience to mikroC in my first test motor servo with Pic16F877A , if anyone can help me so i will be glad so much. how writing too simple program can i control angle in servo motor run some time Left and return Right ?. please anyone help me. thank all of
 

be80be

Well-Known Member
blaze13 if you want to do much you need to learn to use C. And mikroC has a lot help
files to get you started
 

Iceman-

New Member
You may want to consider switching to Atmel and using an Arduino board. They allow you to use microcontrollers and control motors using their simplified programming language, which is great for beginners.

Check out:
Arduino - HomePage
 
Last edited:

Hakachukai

New Member
running a typical standard servo is pretty easy.

It's mainly about making the proper delay routines, because servos run on PWM.

Here is some easy info on how servos work: Whats a servo: A quick tutorial

So basically, you just have to hook up 1 output pin to the servos input, and then make the proper delay routines to change the pulse width.

You'll want a 20msec delay routine (because it expects 20msec between pulses)
and you'll want delay routine that takes input, and is variable between 1.25msec and 1.75msec

so it'll work something like this:

main_loop

bcf PORTB,0 ; Set the output low
call delay_20msec ;wait the required 20msec

bsf PORTB,0 ; set the output high
movlw 0x80 ; <-- this is your servo rotation amount
call variable_delay ;<-- this sets the width of the pulse to 1.25msec to 1.75msec (depnding on wreg)

goto main_loop ;go back and do it again
 

Hakachukai

New Member
I was looking through your datasheet, and it doesn't look like the 16F877 has an internal Oscilator. That is unfortnate, because it means that the instruction execution time will depend on how you operate the chip.

This is pretty easy to do with a PIC16F628A because it has a 4mhz internal Oscilator, which means that almost every instruction takes exactly 1usec to execute.

But... never the less... if you can get the chip operating with a decent, stable clock... you can calibrate your delay routines to use up the correct amount of time.
 

Pommie

Well-Known Member
Most Helpful Member
Have a read of this thread. The code in the first post is in C but another member here (Futz) converted it to asm further down the thread (on page 2). It is for a 18 series chip but is easily converted for the 16 series.

If you swith from the 16F877A to the 16F887 then you could use the internal oscillator.

Mike.
 

Mr RB

Well-Known Member
?? Where did he say he needed an internal oscillator? He has the 16F877A, it's a perfectly valid PIC hobby level chip and still widely available from hobby outlets. Kinda weird the thread took a left turn into needing an internal oscillator for some reason. :eek:

blaze13, there is TONS of stuff out there on the net using 16F877 and RC servos. You just use the TMR1 16bit timer and the CCP module, it can be set up to automatically generate the servo pulse for you, everything you need is already in the 16F877A.
 

Hakachukai

New Member
But... never the less... if you can get the chip operating with a decent, stable clock... you can calibrate your delay routines to use up the correct amount of time.
I never said that he couldn't, or shouldn't use a 16F877. I just pointed out some simple facts.

I plainly said that all he has to do is get a decent clock setup to run the chip with, and it will work.

As for how it is done... I'm sure there is a better way, but this is the way that I currently know, so I'm sharing it.
 

blaze13

New Member
:)Regards to all. ... I thank everyone , be80be,Iceman ,Hakachukai,Pommie,Mr RB, ,,,,
I am somewhat confused :confused:, the truth, I tried writing a program to move left and right motor servo with( Pic16F877A) periodically, but the problem is moving in one direction, I did not know what is the problem Does anyone can write a simple program so that the experience, learn them
I have seen a lot of sites but does not explain the code may be the ideas advanced :(
Cheers.
 

be80be

Well-Known Member
I don't see internal oscillator making it easier and it not hard to use a Ceramic Resonator
Description: Resonators function like crystals but stick closer to their specified frequency over a full temperature range. These resonators are +/-0.5% or better from -20C-+80C. These resonators have built-in load capacitors so no external caps are needed.
 

Hakachukai

New Member
:)
I am somewhat confused :confused:, the truth, I tried writing a program to move left and right motor servo with( Pic16F877A) periodically, but the problem is moving in one direction,
Do you still have the code? Can you post it for us?
If you have a digital camera, can you shoot a quick video of what the servo does and put it on youtube (or some other site)?

If you could do those 2 things, I bet we could find the problem very quickly.
 
Last edited:

Hakachukai

New Member
br80be: (in regaurds to the ceramic resonator)

Interesting! I didn't know that such a thing existed.

Can those be used as a drop in replacement for a crystal on any PIC?

If so, I'd love to be running my 16F628A at 20mhz instead of 4mhz
 
Last edited:

be80be

Well-Known Member
Last edited:

blaze13

New Member
Is there one can write the program correctly

:p A tribute to all, I do not have a lot of experience in programming, but easy is to try to help and I hope I wrote a simple program I do not know may be a big mistake, or far from the target and use the program mikroC

I want (the operation of servo motor to the right and in a moment due to the left and frequently)

Is there one can write the program correctly :D

I hope the assistance of everyone, and thanks in advance :)

the program
________________________________________
//Servo Motor Auto-Mode Test
void lmotor (void);
void rmotor (void);
void main (){ int i;
for(i=0;i<5,i++){
void lmotor ();
void rmotor ();
}
}
void lmotor () {
TRISB = 0;
ADCON1= 0x07;
PORTB = 0;
}
void rmotor () {
TRISB = 0;
ADCON1= 0x80;
PORTB = 0;
}
 

Attachments

Hakachukai

New Member
I'm afraid that there is nothing else that I can tell you except what I already told you before. You don't have to switch to anything else if you don't want to.

Reread the entire thread
 

Russ Hensel

New Member
With reguards to clocks quartz crystals are probably the most accurate ( and clock crystals may be the best cheap ones ), ceramic resonators next, and inernal ossc and RC the least accurate. Price and pin use argue against quartz, everything? else for them.

I do not think that the timing for a servo is very strict. For RS232 I would go for a resonator or better
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top