How to stabilize feedback loop

Hi folks,

I am using this code:

 if (speed_ramp)
  {
    speed_ramp = 0;
    temp_speed_ramp = (output + results);


    //CAlculate Acceleration
    if ((output_speed > (temp_speed_ramp))&(output_speed>0))
    {
      output_speed--;
    }
    // Set maximun speed to 1350/9 = 150Hz
    else if ((output_speed < (temp_speed_ramp))&(output_speed<1350))
    {
      output_speed++;
    }

to regulate the speed of a brushless motor.
In order to provide both feedback and a speed ramp the code above checks for a flag that is true every 1/10 of second (that works fine)
The problem is that at no load the motor has 5 or 6 oscillations when it gets to the speed point until it stabilizes.

I would be looking to know if someone has an idea on how to improve this. Some PID kind of code or similar.

Regards

Do you mean & or && in those if's.

Mark

holmes4:
Do you mean & or && in those if's.

Mark

General "and" statement.

I used to use "&&" but the compiler seems happy enough with "&" only. Is there any difference?

Of course there's a difference.

And because AWOL likes to keep his secrets the difference is here.

I don't want to keep secrets, I want people to forage.

Thanks for pointing that out, first thing to learn is to "spot" the mistake.

With that said, the reason for the oscillations is something else. Likely the motor overshoots and the CPU tries to reduce the variable to compensate.

AWOL:
I don't want to keep secrets, I want people to forage.

Or research or think or ponder. Anything other than be spoon-fed.

+1

PaulS:
Anything other than be spoon-fed.

+1

Some people are born with all the knowledge or had excellent tutors, which is not always the case.

As a matter of fact it was actually quite amusing to do a google search "differences between '&' and '&&' in C programming language".

-1