PIC basic and Servo Motor!

Status
Not open for further replies.

watzmann

New Member
Hi All ,

i have a small R/C servo motor and i have tested it on my pic 16f877 board ,

it worked but it moves with pulses : i mean to move from point A to point B it go there with 2 strokes not in one as usual.

my program is :

DIM POS AS WORD
PINT = PORTC.1
PORTC=0
POS1=1500
POS2=3000
SERVO PIN,POS1
DELAYMS 2000
SERVO PIN,POS2


SO WHAY THAT HAPPNED ,

thank you
 
You need to send a pulse every 20mS and so you need something like,

Code:
	for i = 0 to 100
		servo pin,pos1
		delayms 18
	next i
	for i = 0 to 100
		servo pin,pos2
		delayms 18
	next i

BTW, servo pulses normally go from 1mS to 2mS - not 1.5-3.

Mike.
 
thank you it works very well , but now i need to do something else ,

suppose that i need to know the position of my servo , is it possible with picbasic.

so i need my microcontroller to tell me the current position and it's value and sure i can dispaly it with LCD

hope you can tell me how to do that
 

It's not possible with normal servo's they are input only - but there should be no need to know, you tell it where to go and it goes there, so you should know where it is at all times.
 
i'll fix ultrasnoic sensor on it so i need to program my pic to take an action when the sensor detect soemthing ,so i thought to get the position of the servo and to adjust my robot position to that one .

otherwise how i can do that
 
Move the sensor to a specific point, then check to detect something, repeat for the entire sweep of the sensor - everytime you check you know where the servo is because you've just set it's position.
 
what about the time , will take time when it stop and move again , or the normal eye will not analyies that
 
The servo basically moves to an angle state indicated by the pwm that you're sending to it. As long as it's receiving the same PWM input, the servo would not move until it receives a PWM of a different length.
 
watzmann said:
Pommie told that it's going from 1ms to 2 ms.......but i think it's differant from one servo to another

It may be slightly different, but it will be very similar - and it's not 'cast in stone', you can usually exceed the original specs by a huge amount, and greatly increase the movement range. Take one of your servos and test it.
 
i tried my rader using servo motor and a photosensor.

it works well ,

my program go like that

////for i = 0 to 100
servo pin,pos1
delayms 13
next i

///if sensor = 1 then goto LED, to turn on a led for 2 seconds

and i repeated this part for 10 times and each time i'm changeing the value of the position untill i reach the final destination , after each step i scan the sensor as you notice in the if statment

waiting for your comments.
 

Attachments

  • 1.JPG
    471.1 KB · Views: 1,320
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…