Small servo shake

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I'm using my own timing library to drive some servos.

Currently I'm testing it and it works, but my servo just shakes a very small quantity. Like a tick-tick-tick sound.

This is my main loop:

int main() {
    setup();
    chrono_start();

    while(1) {
        if (chrono_us() < 2000) {
            SET(B, 5);
        } else {
            CLEAR(B, 5);
        }
        if (chrono_ms() >= 19) {
            chrono_reset();
        }
    }
}

and the chrono_reset() function is:

void chrono_reset() {
    cli();
    _ellapsed_us = 0;
    _ellapsed_ms = 0;
    _us_count = 0;
    sei();
}

What I've found is that removing cli() and sei() from that function, the shake is gone.

Why? I don't like not securing the reset function.

thanks in advance (if you need more code just ask me)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So your program is putting out 1-2ms servo pulses to 3 servos in three 2ms windows, and repeating every 20ms? There must be some timing jitter on your signal. Got Scope?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
So your program is putting out 1-2ms servo pulses to 3 servos in three 2ms windows, and repeating every 20ms? There must be some timing jitter on your signal. Got Scope?

No, currently only 1 servo, just for testing.

It's sending 2ms HIGH and 18ms LOW

Every chrono_reset, if cli and sei are present, the servo have some jitter. Without them, all is perfect.

I don't understand why disabling and enabling interrupts produce jitter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you handle interrupts anywhere? If not the MCU will reset if any interrupt is triggered.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kherseth wrote:
Do you handle interrupts anywhere? If not the MCU will reset if any interrupt is triggered.

mmm I have the interrupt code on my chrono lib, what do you mean?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show the whole program. Maybe try to get one servo working without interrupts. They always cause problems at the beginning.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Show the whole program. Maybe try to get one servo working without interrupts. They always cause problems at the beginning.

solved it, I was calling cli and sei too fast in my code

added a _delay_us(100) and the shake has gone :)

thanks guys