Author Topic: Strange delay on the pushbutton  (Read 1605 times)

0 Members and 1 Guest are viewing this topic.

Offline VaulBTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Strange delay on the pushbutton
« on: March 05, 2010, 07:04:08 AM »
I've just started with Axon and i wrote a simple program

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart)
{
pin_make_output(E5);

      while(button_pressed())
      {
         pin_high(E5);
         delay_us(700);
         pin_low(E5);
         delay_ms(10);
      }         
         pin_high(E5);
         delay_us(2100);
         pin_low(E5);
         delay_ms(10);
   return 0;
}

There should be no noticable delay, but when i push the button  on off on off, the the servo doesn't respond immediately. Why is this?
I also had a problem with a for loop that counted servo pwm up and down between 700-2000. Servo moved CW and CCW like it was supposed to, but it did it  slowly and with stuttering. Maybe like 200-500ms stutter on each step.


I have to say that this is is very confusing compared to the PIC. There are like a million header files which mostly don't make sense to me. Why doesn't the program just start with a couple of includes and int main() like  PICs?


Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Strange delay on the pushbutton
« Reply #1 on: March 05, 2010, 07:37:31 AM »
Assuming delay_ms(10) is actually a 10 millisecond delay you are not supplying the correct timing for a hobby servo. The delay should be 20ms for most servos, check your datasheet.

The 'million header files' are the reason you can write delay_ms(x) and have an x millisecond delay, or read a sensor with just a few lines of code. You can leave them all out and work from scratch with avr gcc if you want to... (but you really don't want to  ;)).

Offline VaulBTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Strange delay on the pushbutton
« Reply #2 on: March 05, 2010, 07:50:35 AM »
20ms did not solve the problem and after all it does work. There is just this delay that shouldn't be there. For some reason the dot on the led display blinks about 1 per second and servo stutters at the same rythm. If I hold the button down for like a second and then let it go, the stutter stops, but if I then quickly press and release it again it starts to stutter. I put my code on a while(1) loop so the program wouldn't end, but it made the delay even worse.

Offline VaulBTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: Strange delay on the pushbutton
« Reply #3 on: March 05, 2010, 08:24:54 AM »
I solved it myself. One of the batteries seems to be broken so the voltage was too low  ;D

 


Get Your Ad Here