Dear sir,
I need help in PID algorithm project is to control generator output
voltage by field coil using pid,i use same code which you placed in
the http://robotsforroboticists.com
my question is according to PID algorithm it gives some negative value or positive value
my pwm register accepts only 02000 positive values .how to convert
my pid value in to 02000?
this one is my part of code
while(1)
{
RMS_VOLTAGE=measure_volt_freq();
error = set_point_buffer  RMS_VOLTAGE ;
integral = integral + (error*dt);
if(integral < windup_guard)
integral= windup_guard;
else if (integral > windup_guard)
integral= windup_guard;
derivative= (error  pre_error)/dt;
output = (Kp*error) + (Ki*integral) + (Kd*derivative);
pre_error = error;
PWM_value = 1000output;
if(PWM_value>2000)
PWM_value=2000;
else if(PWM_value<0)
PWM_value=0;
EPwm1Regs.CMPA.half.CMPA =(int)PWM_value;
}
i am using this code currently.please guide me to move in right position.
thank you
Ramesh rahi
PID control for generators

 Posts: 9
 Joined: Fri Jul 08, 2016 6:55 pm
Re: PID control for generators
Hi
Is your question about scaling the output?
The easiest way is if you know what the minimum negative value use you can add that as an offset to keep things positive.
Then you divide by the range and multiply by how you are scaling it.
PWM_CMD = ( (PWM_ORIGINAL + ABS(SMALLEST_NEGATIVE_VALUE) ) / POSSIBLE_RANGE ) * SCALE_RANGE
So in your case assuming that your possible range is 10 to 10
PWM_CMD = ( (PWM_ORIGINAL + 10 ) / 20 ) * 2000
Is your question about scaling the output?
The easiest way is if you know what the minimum negative value use you can add that as an offset to keep things positive.
Then you divide by the range and multiply by how you are scaling it.
PWM_CMD = ( (PWM_ORIGINAL + ABS(SMALLEST_NEGATIVE_VALUE) ) / POSSIBLE_RANGE ) * SCALE_RANGE
So in your case assuming that your possible range is 10 to 10
PWM_CMD = ( (PWM_ORIGINAL + 10 ) / 20 ) * 2000
Return to “Electrical & Electronics”
Who is online
Users browsing this forum: No registered users and 1 guest