1

The question is quite simple and I don't know where and how to implement the transfer functions.

Let's say that I have a classic system

enter image description here

where P has a transfer function of the second order with zita=0.7, F=1 and C is the process regulator.

I would like to implement this regulator on a controller like ATMega128P in C or C++.

The transfer function of the process is identified by experimental methods and the regulator may vary depending on the process transfer function.

Where should I start?

Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28
tzortzik
  • 4,993
  • 9
  • 57
  • 88
  • The first step is to select the language. Will it be C or c++ ? – Mahonri Moriancumer May 24 '14 at 21:47
  • It doesn't really matter in this project. The only advantage of using C is the processing time which will be faster. But if there is a lot of code to be written, I'll go for C++. Also the microcontroller is working at 16MHz which is enough for both languages in a real time application like mine. – tzortzik May 24 '14 at 21:51
  • So, which will it be, C or c++? – Mahonri Moriancumer May 24 '14 at 22:00
  • Let's say C for the sake of time. – tzortzik May 24 '14 at 22:01
  • As a start, you should realize that the systems engineers that would instantly understand that diagram aren't going to find this question. So you have to help yourself by helping others understand what you are trying to do. In other words, you need to fully specify the system in plain english without using jargon like `classic system`, `transfer function of the second order`, and `process regulator`. You may find that in the process of trying to explain your system to others, you'll come to a much better understanding of the problem yourself. – user3386109 May 24 '14 at 22:46
  • ..and the systems engineers that do understand the diagram are not going to design, code and test it for you, FFS, you are layers of design away from code, so why bring it here? You want us to design a generic software feedback system? – Martin James May 24 '14 at 23:27
  • @user3386109 this is a problem for system engineers that have already done this kind of things and it would've taken a lot of time for me to explain every concept – tzortzik May 25 '14 at 12:03
  • @MartinJames I wasn't searching for someone to write my code, I was only searching for a way to implement a simple regulator. Well, the idea was to put in practice what I learned in school and that wasn't very clear. The answer that IsKernel gave is a very good one and that is the answer I was looking for. – tzortzik May 25 '14 at 12:05

1 Answers1

5

If you have your transfer function it in continuous time (Laplace), you will need to transform it in discrete time (Z-Transform), using one of the discretization methods (forward difference, backward difference, trapezoidal).

Once you have the discrete transfer function, you will need to apply inverse Z transform to obtain the system's equation in the time domain. Next, you will need to detrmine the discretization step.

When if you have this data, you can implement this system on the microcontroller quite easily, since practically you will only implement a simple equation which will probably read a sensor periodically through an ADC input and according to that and previous input (y[k], y[k-1], ...) values will generate the control value (u[k]) according to its reference (r[k]).

The ADC (y[k]) can be read using in a timer interrupt, set to fire according to your discretization step. Once the value is read, you can compute u[k] and set the execution element accordingly.

For implementation, I would recommend C, since C++ would probably be a little bit of an overkill in this case (most embedded systems which implement a system such as this one are programmed using ANSI C or MISRA C - especially in automotive).

Before jumping to C, I would first try to see if I got the calculations correctly and I would simulate the system in Simulink (MATLAB), or Scilab.

For tuning the real embedded system, I would recommend reading about the Ziegler-Nichols method.

http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method

Info on discretization:

http://www-verimag.imag.fr/~tdang/DocumentsCours/Discretization.pdf

IsKernel
  • 333
  • 4
  • 12