This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Best way to control a servo?

Hi,

This might be a little OT but I've been exploring a few new ways of controling a servo.

I'm using a 8051 board of my own design, a Hitec HS300BB servo and the control line of the servo is connected to a digital out line.

Up untill now I've been using code similar to this:

sbit P1_1 = P1^1;
unsigned int wait;

P1_1 = 1;
for(x = 0; x <= wait; x++);
P1_1 = 0;
for(x = 0; x <= wait; x++);

This solution works but it isn't a very nice way of doing it cause it's strongly depended on lots os variables like overhead and processing power.

For my question, what is considerd to be the best way of controlling a servo which isn't as sensitive for overhead? (with the material I have ofcourse) Some example code would be apriciated.

TIA,
Mike

Parents

  • A more general solution you might like would be to program one of the timers to correspond to your "wait" interval, and toggle the output bit when the interrupt occurs. Keil's app note #105 talks about a general timer tick interrupt.

    http://www.keil.com/appnotes/files/apnt_105.pdf

    If the delays you need are really short (a few instruction cycle times), then you might need a instruction-loop delay. See, for example, the recent thread:

    http://www.keil.com/forum/docs/thread2150.asp

    Your particular part might include some PWM hardware to make your life even easier by driving an output pin for you according to some timer parameters.

    If you're relying on timing with an instruction loop to be precise, then you might want to keep interrupts masked during the loop, so that you don't lose any extra time to the interrupt handler.


Reply

  • A more general solution you might like would be to program one of the timers to correspond to your "wait" interval, and toggle the output bit when the interrupt occurs. Keil's app note #105 talks about a general timer tick interrupt.

    http://www.keil.com/appnotes/files/apnt_105.pdf

    If the delays you need are really short (a few instruction cycle times), then you might need a instruction-loop delay. See, for example, the recent thread:

    http://www.keil.com/forum/docs/thread2150.asp

    Your particular part might include some PWM hardware to make your life even easier by driving an output pin for you according to some timer parameters.

    If you're relying on timing with an instruction loop to be precise, then you might want to keep interrupts masked during the loop, so that you don't lose any extra time to the interrupt handler.


Children