Main Site Documentation

Breakout TB10 / SetPulse


#1

Hi,

I have the following servo (http://www.hobbyking.com/hobbyking/store/__25456__turnigy_xgd_11mb_digital_mini_servo_2_2kg_11g_0_12.html?gclid=CIHwi-774rsCFcJ0QgodPysASw) connected to a TB 10 breakout using the following code:

		PWMOutput servo = this.breakout_TB10.SetupPWMOutput(GT.Socket.Pin.Seven);//must be pin 7,8,9

		servo.Active = true;
		while (1 == 1)
		{
			for (UInt32 hightime = 600; hightime <= 2500; hightime += 200)
			{
				servo.SetPulse(100 * 1000 * 1000, hightime * 1000);
			}

		}

This actually works, but I am having difficulties changing the parameters to anything meaningful. By that I mean, I want to rotate the servo from 0 to 180 degrees. There are a few things going on here, first off I simply do not understand the high time and I am unable to get the range for this servo. If someone could explain in SetPuse For Dummies terminology, that would be great. Secondly, the above code rotates incrementally about 90 degrees, then resets. How in the world do I change these???

any help would be greatly appreciated!!

M


#2

Update: Even better take a look at Wikipedia http://en.wikipedia.org/wiki/Servo_control

PWM is a square wave which oscillates between high and low at a specified frequency.

A single oscillation from one state to the next is a cycle, the duration of this cycle is called the period. During this cycle the wave can be in the high state for a portion of the time and in the low state for the remainder of the time. The amount of time the signal is high is called the high time.

Servos are typically controlled be a PWM signal which runs at around 50Hz ie. 50 cycles per second which is a period of 20ms.

The servo will adjust it’s position based on the high time for each cycle, typically a high time of 1.5ms will put the servo at it’s neutral position, a shorter high time will move the servo to a position to the left of the neutral position while longer high times will move the servo to the right of the neutral position. typically the full range is 1ms to 2ms, with 1.5ms being center.

Remember that PWMOutput.SetPulse expects the period to be in nanoseconds, so to center the servo you would use the following


// 20ms -> 20,000,000ns
// 1.5ms -> 1,500,00ns
servo.SetPulse(20000000, 15000000);

As a final note, you will notice that the important thing is the high time, the duration is not normally critical so 20ms or 50Hz is just a common value. Also not that this description is typical for many servos, but you should review the data sheet to get the exact specification and timings the specific servo expects, not all servo are the same.

I hope I have been able to explain this relatively clearly.


#3

So a servo usually should have a period in the 20ms arena, not 100ms. Also, you constantly change the pulse so you’ll never really see a change - add some sleeps :slight_smile:

Here’s a more robust example for you.


            GTI.PWMOutput servo = this.breakout_TB10.SetupPWMOutput(GT.Socket.Pin.Seven);//must be pin 7,8,9
            UInt32 max = 2000;
            UInt32 min = 1000;
            UInt32 period = 20 * 1000 * 1000;
            servo.Active = true;
            while (1 == 1)
            {
                for (UInt32 hightime = min; hightime <= max; hightime += 100)
                {
                    servo.SetPulse(period, hightime * 1000);
                    Thread.Sleep(1000);
                }
                for (UInt32 hightime = max; hightime >= min; hightime -= 100)
                {
                    servo.SetPulse(period, hightime * 1000);
                    Thread.Sleep(1000);
                }
                Thread.Sleep(3000);
            }



#4

Brett, that totally works and I had something similar working before. My next question is how do I make it rotate 180 degrees instead of just 90, as it does now. I am missing something here. Thanks for ur reply


#5

Mine goes, as @ Taylorza’s link shows, from almost 90* left to almost 90* right, total of almost 180*. That’s all a servo should do. If adjusting the min and max doesn’t help, then that’s the range of your servo - you will need to either buy a different servo (and take pot luck again) or live with it.


#6

Thanks to both of u for answering these basic question. Since I have no idea what I am doing, I had the idea stuck in my head that I could rotate it as far as I wanted, in either direction. So this totally explains it. Thanks a bunch for both of your answers as it is greatly appreciated!!!


#7

There is a “hack” that creates a “continuous rotation servo” that you can research if that’s what you want - but a typical RC servo will only do +/-90* from centre (the amount a control surface on an RC plane/boat/whatever needs to change)


#8

totally totally makes sense now ;D


#9

@ Mooo999 - It is a pleasure.
For continuous rotation, I use the Parallax servos

http://www.parallax.com/product/900-00008


#10

OMG that was my next question. I am ordering one as we speak. Thank u so much