PID control for generators

For everything electrical and electronic related. Wiring, PCBs, motor control, circuitry, solar, batteries, etc…
ramesh rahi
Posts: 1
Joined: Tue Nov 22, 2016 10:04 am

PID control for generators

Postby ramesh rahi » Tue Nov 22, 2016 10:21 am

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 0-2000 positive values .how to convert
my pid value in to 0-2000?

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 = 1000-output;

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

RobotsforRoboticists
Posts: 9
Joined: Fri Jul 08, 2016 6:55 pm

Re: PID control for generators

Postby RobotsforRoboticists » Fri Nov 25, 2016 12:21 am

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


Return to “Electrical & Electronics”

Who is online

Users browsing this forum: No registered users and 1 guest