Hello!

I measured the step response of a system. Now, I can find the transfer

function H(s) as a first or second order approximation. Then I'm able to

select the right gains for the PID controller.

The PID itself is implemented into a microcontroller, so it has an ADC

on the input and a DAC on the output.

I don't understand if I can create the PID transfer function in s-domain

G(s) and then convert to z-domain to find the new kp, ki, kd or I have

to convert the whole H(s) to H(z) and then discuss about the PID (in

z-domain).

You can do either. I prefer to model the system in the s domain, then

transform it into the z domain. If you do this right it'll take the

behavior of the DAC into account -- see the section titled "Exact" (which

should say "Exact Models") starting on page 179 in my book.

This doesn't matter much if you're sampling really fast, or if you know

you're going to do tuning once you get the thing into the sampled-time

domain.

You can also find the P, I and D gains in the continuous time domain, then

construct a controller with those same gains in the sampled time domain.

This keeps your controller parameterized in terms of its gains, which is

helpful for future tuning.

Another question: to convert either H(s) to H(z) or G(s) to G(z) may I

use the Tustin approximation?

z=(2+Ts)/(2-Ts)

Yes you may. The only downside to converting your plant model is that the

Tustin approximation always gives you an improper fraction in z, where the

leading term of the numerator is of the same order as the leading term of

the denominator. This doesn't matter too much for your controller, but

the model of the plant would imply an instantaneous response, which is

absurd given that in reality the write to the DAC happens strictly after

the read from the ADC. You can fix this by just dividing by an extra 'z',

or ignoring the fact that the plant polynomial isn't realizable and

getting on with life.

I read this on the "Applied Control Theory for Embedded System" by Tim

Wescott (who I thank for his suggestion to buy the book!) but I'm not

sure about "[the Tustin approximation] is generally useful [...] when

you are converting an inherited analog controller to digital".

That refers to a situation where you may be you may be tasked with taking

an analog controller that works just fine and converting it to a digital

controller. In such a case you can extract the analog controller's

s-domain transfer function, use the Tustin approximation to convert it to

digital, then implement your digital controller.

In the early days of digital control, and to a great extent now, the

procedure was to design a controller in the s domain even though you had

no intention of implementing a continuous-time controller. When you were

happy with it, you'd convert it to z. This is the right thing to do

if you are significantly more comfortable in the s domain than z, but I

think it's better overall to get comfortable in the z domain and do all

your design there -- this slant is _quite_ discernible in my book, if you

know what to look for.

I'm glad that you're finding the book helpful. I've recently expanded the

errata, so you may want to check the book's page on my web site. I hope

to be putting interesting things in the addenda as well, but I'm buried in

work at the moment -- look at it every month or so for developments.

--

Tim Wescott

Control systems and communications consulting

http://www.wescottdesign.com
Need to learn how to apply control theory in your embedded system?

"Applied Control Theory for Embedded Systems" by Tim Wescott

Elsevier/Newnes,

http://www.wescottdesign.com/actfes/actfes.html