I'm trying to design a digital PID controller in Matlab/ Simulink, right now I have the values for a continuous time PID controller and a sampling time. So I am stuck on how should I convert what I have into digital.
D_z = K_d*(1/T)*(z-1)/z for your differentiator block.
See attached pic for Simulink circuit. This is derived using "backwards differences" for your I and D terms. K_p, K_i & K_d are your continuous-time PID coeffs. T is your sampling period for the discrete-time case. This should be OK if you are sampling quickly, relative to the plant dynamics.
If you want to derive an optimal PID controller, from first principles, directly in the digital domain (i.e without s-z mapping/approximation) you might want to have a look at the paper I recently wrote on this ...
Since you are using MATLAB, I would suggest using the 'c2d' function:
http://au.mathworks.com/help/control/ref/c2d.html
This will discretize your continuous-time transfer-function.
The default discretization is 'zoh' (zero-order hold), also known as 'exact discretization'. Almost any digital-to-analog converter you can buy these days will use 'zoh', so this is typically the most accurate discretization for most control systems.
Read more about 'zoh'/'exact discretization' here:
Yes, the zero-order hold would need to be considered if you were designing a digital controller from first principles. But if you are discretising an analogue controller that you have already designed, then I think something like a bilinear transform or backward differences would be sufficient.
There is no transformation to make a continuous-time system into an an exact discrete systems.
So, we have one theory for continuous-time systems and another one for discrete-time systems.
When we mix continuous time systems with discrete controllers, you are supposed to do one of the two:
1) Do a continuous-time design and at the end only do a digital implementation of the controller. In this case, you stay with the right system, yet end with the wrong (or just inexact) controller.
2) Do a transformation of the continuous-time system to discrete-time, using any of the suggestions above, but then you end with the right controller for the wrong (or just inexact) system.
The combined system used to be called 'sampled data" and these days "hybrid."
You can see many publications on hybrid systems.
However, these days, when the sampling time can be reduced to times that were unimaginable just a short time ago, the practice is to do the design in the continuous-time domain ad then use a simple transformation (like the one Hugh Lachlan Kenedy suggested above) and make sure that the sampling time is so short that sampling rate is much larger than any relevant continuous-time frequency (including any noise, not only the expected system bandwidth).
As the price of microprocessors is becoming only a small part of any cost of actual hardware, this is the common control practice. You may find out that the sampling rate Fs=100 Hz is not enough, yet Fs=400 Hz is. (Depending on the system, could also be that Fs=1000 Hz is not enough, yet Fs=4000 Hz is).
3) Make a discrete-time controller for the continuous-time plant (connected via a zero-order hold) so that you get the right controller for the right system?
For example. see the link to the paper in my initial answer.
At another discussion you say "PID can be used anywhere!" and I don't disagree, yet I would add "almost."
When you tune a PID, you already assume that you close some system and that the PID-closed system is stable, so you only have to fix the right P+I+D values.
If PID is what we think of as "the controller," then yes, (with sufficiently large sampling rate) it is not important if you directly design it as a discrete-time PID or as continuous-time PID that you discretize later.
However, if we talk about more complex systems that may require quite a bit of design in order to, first of all, stabilize (or try to stabilize) them, that may also contain just a few oscillatory modes, etc., then a lot of the continuous-time practice and accumulated experience and intuition might be needed.