need help on controlling servo
apache
Posts: 7
first of all sorry for making multiple postings. i have worked on my project and got to a point. my code has become
DO
PULSOUT 15, 5
PULSIN 15, 1, time
DEBUG HOME
time = time ** 2251
DEBUG CR, "Distance = ", DEC4 time, " cm"
PAUSE 100
LOOP
IF (time < 880) THEN
PULSOUT 14, 1000
ENDIF
IF (time > 900) THEN
PULSOUT 14, 500
ENDIF
what i am trying to do is from the datas which is variable time i need to control a servo. i tried to write down a code from tutorials but it didnt work.· i need to reset my servo which means stay in the middle before starting or inaother meanings between time 880 and 900. when the time increases i need my servo to turn left or right. but i couldnt do it. i also need help on changing my variables. i dont want to talk with time in my program. i need to wirte it an when distance is greater than something. if someone can help me on these i will be very happy.
DO
PULSOUT 15, 5
PULSIN 15, 1, time
DEBUG HOME
time = time ** 2251
DEBUG CR, "Distance = ", DEC4 time, " cm"
PAUSE 100
LOOP
IF (time < 880) THEN
PULSOUT 14, 1000
ENDIF
IF (time > 900) THEN
PULSOUT 14, 500
ENDIF
what i am trying to do is from the datas which is variable time i need to control a servo. i tried to write down a code from tutorials but it didnt work.· i need to reset my servo which means stay in the middle before starting or inaother meanings between time 880 and 900. when the time increases i need my servo to turn left or right. but i couldnt do it. i also need help on changing my variables. i dont want to talk with time in my program. i need to wirte it an when distance is greater than something. if someone can help me on these i will be very happy.
Comments
2) Servos require that the control pulse be repeated about every 20ms. If the servo doesn't get a control pulse every 20ms, it will turn off the power to the motor. If you look at the Roaming with the PING program or the similar IR-based program in the Robotics tutorial, you'll see that the program always puts out the servo pulses in some kind of loop. Sometimes it puts out a sequence of 8 pulses, sometimes it puts out 20 to 40 pulses. Usually, the servo will finish moving within about 1/2 second to 1 second ... that's why the 20 - 40 pulses. Because of the gears in the servo and the friction and the drag of the motor, the servo will usually hold its position if there's not much force on it (try turning it when there's no power). Try putting your servo PULSOUT statements in FOR statements like:
The "i" is simply a loop counter. Define it as "i VAR byte".