Continue to Site

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.

  • 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.

Help controlling servo motor with pic16f877a

Status
Not open for further replies.
Hi everyone
Im kind of new in PIC , I want to control the servo motors with 2 buttons
for example if button 1 pressed the servo rotate 90 degree CW and then if button 2 pressed the servo rotate CCW 90 degree (back to the previous position)
I think it will be easy but im confusing at the parts of delay or pulse
can anyone send me the code plz...
thanks
 
There are tons of how-to guides online (and in this forum's archive) for implementing RC servo control on a PIC. But here are the basics:

RC servos require a PWM signal of about 50 Hz (doesn't need to be exact). The typical duty cycles are 1ms for maximum rotation in one direction and 2ms for maximum rotation in the other direction. IIRC, you won't be able to achieve that slow of a PWM frequency using the hardware PWM module. So you'll have to implement your own PWM in software using a timer.
 
Servo motor tutorial: **broken link removed**
you need to work with PWM with a 50hz signal, (varying pulse of 0.5ms On to 1.5ms OFF)
 
hi everyone thanks for your help
actually I just want to rotate the servo motor 90 CW and then after 45 seconds 90 degree CCW (back to the same position) use just one button (if button pressed) here is my code but i dun know whether it will work or not here is my code:


if (BUTTON != 0)
for(i=0;i<45*5; i++) // for 45 seconds
{
RC3 = 1;
__delay_ms(1.5); // delay for 2 milliseconds
CLRWDT();

for(i=0;i<45*5; i++) // for 45 seconds

RC3 = 0;
__delay_ms(18.5);
CLRWDT();
}

actually where should I place this delay ?????

thanks
 
Status
Not open for further replies.

Latest threads

Back
Top