View previous topic :: View next topic |
Author |
Message |
j_andres Guest
|
speed ramp |
Posted: Fri Feb 12, 2010 4:36 pm |
|
|
Hi,
Anyone has a code for a speed ramp, or some explanation about how to implement it.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 12, 2010 5:47 pm |
|
|
Speed ramp for what ? PWM ? Stepper Motor ?
If you want help, you need to give more details. We are not mindreaders. |
|
|
j_andres Guest
|
yes yes, PWM |
Posted: Sat Feb 13, 2010 5:55 am |
|
|
sorry PCM Programmer, you are right, and yes, I need one for PWM.
what i cant understand is how to set the time between increasing, constant and decreasing speed, in a "X" time between A and B position of the servo motor.
thanks |
|
|
j_andres Guest
|
|
Posted: Sat Feb 13, 2010 6:18 am |
|
|
by the way,
I have also an encoder, now i am implementing a PID controller and the ramp, until now, i read very well the encoder and i have implemented a P controller, but still my movement are too heavy, and before to implement the I controller i would like to have the ramp ... |
|
|
j_andres Guest
|
|
Posted: Sat Feb 13, 2010 7:22 am |
|
|
and this is my own "ramp"
Code: |
int16 reference=554; // actually the steps i want to move the motor
int16 referenc2=0;
int16 duty=0; // PWM
int16 i=1; // actually the encoder counts
void main()
{
while (i<=reference/4){ // increasing speed
duty+=2;
if (duty>=121) duty = 121; // max speed
printf("\fDuty = %ld\n\ri = %ld",duty,i);
delay_ms(50);
i++;
}
referenc2 = 3 * reference;
referenc2 /= 4;
for(i;i<=referenc2;++i){
duty = duty;
printf("\fDuty = %ld\n\ri = %ld",duty,i);
delay_ms(50);
}
while (i>=referenc2){ // decreasing speed
if (i == reference+1){
duty = 0;
break;
}
else{
duty-=2;
if (duty < 0){
duty = 0; // min speed
}
}
printf("\fDuty = %ld\n\ri = %ld",duty,i);
delay_ms(50);
i++;
}
} // end main
|
I am fixing how to get 0 duty when the i count reach the reference .... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
j_andres Guest
|
|
Posted: Sat Feb 13, 2010 2:34 pm |
|
|
Thank you.
It was useful : )
Please, is there any technic to calculate the speed of the motor with the encoder?
I am trying to read the encoder with a certain time and then say that "n counts" by ticks is my speed ... |
|
|
|