Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

New Contributor II

Greetings all!  This is a general question that involves engineering judgement (which I don't have a lot of in the field of motor controls).

1. In discrete math for a real time application, I might code a time derivative as:

y = (x - x[n - 1]) / T     Where x is the current ADC sample, x[n-1] is the previous ADC sample, T is the sampling period, and y is the "derivative"

Similar equation for an integral:

y = y[n-1] + T*x

2. There are more "accurate" equations than the ones above, for instance:

More accurate derivative:

y =    (4 / 3) * (x[n+1] - x[n-1]) / (2*T)   -   (1 / 3) * (x[n+2] - x[n-2]) / (4*T)


Let's say I want to use the "more accurate" derivative equation in a 100kHz PWM control loop application (for instance, a dc-dc converter, or a motor control application).

The "more accurate" derivative uses an x[n+2] term, which means that whenever I use the equation, I'm always 2 samples "behind".  In the world of 100kHz real time applications, is this 2 sample delay a "big deal", or can I get away with it?

2 Replies


Are you trying to implement PID loop for motor speed control. These delays have effect and also the motor/circuit lag will introduce more delay in the system. A proper tuned PID can overcome this.


Jobin GT

Honored Contributor II

In my experience with PID control, the derivative term is usually unnecessary or diminished. In discrete math it is mostly a noise maker, for that it is not worth improving it with 4-point approximation. Furthermore, increasing sampling rate worsens derivative term accuracy to practically a noise level. I think that 10kHz sampling rate should suffice for a motor control, while 100kHz is not enough for DC-DC converter application.