In many real-time PID control loop application I have seen that the control loop is triggered exactly as the ADC interrupts arrives in order to achieve maximum synchronization between feedback conversion and control loop execution.

I am in a situation where it would be better to have the control loop triggered by a timer interrupt so that it can be indipendent from how the feedback is acquired, for example:

  1. Capacitive encoder read through ADC -> interrupts;
  2. Hall absolute encoder read through I2C -> no interrupts;

In the first case I have a sample available each 4ms. How fast the control loop should be triggered? What are the drawbacks of this implementation? Is it possible to take this issue into account when modeling the digital control system?

Thank you for your time.

Edit 1:

Yes I am controlling a motor that can use different kind of encoders (one at time). Each encoder implements the same software interface so that I can keep motor logic indipendent from encoder internals.

Edit 2:

Sampled feedback

The rising edges in the image are the instants the feedback is sampled and thus made available by ADC interrupts. The sampling period is 4ms. Assuming the control loop executes its calculation in the same time as the sampling period, what happens if the control loop interrupt is triggered late in respect to the ADC interrupt?

  • 1
    $\begingroup$ What are you controlling ? I would assume its some kind of a motor. Is there an inertia of the system after changing the control variable. What you need to think of is how long does it take for system to stabilise after changing the output of the controller. That is basically your max PID sequence. That should be less or equal to your sensor sampling rate. It is a good practice to have timer interrupt to align the read and set of the variables. Interrupt could be good to collect the data which is then used in moving average filter and then use that data in the control loop on timer interrupt. $\endgroup$ – Gossamer Jun 10 '19 at 21:35
  • $\begingroup$ Are you saying you have a capacitive encoder and a Hall encoder, or that you might use one or the other? If both, why two? Please edit your question rather than replying in the comments. $\endgroup$ – TimWescott Jun 11 '19 at 0:14

This kind of control situation in general Nyquist method is used, In your first if your sampling period is 4 ms, your sampling frequency is 250 Hz, so you can control event maximum 125 Hz or another saying 8 ms of sampling period. But it is only for starting, if your sensor values very volatile you would make your period much longer. But I can say 8 ms is the minimum.

  • 1
    $\begingroup$ Hi Ufuk, thank you for your answer. Could you give me some textbook reference? Are you talking about Nyquist stability criterion or sampling theorem? $\endgroup$ – Roberto Maisto Jun 10 '19 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.