NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Sensors, Actuators, and Robotics » Servo control - PWM_MIN and PWM_MAX

June 20, 2010
by kyrre
kyrre's Avatar

Hello.

I've been going through quite a few projects, some from this site, some from other sources, and some that I just came up with (quite a bit proud).

However, the servo squirter/PWM stuff has me a bit stumped. I've gone through the numbers and code, but I can not for the life of me figure out where the numbers PWM_MAX, PWM_START and PWM_MIN comes from.

In my understanding, the TOP value is set so that the trip from 0 to TOP takes about 20 ms (36864 counts using a prescaler of 8).

If the value of the counter is smaller than the COMPARE value, the output is 1 on the ouput pin, and over COMPARE, the value is 0.

Now, in my head, this means that for a 1 ms pulse, the COMPARE value should be set to 1844, for 2 ms it should be 3686. This means that we have about 1842 distinct values to set COMPARE to (due to rounding), and varying between the min and max values, should make the servo move to the corresponding position.

So, how does this relate to the PWM_* in the example source?

I have a suspicion the answer is realy simple, and that I have missed something crucial.

Kyrre

June 20, 2010
by mongo
mongo's Avatar

I think the PWM_xxx numbers are more or less specific to the servos in use. I had to change mine to get the proper operation out of them. PWM_MIN is the low end of travel of the servo. If the number is too high, the servo does not travel to the end of travel. If the number is too low, the servo may sit there and chatter at the end of travel. The same for PWM_MAX, only the other end of things.

The PWM_START is just a place somewhere in the middle of it all so the servo has a valid number to begin with.

June 20, 2010
by kyrre
kyrre's Avatar

Thanks for the reply, mongo.

Well, if the timing is the same for all servos (within a certain threshold) should the PWM_xxx numbers be more or less the same for all servos, as long as the clock frequency and prescaler are the same values?

June 20, 2010
by mongo
mongo's Avatar

The numbers are fairly close across the various brands and types... My servos are Futaba FP-S148. The numbers in the original servo squirter program didn't give me the full range of movement so I changed them. Through trial and error, I found the limits for these particular models and they do seem to work well.

I wrote a quick little batch program that sends a series of commands to the NK with two servos operating. It's linked on U-Tube here, TWOSERVOS You can see the numbers on the display as they are processed.

I think the timing in the program does depend on the clock and prescaling, since it looks at the clock frequency in the program.

Post a Reply

Please log in to post a reply.

Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...