|
|
View previous topic :: View next topic |
Author |
Message |
Jent
Joined: 04 Feb 2012 Posts: 20
|
Servo Motor is unable to turn..help.. |
Posted: Mon Feb 27, 2012 9:58 am |
|
|
Hi, I am doing my testing on a RC servo motor.. I understand that to turn the servo motor either -45degree, 0degree and 45degree is based on the PWM signal send to the servo motor.
I am using PIC18f4550 with crystal 20Mhz. Since the crystal freq is quite high, i am unable to use the PWM calculation method to calculate out the PWM period and duty cycle.
therefore, I just used a simple coding with time delay to generate the pulse of 1ms or 1.5ms or 2.0ms for ON with 19ms or 18.5ms or 18ms for OFF. My coding has no error. But the servo motor did not function.
And one more thing weird, when i connect the pin of +Vdd (+5V i gave) and pin of GND, the motor suddenly vibrate for 2 or 3 seconds, then stop, although I still didn't provide any signal to the signal pin.
Can anyone help me....below is my simple coding.
Code: |
#include <18F4550.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20M, crystal)
#define SERVO_CONTROL PIN_B3
#define SW1 PIN_B0
#define SW2 PIN_B1
#define SW3 PIN_B2
void main()
{
unsigned int a;
set_tris_b(0b00000111); //set port b of pin7-3 as output and input, pin2-0 as input
output_low(PIN_B3);
while(true)
{
if(!input(SW1)==1)
{
for(a=0; a<50; a++)
{
output_high(SERVO_CONTROL); //high with pulse of +5V
delay_ms(2); //delay 2ms for move the servo to right
output_low(SERVO_CONTROL); //low pulse of 0V
delay_ms(18); //delay low pulse with 18ms, plus 2ms
// total 20ms for one pulse period
}
}
if(!input(SW2)==1)
{
for(a=0; a<50; a++)
{
output_high(SERVO_CONTROL); //high with pulse of +5V
delay_ms(1.5); //delay 1.5ms for move the servo to cetre
output_low(SERVO_CONTROL); //low pulse of 0V
delay_ms(18.5); //delay low pulse with 18.5ms, plus
// 1.5ms total 20ms for one pulse period
}
}
if(!input(SW3)==1)
{
for(a=0; a<50; a++)
{
output_high(SERVO_CONTROL); //high with pulse of +5V
delay_ms(1.0); //delay 1ms for move the servo to left
output_low(SERVO_CONTROL); //low pulse of 0V
delay_ms(19); //delay low pulse with 19ms, plus
// 1.0ms total 20ms for one pulse period
}
}
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Feb 27, 2012 10:13 am |
|
|
1) How does the servo perform with a regular RC control system?
2) What is the power supply for the project?
3) What kind of decoupling between the servo supply and the PIC have you ?
4)Get rid of the set_tris()...functions,NOT required unless you are using fast_io().
5) delay_ms(nnnn) MUST have integers NOT floating point numbers as variables. You can use delay_us(1500) as your 1.5ms delay value.
that's a start....
oh yeah...there is a working RC servo program in the EXAMPLES folder... |
|
|
Jent
Joined: 04 Feb 2012 Posts: 20
|
|
Posted: Mon Feb 27, 2012 10:50 am |
|
|
Thanks your reply..
I checked from its datasheet, when send the pulse 1.5ms, the servo supposes rotating to neutral point. 1ms for anticlockwise, 2ms for clockwise.
I use 5V (Vdd) from PIC since the servo support the voltage from 4.8 to 6V.
If I need to use switch as input (push button), then is that requiring to set_tris?
I discovered the Servo.c from C compiler, but it seems to be using ADC...but i am so sure about it... |
|
|
Jent
Joined: 04 Feb 2012 Posts: 20
|
|
Posted: Mon Feb 27, 2012 11:18 am |
|
|
Now my servo can be turning after changing to the delay_us..Thanks..^.^ |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|