Here's how I'd do it:
Code:
//In user_routines.h, just an example value
#define ramp_speed 3
//In user_routines.c
if(pwm01 > (p1_y+ramp_speed))
{
pwm01 += ramp_speed;
}
else if (pwm01 < (p1_y-ramp_speed))
{
pwm01 -= ramp_speed;
}
else
{
pwm01 = p1_y;
}
(replacing p1_y with the value you ultimately want the pwm to have, and pwm01 with the actual port connected to the motor)
(similar to what was posted earlier I believe)
Although it might seem too simple this should work fine; taking into account the rate of change seems unnecessary to me because the ramping should/will only have a difference when the rate of change is large.