# Digital controller slow response time

I built a PI controller for a motor by analog method and digital method. By analog I using op-amp and by digital I use Arduino Mega2560. I use Euler equation to convert the transfer function of PI controller to algorithm for Arduino to use. The problem is that while the analog controller has very good response, low overshoot, short settling time, the digital controller has high overshoot and long settling time. Can anyone explain why and how to overcome this problem?

Post your code. Not a picture of something.

…R

At a guess you have something out by a factor of ten or so - perhaps time step, but yes
the code and the opamp circuit for comparison would be needed to see what the differences
are.

Here is the op-amp circuit

About the digital controller. I use ADC module on Arduino to transform analog to digital and this signal is perform by the algorithm
u(k) = u(k-1) + e(k) + (10Ts-1)*e(k-1), with Ts is the sampling time
I do not know how to choose Ts. I just choose randomly Ts = 0.01s. What Ts influence on the circuit?

new.ino (1.15 KB)

You can't randomly choose! You have only an integrator so its trivial as the filter poles are at zero,
in digital terms an integrator is just:

``````float integ (float input)
{
static float val = 0.0 ;
val += dt * input ;
return val ;
}
``````

With a suitable output scaling to match the opamp, here 10 as it
outputs 10V/s for a 1V input

But how can I choose Ts accurately?

So that all the frequencies of interest are less than 1/2th the sampling frequency - the nyquist limit.