Shop OBEX P1 Docs P2 Docs Learn Events
weird servo problem — Parallax Forums

weird servo problem

Robot FreakRobot Freak Posts: 168
edited 2006-12-27 12:08 in General Discussion
i've made the following program:
import stamp.core.*;
public class servo_test
{
 public static DAC pin14 = new DAC(CPU.pin14);
 public static DAC pin15 = new DAC(CPU.pin15);
 public static void main()
 {
  int tempa = 0;
  while (true)
  {
   pin14.update(tempa);
   pin15.update(tempa);
   System.out.println(tempa);
   CPU.delay(25000);
   if (tempa == 250)
   {
    tempa=0;
   }
   else
   {
    tempa+=10;
   }
  }
 }
}


but when it reaches 130, the servo isn't rotating in the same direction as in the wollowing program:
import stamp.core.*;
public class servo_test
{
 public static DAC pin14 = new DAC(CPU.pin14);
 public static DAC pin15 = new DAC(CPU.pin15);
 public static void main()
 {
  while (true)
  {
   pin14.update(130);
   pin15.update(130);
  }
 }
}


Why is this? Variables don't work???

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-12-26 11:19
    Don't you need a CPU.delay(25000) in the 2nd program?

    regards peter
  • Robot FreakRobot Freak Posts: 168
    edited 2006-12-26 12:43
    no, that doesn't change a thing.
    The problem is in the first script.
    at 130, it is rotating in the same direction as 255
  • BenoitBenoit Posts: 47
    edited 2006-12-26 14:50
    Peter,

    I'm pretty new at this, but from the examples in the "What's a microcontroller" Stamp-in-class course, in the servos excercises, a value of 750 was "center", anything below that would turn the servos counter clockwise, and over 750 would turn clockwise.

    -Ben
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-12-26 15:29
    The DAC is used for voltage generation using an RC circuit.
    For servos I think PWM should be used.
    Attached is the ServoControl example from the manual.
    You'll notice different numbers (173 instead of 750)
    because of the different timebase (173*8.68usec = 750*2usec)

    The difference monitored from the two programs in the first post might
    be due to the fact that the pulse dutycycle is increased from 0 to about 50%,
    whereas the 2nd is about 50% immediately.

    regards peter

    Post Edited (Peter Verkaik) : 12/26/2006 3:33:22 PM GMT
  • Robot FreakRobot Freak Posts: 168
    edited 2006-12-27 12:08
    Oh! I used DAC instead of PWM, stupid mistake...

    Thanks!
Sign In or Register to comment.