Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PID code in C++ language

Status
Not open for further replies.

simon_12

New Member
Hi every1

Can someone please send me the code in C++ for PID control? The code should be like that when it is run , the window should ask for Kp, Ki , Kd and sample time? and then generates the pwm output. I will use a USB daq card for to control the motor speed.

Any help will be greatly appreciated.

Regards
Simon
 
People are not going to do your work for you. And there is no generic code that fits all.
 
I am not asking anyone to write code for me but if anyone has previouly done this task then it can be a source of guidance for me?
 
Code:
float pid(float setpoint, float x, float oldx, float kp, float ki, float kd, float &integrator)
{
    float err = x - setpoint;
    integrator += err;
    
    return kp*err + ki*integrator + kd*(x-oldx);
}
 
Status
Not open for further replies.

Latest threads

Back
Top