CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

speed ramp

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
j_andres
Guest







speed ramp
PostPosted: Fri Feb 12, 2010 4:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 12, 2010 5:47 pm     Reply with quote

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
PostPosted: Sat Feb 13, 2010 5:55 am     Reply with quote

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







PostPosted: Sat Feb 13, 2010 6:18 am     Reply with quote

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







PostPosted: Sat Feb 13, 2010 7:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 13, 2010 12:30 pm     Reply with quote

Here is a routine which changes the PWM duty cycle in the #int_Timer2
interrupt:
http://www.ccsinfo.com/forum/viewtopic.php?t=41473&start=3
j_andres
Guest







PostPosted: Sat Feb 13, 2010 2:34 pm     Reply with quote

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 ...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group