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

servo motor help!

Status
Not open for further replies.

show-boat

New Member
I’m trying to control a R/C servo motor using a PIC16F877 and I’m trying to figure out what way is best using the built in PWM, Timer0 or writing a microsecond delay function that will allow me to pulse the output from 1ms-2ms...anyone have some tips on how I could do this, simple as possible
Thanks
 

crust

Member
Though my project used an AVR, I chose to use a timer. The timer allowed me to control multiple servos by just scheduling (and rescheduling) timer interrupts at the appropriate intervals. The PWM would have worked for two servos in my case, but I needed more outputs.
 

ivancho

New Member
What compiler are you using?

You do realize that you are going to need a varying pulse between 1ms and 2ms to position the servo. Doing a 1.5ms pulse should positin the servo in the middle. Also this pulses have to be at least 18ms apart.

PWM is used to retain the same frequency and change the duty cycle. Your frequency would be anywhere (1/1ms+18ms) 52Hz and 50Hz. If you are using PICBASIC PRO and you want to use the HPWM command you run into the problem that the lowest frequency that you can use with a 4Mz crystal is 145Hz. THen you are wanting to vary the frequency and the dutycycle...... it's all just asking for trouble.....

What are you trying to do with the servo? Can you just do it by software

Ivancho
 

happy_99

New Member
The best and efficient way to control a servo is to use a timer. If the servos you want to control is less, 1 or 2, it doesn't matter which method you use. You may use either a microsecond delay or a timer. But if the no. of servos is more, it's good not to use a microsecond delay. If you use a microsecond delay, it's a busy delay, means it executes a sequence of NOP statements for a definite no. of times. Processor will do no other job other than executing these NOPs. Instead if you use timer, you may set a pin high and then enable timer interrupt. The timer interrupt occures after the required delay and you can set the pin low to produce a pulse. The processor can do other jobs like cheching the senser status etc during the delay period.

happy_99

show-boat said:
I’m trying to control a R/C servo motor using a PIC16F877 and I’m trying to figure out what way is best using the built in PWM, Timer0 or writing a microsecond delay function that will allow me to pulse the output from 1ms-2ms...anyone have some tips on how I could do this, simple as possible
Thanks
 

show-boat

New Member
All i want to be able to do is control 1 servo and be able to change the postion anytime i need i am currently using FED Pic C to wite my code
there is no built in microsecond delay
i want to find is the the best method to control a single servo, while it be using a timer or PWM or even writing a microsecond delay it dont matter to me just whats the easyest
Thanks
 

happy_99

New Member
You may use a microsecond delay. Set the timer0 int to occur every 18ms. Write these codes to the tmr0 int routine

TMR0 INT
output_high(PIN No.)
delay_us(REQ Delay)
output_low(PIN No.)

happy_99

show-boat said:
All i want to be able to do is control 1 servo and be able to change the postion anytime i need i am currently using FED Pic C to wite my code
there is no built in microsecond delay
i want to find is the the best method to control a single servo, while it be using a timer or PWM or even writing a microsecond delay it dont matter to me just whats the easyest
Thanks
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top