PID library output is limited only 255

So I want to make a closed loop VSD system with PID, I use the MCP4725 DAC which can output up to 4095 (12bit) as the analog input to the VSD. input here I use "kecepatan" (rpm measurement), Setpoint uses "kecepatanSet" (rpm set, by operator). But if I use the PID library, the output only reaches 255. I want the output to only reach 4095, not just up to 255, I'm a newbie in coding, can anyone help me?

#include <PID_v1.h>
#include <Adafruit_MCP4725.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double PIDValue;
//Specify the links and initial tuning parameters
double Kp=1.5, Ki=0.3, Kd=0.01;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void updatePID()
{
  myPID.Compute();
  PIDValue = Output;
  
}

float checkPid(Adafruit_MCP4725& dac, double kecepatanSet, double kecepatan) {
    double errorSekarang = kecepatanSet - kecepatan;
    Input = kecepatan;
    Setpoint = kecepatanSet;
    updatePID();
    dac.setVoltage(PIDValue, false);
    Serial.println(PIDValue);
    return PIDValue;
}
1 Like

the library has defaults between 0 and 255 in the constructor, the decision there was driven to match the typical PWM values of a small arduino

call SetOutputLimits with your own values in setup()

Hi, @ahmadazzam2000
Welcome to the forum.

Is there a reason you want to control your motor with an analog voltage and not PWM?

How big is your motor?
Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

thanks @J-M-L , it works like a charm. I now just have to tune the PID

hello @TomGeorge , greetings from Indonesia

I use analog input because I use a Schneider ATV12 VSD, instead of making a VSD from scratch. it has several drawbacks, such as open loop, cannot know parameters such as voltage, current, motor speed, etc, and cannot be remote or IoT. so I want to design a system that can cover this lacks of vsd.

The system that I made is dependent on VSD, the VSD that I use can only be up to 0.75 kW, so it can only control motors under 0.75 kW.

for my schematic like the picture below, I made this for my course, it's called a creative project, feel free to use it but please don't use it for commercial purposes hehe

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.